forked from qt-creator/qt-creator
C++: fix functionAt(), moved it, and added test.
Thanks to Jesper K. Pedersen for the fix! Change-Id: Ie49c3352e26a9632b1500596b00d559bfe932dff Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
6a4a926622
commit
ca291fbc7b
@@ -55,29 +55,13 @@ QString AbstractEditorSupport::functionAt(const CppModelManagerInterface *modelM
|
||||
const QString &fileName,
|
||||
int line, int column)
|
||||
{
|
||||
const CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||
const CPlusPlus::Document::Ptr document = snapshot.document(fileName);
|
||||
if (!document)
|
||||
if (!modelManager)
|
||||
return QString();
|
||||
if (const CPlusPlus::Symbol *symbol = document->lastVisibleSymbolAt(line, column))
|
||||
if (const CPlusPlus::Scope *scope = symbol->enclosingScope())
|
||||
if (const CPlusPlus::Scope *functionScope = scope->enclosingFunction())
|
||||
if (const CPlusPlus::Symbol *function = functionScope) {
|
||||
const CPlusPlus::Overview o;
|
||||
QString rc = o.prettyName(function->name());
|
||||
// Prepend namespace "Foo::Foo::foo()" up to empty root namespace
|
||||
for (const CPlusPlus::Symbol *owner = function->enclosingNamespace();
|
||||
owner; owner = owner->enclosingNamespace()) {
|
||||
const QString name = o.prettyName(owner->name());
|
||||
if (name.isEmpty()) {
|
||||
break;
|
||||
} else {
|
||||
rc.prepend(QLatin1String("::"));
|
||||
rc.prepend(name);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
const CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||
if (const CPlusPlus::Document::Ptr document = snapshot.document(fileName))
|
||||
return document->functionAt(line, column);
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user