MCPcopy Create free account
hub / github.com/KDE/kdevelop / applyAliases

Method applyAliases

kdevplatform/language/duchain/ducontext.cpp:1220–1276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1218}
1219
1220void DUContext::applyAliases(const SearchItem::PtrList& baseIdentifiers, SearchItem::PtrList& identifiers,
1221 const CursorInRevision& position, bool canBeNamespace, bool onlyImports) const
1222{
1223 DeclarationList imports;
1224 findLocalDeclarationsInternal(globalIndexedImportIdentifier(), position, AbstractType::Ptr(), imports,
1225 topContext(), DUContext::NoFiltering);
1226
1227 if (imports.isEmpty() && onlyImports) {
1228 identifiers = baseIdentifiers;
1229 return;
1230 }
1231
1232 for (const SearchItem::Ptr& identifier : baseIdentifiers) {
1233 bool addUnmodified = true;
1234
1235 if (!identifier->isExplicitlyGlobal) {
1236 if (!imports.isEmpty()) {
1237 //We have namespace-imports.
1238 for (Declaration* importDecl : std::as_const(imports)) {
1239 //Search for the identifier with the import-identifier prepended
1240 if (dynamic_cast<NamespaceAliasDeclaration*>(importDecl)) {
1241 auto* alias = static_cast<NamespaceAliasDeclaration*>(importDecl);
1242 identifiers.append(SearchItem::Ptr(new SearchItem(alias->importIdentifier(), identifier)));
1243 } else {
1244 qCDebug(LANGUAGE) << "Declaration with namespace alias identifier has the wrong type" <<
1245 importDecl->url().str() << importDecl->range().castToSimpleRange();
1246 }
1247 }
1248 }
1249
1250 if (!identifier->isEmpty() && (identifier->hasNext() || canBeNamespace)) {
1251 DeclarationList aliases;
1252 findLocalDeclarationsInternal(identifier->identifier, position,
1253 AbstractType::Ptr(), imports, nullptr, DUContext::NoFiltering);
1254
1255 if (!aliases.isEmpty()) {
1256 //The first part of the identifier has been found as a namespace-alias.
1257 //In c++, we only need the first alias. However, just to be correct, follow them all for now.
1258 for (Declaration* aliasDecl : std::as_const(aliases)) {
1259 if (!dynamic_cast<NamespaceAliasDeclaration*>(aliasDecl))
1260 continue;
1261
1262 addUnmodified = false; //The un-modified identifier can be ignored, because it will be replaced with the resolved alias
1263 auto* alias = static_cast<NamespaceAliasDeclaration*>(aliasDecl);
1264
1265 //Create an identifier where namespace-alias part is replaced with the alias target
1266 identifiers.append(SearchItem::Ptr(new SearchItem(alias->importIdentifier(),
1267 identifier->next)));
1268 }
1269 }
1270 }
1271 }
1272
1273 if (addUnmodified)
1274 identifiers.append(identifier);
1275 }
1276}
1277

Callers 1

fullyApplyAliasesMethod · 0.45

Calls 8

topContextFunction · 0.85
importIdentifierMethod · 0.80
strMethod · 0.80
isEmptyMethod · 0.45
appendMethod · 0.45
urlMethod · 0.45
rangeMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected