| 30 | namespace |
| 31 | { |
| 32 | QualifiedIdentifier 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 |
| 68 | QString zeroIndentation(const QString& str, int fromLine = 0) |
no test coverage detected