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

Function stripPrefixes

plugins/clang/codegen/sourcemanipulation.cpp:32–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30namespace
31{
32QualifiedIdentifier stripPrefixes(const DUContextPointer& ctx, const QualifiedIdentifier& id)
33{
34 if (!ctx) {
35 return id;
36 }
37
38 auto imports = ctx->fullyApplyAliases({}, ctx->topContext());
39 if (imports.contains(id)) {
40 return {}; /// The id is a namespace that is imported into the current context
41 }
42
43 auto basicDecls = ctx->findDeclarations(id, CursorInRevision::invalid(), {}, nullptr,
44 (DUContext::SearchFlags)(DUContext::NoSelfLookUp | DUContext::NoFiltering));
45
46 if (basicDecls.isEmpty()) {
47 return id;
48 }
49
50 auto newId = id.mid(1);
51 auto result = id;
52 while (!newId.isEmpty()) {
53 auto foundDecls
54 = ctx->findDeclarations(newId, CursorInRevision::invalid(), {}, nullptr,
55 (DUContext::SearchFlags)(DUContext::NoSelfLookUp | DUContext::NoFiltering));
56
57 if (foundDecls == basicDecls) {
58 result = newId; // must continue to find the shortest possible identifier
59 // esp. for cases where nested namespaces are used (e.g. using namespace a::b::c;)
60 newId = newId.mid(1);
61 }
62 }
63
64 return result;
65}
66
67// Re-indents the code so the leftmost line starts at zero
68QString zeroIndentation(const QString& str, int fromLine = 0)

Callers 1

setSubScopeMethod · 0.85

Calls 7

fullyApplyAliasesMethod · 0.80
findDeclarationsMethod · 0.80
midMethod · 0.80
invalidFunction · 0.50
topContextMethod · 0.45
containsMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected