diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 3bb6ea04586684fd9a820ded833f868de0648fca..ce832e2df60c7b5f911c70420489488fdfd1a0b5 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -47,24 +47,24 @@ namespace { using namespace CPlusPlus; -static void addNames(const Name *name, QList<const Name *> *names) +static void addNames(const Name *name, QList<const Name *> *names, bool addAllNames = false) { if (! name) return; - else if (name->isNameId() || name->isTemplateNameId()) - names->append(name); else if (const QualifiedNameId *q = name->asQualifiedNameId()) { addNames(q->base(), names); addNames(q->name(), names); + } else if (addAllNames || name->isNameId() || name->isTemplateNameId()) { + names->append(name); } } -static void fullyQualifiedName_helper(Symbol *symbol, QList<const Name *> *names) +static void path_helper(Symbol *symbol, QList<const Name *> *names) { if (! symbol) return; - fullyQualifiedName_helper(symbol->enclosingSymbol(), names); + path_helper(symbol->enclosingSymbol(), names); if (symbol->name()) { if (symbol->isClass() || symbol->isNamespace()) { @@ -137,14 +137,22 @@ LookupContext &LookupContext::operator = (const LookupContext &other) } QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol) +{ + QList<const Name *> qualifiedName = path(symbol->enclosingSymbol()); + addNames(symbol->name(), &qualifiedName, /*add all names*/ true); + return qualifiedName; +} + +QList<const Name *> LookupContext::path(Symbol *symbol) { QList<const Name *> names; - fullyQualifiedName_helper(symbol, &names); + path_helper(symbol, &names); return names; } + const Name *LookupContext::minimalName(const Name *name, - Scope *source, + Scope *scope, ClassOrNamespace *target) const { qWarning() << "TODO:" << Q_FUNC_INFO; @@ -329,7 +337,7 @@ QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const ClassOrNamespace *LookupContext::lookupParent(Symbol *symbol) const { - QList<const Name *> fqName = fullyQualifiedName(symbol); + QList<const Name *> fqName = path(symbol); ClassOrNamespace *binding = globalNamespace(); foreach (const Name *name, fqName) { binding = binding->findType(name); @@ -697,15 +705,19 @@ ClassOrNamespace *CreateBindings::globalNamespace() const ClassOrNamespace *CreateBindings::lookupType(Symbol *symbol) { - const QList<const Name *> names = LookupContext::fullyQualifiedName(symbol); + const QList<const Name *> path = LookupContext::path(symbol); + return lookupType(path); +} - if (names.isEmpty()) +ClassOrNamespace *CreateBindings::lookupType(const QList<const Name *> &path) +{ + if (path.isEmpty()) return _globalNamespace; - ClassOrNamespace *b = _globalNamespace->lookupType(names.at(0)); + ClassOrNamespace *b = _globalNamespace->lookupType(path.at(0)); - for (int i = 1; b && i < names.size(); ++i) - b = b->findType(names.at(i)); + for (int i = 1; b && i < path.size(); ++i) + b = b->findType(path.at(i)); return b; } diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 82f180592ce0bf000e6d16717a53156599cdfd34..3854b4cb7b7b5924d6f1556de3ffcc80972f6a96 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -125,6 +125,7 @@ public: /// Finds the binding associated to the given symbol. ClassOrNamespace *lookupType(Symbol *symbol); + ClassOrNamespace *lookupType(const QList<const Name *> &path); /// Returns the Control that must be used to create temporary symbols. /// \internal @@ -227,9 +228,10 @@ public: QSharedPointer<Control> control() const; // ### deprecate static QList<const Name *> fullyQualifiedName(Symbol *symbol); + static QList<const Name *> path(Symbol *symbol); - const Name *minimalName(const Name *name, Scope *source, - ClassOrNamespace *target) const; + Q_DECL_DEPRECATED const Name *minimalName(const Name *name, Scope *source, + ClassOrNamespace *target) const; private: // The current expression. diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index 5237e35773fc638d8144caa2e7fc2f0946a06bf9..b717d632541392c1cc55635d29e5702b6f5d7979 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -931,7 +931,7 @@ public: // We need to do a QCA::translate, so we need a context. // Use fully qualified class name: Overview oo; - foreach (const Name *n, LookupContext::fullyQualifiedName(function)) { + foreach (const Name *n, LookupContext::path(function)) { if (!m_context.isEmpty()) m_context.append(QLatin1String("::")); m_context.append(oo.prettyName(n)); @@ -1563,7 +1563,10 @@ QList<TextEditor::QuickFixOperation::Ptr> CppQuickFixFactory::quickFixOperations quickFixOperations.append(convertNumericToOctal); quickFixOperations.append(convertNumericToDecimal); quickFixOperations.append(completeSwitchCaseStatement); + +#if 0 quickFixOperations.append(declFromDef); +#endif if (editor->mimeType() == CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE) quickFixOperations.append(wrapCString);