From fa491c882c8779b546693d0e4d620f8a898217ba Mon Sep 17 00:00:00 2001
From: Joerg Bornemann <joerg.bornemann@digia.com>
Date: Thu, 12 Sep 2013 13:40:17 +0200
Subject: [PATCH] CppEditor: make isNamespaceFunction available for all C++
 quickfixes

This function is generally useful when dealing with free functions.

Change-Id: I52c0057b587d81c4b0eddac24e4d7659f80cf840
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
---
 src/plugins/cppeditor/cppquickfixes.cpp | 76 ++++++++++++-------------
 1 file changed, 38 insertions(+), 38 deletions(-)

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 <afile.h> (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)
-- 
GitLab