diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index e8611e7962e..c4103dea43e 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -227,6 +227,44 @@ Class *isMemberFunction(const LookupContext &context, Function *function) return 0; } +Namespace *isNamespaceFunction(const LookupContext &context, Function *function) +{ + QTC_ASSERT(function, return 0); + if (isMemberFunction(context, function)) + return 0; + + Scope *enclosingScope = function->enclosingScope(); + while (!(enclosingScope->isNamespace() || enclosingScope->isClass())) + enclosingScope = enclosingScope->enclosingScope(); + QTC_ASSERT(enclosingScope != 0, return 0); + + const Name *functionName = function->name(); + if (!functionName) + return 0; // anonymous function names are not valid c++ + + // global namespace + if (!functionName->isQualifiedNameId()) { + foreach (Symbol *s, context.globalNamespace()->symbols()) { + if (Namespace *matchingNamespace = s->asNamespace()) + return matchingNamespace; + } + return 0; + } + + const QualifiedNameId *q = functionName->asQualifiedNameId(); + if (!q->base()) + return 0; + + if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) { + foreach (Symbol *s, binding->symbols()) { + if (Namespace *matchingNamespace = s->asNamespace()) + return matchingNamespace; + } + } + + return 0; +} + // Given include is e.g. "afile.h" or (quotes/angle brackets included!). void insertNewIncludeDirective(const QString &include, CppRefactoringFilePtr file) { @@ -3975,44 +4013,6 @@ private: const ChangeSet::Range m_toRange; }; -Namespace *isNamespaceFunction(const LookupContext &context, Function *function) -{ - QTC_ASSERT(function, return 0); - if (isMemberFunction(context, function)) - return 0; - - Scope *enclosingScope = function->enclosingScope(); - while (!(enclosingScope->isNamespace() || enclosingScope->isClass())) - enclosingScope = enclosingScope->enclosingScope(); - QTC_ASSERT(enclosingScope != 0, return 0); - - const Name *functionName = function->name(); - if (!functionName) - return 0; // anonymous function names are not valid c++ - - // global namespace - if (!functionName->isQualifiedNameId()) { - foreach (Symbol *s, context.globalNamespace()->symbols()) { - if (Namespace *matchingNamespace = s->asNamespace()) - return matchingNamespace; - } - return 0; - } - - const QualifiedNameId *q = functionName->asQualifiedNameId(); - if (!q->base()) - return 0; - - if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) { - foreach (Symbol *s, binding->symbols()) { - if (Namespace *matchingNamespace = s->asNamespace()) - return matchingNamespace; - } - } - - return 0; -} - } // anonymous namespace void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result)