forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user