Commit fa491c88 authored by Joerg Bornemann's avatar Joerg Bornemann
Browse files

CppEditor: make isNamespaceFunction available for all C++ quickfixes



This function is generally useful when dealing with free functions.

Change-Id: I52c0057b587d81c4b0eddac24e4d7659f80cf840
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 6a352130
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment