Commit 91dbac03 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Fix qualified ids in the ':' locator filter

* Always display qualified ids in the ':' filter
* Show correct qualified ids (for some symbols the namespace was shown
  twice)

Task-number: QTCREATORBUG-10136

Change-Id: Id178cb4b8abcc316250fa16e5f3e5a8e72bc0c10
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent feef5cac
......@@ -94,8 +94,12 @@ QList<Locator::FilterEntry> CppCurrentDocumentFilter::matchesFor(QFutureInterfac
|| (!hasWildcard && matcher.indexIn(matchString) != -1))
{
QVariant id = qVariantFromValue(info);
Locator::FilterEntry filterEntry(this, matchString, id, info.icon);
filterEntry.extraInfo = info.symbolScope;
QString name = matchString;
QString extraInfo = info.symbolScope;
if (info.type == ModelItemInfo::Method)
info.unqualifiedNameAndScope(matchString, &name, &extraInfo);
Locator::FilterEntry filterEntry(this, name, id, info.icon);
filterEntry.extraInfo = extraInfo;
if (matchString.startsWith(entry, caseSensitivityForPrefix))
betterEntries.append(filterEntry);
......
......@@ -52,10 +52,15 @@ QList<QList<CppTools::ModelItemInfo> > CppFunctionsFilter::itemsToMatchUserInput
Locator::FilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
{
const QVariant id = qVariantFromValue(info);
Locator::FilterEntry filterEntry(this, info.symbolName + info.symbolType, id, info.icon);
filterEntry.extraInfo = info.symbolScope.isEmpty()
? info.shortNativeFilePath()
: info.symbolScope;
QString name = info.symbolName;
QString extraInfo = info.symbolScope;
info.unqualifiedNameAndScope(name, &name, &extraInfo);
if (extraInfo.isEmpty())
extraInfo = info.shortNativeFilePath();
Locator::FilterEntry filterEntry(this, name + info.symbolType, id, info.icon);
filterEntry.extraInfo = extraInfo;
return filterEntry;
}
......
......@@ -50,7 +50,7 @@ CppLocatorFilter::~CppLocatorFilter()
Locator::FilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info)
{
const QVariant id = qVariantFromValue(info);
Locator::FilterEntry filterEntry(this, info.symbolName, id, info.icon);
Locator::FilterEntry filterEntry(this, info.scopedSymbolName(), id, info.icon);
filterEntry.extraInfo = info.type == ModelItemInfo::Class || info.type == ModelItemInfo::Enum
? info.shortNativeFilePath()
: info.symbolType;
......
......@@ -173,8 +173,15 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
QTest::newRow("CppFunctionsFilter")
<< testFile
<< cppFunctionsFilter
<< QString::fromLatin1("myfunction")
<< QString::fromLatin1("function")
<< (QList<ResultData>()
<< ResultData(_("function2(bool, int)"), _("MyClass"))
<< ResultData(_("function2(bool, int)"), _("MyNamespace::MyClass"))
<< ResultData(_("function2(bool, int)"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass"))
<< ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClass(char)"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass"))
<< ResultData(_("myFunction(bool, int)"), testFileShort)
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace"))
<< ResultData(_("myFunction(bool, int)"), _("<anonymous namespace>"))
......@@ -187,6 +194,8 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< (QList<ResultData>()
<< ResultData(_("MyClass()"), _("MyNamespace::MyClass"))
<< ResultData(_("function2(bool, int)"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass"))
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace"))
);
......@@ -208,22 +217,27 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< ResultData(_("MyClass"), _("MyNamespace"))
);
QTest::newRow("CppLocatorFilter")
// all symbols in the left column are expected to be fully qualified.
QTest::newRow("CppLocatorFilter-filtered")
<< testFile
<< cppLocatorFilter
<< _("my")
<< (QList<ResultData>()
<< ResultData(_("<anonymous namespace>::MyClass"), testFileShort)
<< ResultData(_("<anonymous namespace>::MyClass::MyClass"), _("()"))
<< ResultData(_("<anonymous namespace>::MyClass::functionDefinedOutSideClass"), _("(char)"))
<< ResultData(_("<anonymous namespace>::MyEnum"), testFileShort)
<< ResultData(_("<anonymous namespace>::myFunction"), _("(bool, int)"))
<< ResultData(_("MyClass"), testFileShort)
<< ResultData(_("MyClass"), testFileShort)
<< ResultData(_("MyClass"), testFileShort)
<< ResultData(_("MyClass"), _("()"))
<< ResultData(_("MyClass"), _("()"))
<< ResultData(_("MyClass"), _("()"))
<< ResultData(_("MyEnum"), testFileShort)
<< ResultData(_("MyClass::MyClass"), _("()"))
<< ResultData(_("MyClass::functionDefinedOutSideClass"), _("(char)"))
<< ResultData(_("MyEnum"), testFileShort)
<< ResultData(_("MyEnum"), testFileShort)
<< ResultData(_("myFunction"), _("(bool, int)"))
<< ResultData(_("myFunction"), _("(bool, int)"))
<< ResultData(_("MyNamespace::MyClass"), testFileShort)
<< ResultData(_("MyNamespace::MyClass::MyClass"), _("()"))
<< ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClass"), _("(char)"))
<< ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace"), _("(float)"))
<< ResultData(_("MyNamespace::MyEnum"), testFileShort)
<< ResultData(_("MyNamespace::myFunction"), _("(bool, int)"))
<< ResultData(_("myFunction"), _("(bool, int)"))
);
}
......@@ -240,27 +254,36 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
<< ResultData(_("int V1"), _("MyEnum"))
<< ResultData(_("int V2"), _("MyEnum"))
<< ResultData(_("MyClass"), _(""))
<< ResultData(_("MyClass()"), _("MyClass"))
<< ResultData(_("function1()"), _("MyClass"))
<< ResultData(_("function2(bool, int)"), _("MyClass"))
<< ResultData(_("MyClass"), _("MyClass"))
<< ResultData(_("function1"), _("MyClass"))
<< ResultData(_("function2"), _("MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("MyClass"))
<< ResultData(_("int myVariable"), _("MyNamespace"))
<< ResultData(_("myFunction(bool, int)"), _("MyNamespace"))
<< ResultData(_("myFunction"), _("MyNamespace"))
<< ResultData(_("MyEnum"), _("MyNamespace"))
<< ResultData(_("int V1"), _("MyNamespace::MyEnum"))
<< ResultData(_("int V2"), _("MyNamespace::MyEnum"))
<< ResultData(_("MyClass"), _("MyNamespace"))
<< ResultData(_("MyClass()"), _("MyNamespace::MyClass"))
<< ResultData(_("function1()"), _("MyNamespace::MyClass"))
<< ResultData(_("function2(bool, int)"), _("MyNamespace::MyClass"))
<< ResultData(_("MyClass"), _("MyNamespace::MyClass"))
<< ResultData(_("function1"), _("MyNamespace::MyClass"))
<< ResultData(_("function2"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClassAndNamespace"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("MyNamespace::MyClass"))
<< ResultData(_("functionDefinedOutSideClassAndNamespace"), _("MyNamespace::MyClass"))
<< ResultData(_("int myVariable"), _("<anonymous namespace>"))
<< ResultData(_("myFunction(bool, int)"), _("<anonymous namespace>"))
<< ResultData(_("myFunction"), _("<anonymous namespace>"))
<< ResultData(_("MyEnum"), _("<anonymous namespace>"))
<< ResultData(_("int V1"), _("<anonymous namespace>::MyEnum"))
<< ResultData(_("int V2"), _("<anonymous namespace>::MyEnum"))
<< ResultData(_("MyClass"), _("<anonymous namespace>"))
<< ResultData(_("MyClass()"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("function1()"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("function2(bool, int)"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("MyClass"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("function1"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("function2"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("functionDefinedOutSideClass"), _("<anonymous namespace>::MyClass"))
<< ResultData(_("main()"), _(""))
;
CppCurrentDocumentFilterTest test(testFile);
......
......@@ -95,21 +95,9 @@ bool SearchSymbols::visit(Function *symbol)
{
if (!(symbolsToSearchFor & SymbolSearcher::Functions))
return false;
QString extraScope;
if (const Name *name = symbol->name()) {
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
if (q->base())
extraScope = overview.prettyName(q->base());
}
}
QString fullScope = _scope;
if (!_scope.isEmpty() && !extraScope.isEmpty())
fullScope += QLatin1String("::");
fullScope += extraScope;
QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type());
appendItem(name, type, fullScope, ModelItemInfo::Method, symbol);
appendItem(name, type, _scope, ModelItemInfo::Method, symbol);
return false;
}
......
......@@ -94,6 +94,18 @@ struct CPPTOOLS_EXPORT ModelItemInfo
: symbolScope + QLatin1String("::") + symbolName;
}
void unqualifiedNameAndScope(const QString &defaultName, QString *name, QString *scope) const
{
*name = defaultName;
*scope = symbolScope;
const QString qualifiedName = scopedSymbolName();
const int colonColonPosition = qualifiedName.lastIndexOf(QLatin1String("::"));
if (colonColonPosition != -1) {
*name = qualifiedName.mid(colonColonPosition + 2);
*scope = qualifiedName.left(colonColonPosition);
}
}
QString typeNameRepresentation() const
{
if (type == ModelItemInfo::Declaration) {
......@@ -112,7 +124,7 @@ struct CPPTOOLS_EXPORT ModelItemInfo
QString shortNativeFilePath() const
{ return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(fileName)); }
QString symbolName;
QString symbolName; // as found in the code, therefore might be qualified
QString symbolType;
QString symbolScope;
QString fileName;
......
......@@ -20,8 +20,11 @@ public:
MyClass() {}
int function1();
int function2(bool yesno, int number) {}
int functionDefinedOutSideClass(char c);
};
int MyClass::functionDefinedOutSideClass(char c) {}
//
// Symbols in a named namespace
//
......@@ -40,10 +43,16 @@ public:
MyClass() {}
int function1();
int function2(bool yesno, int number) {}
int functionDefinedOutSideClass(char c);
int functionDefinedOutSideClassAndNamespace(float x);
};
int MyClass::functionDefinedOutSideClass(char c) {}
} // namespace MyNamespace
int MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace(float x) {}
//
// Symbols in an anonymous namespace
//
......@@ -62,6 +71,12 @@ public:
MyClass() {}
int function1();
int function2(bool yesno, int number) {}
int functionDefinedOutSideClass(char c);
};
int MyClass::functionDefinedOutSideClass(char c) {}
} // anonymous namespace
int main() {}
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