CppTools: Get rid of SearchSymbols::setSeparateScope()

This will make it easier to use a single SearchSymbols instance and a
single run serving all locator filters.

Change-Id: Idb6a3693ad356227d46d0b28fb4c3a5db62b4ac4
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-08-20 17:16:25 +02:00
parent 7e09b90723
commit 760aa0f8bc
12 changed files with 165 additions and 95 deletions

View File

@@ -42,9 +42,8 @@ SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
| SymbolSearcher::Enums
| SymbolSearcher::Declarations;
SearchSymbols::SearchSymbols():
symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums),
separateScope(false)
SearchSymbols::SearchSymbols() :
symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums)
{
}
@@ -53,11 +52,6 @@ void SearchSymbols::setSymbolsToSearchFor(SymbolTypes types)
symbolsToSearchFor = types;
}
void SearchSymbols::setSeparateScope(bool separateScope)
{
this->separateScope = separateScope;
}
QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, int sizeHint, const QString &scope)
{
QString previousScope = switchScope(scope);
@@ -89,9 +83,7 @@ bool SearchSymbols::visit(Enum *symbol)
QString name = symbolName(symbol);
QString scopedName = scopedSymbolName(name);
QString previousScope = switchScope(scopedName);
appendItem(separateScope ? name : scopedName,
separateScope ? previousScope : QString(),
ModelItemInfo::Enum, symbol);
appendItem(name, QString(), previousScope, ModelItemInfo::Enum, symbol);
for (unsigned i = 0; i < symbol->memberCount(); ++i) {
accept(symbol->memberAt(i));
}
@@ -116,12 +108,8 @@ bool SearchSymbols::visit(Function *symbol)
fullScope += QLatin1String("::");
fullScope += extraScope;
QString name = symbolName(symbol);
QString scopedName = scopedSymbolName(name);
QString type = overview.prettyType(symbol->type(),
separateScope ? symbol->unqualifiedName() : 0);
appendItem(separateScope ? type : scopedName,
separateScope ? fullScope : type,
ModelItemInfo::Method, symbol);
QString type = overview.prettyType(symbol->type());
appendItem(name, type, fullScope, ModelItemInfo::Method, symbol);
return false;
}
@@ -152,11 +140,8 @@ bool SearchSymbols::visit(Declaration *symbol)
}
QString name = symbolName(symbol);
QString scopedName = scopedSymbolName(name);
QString type = overview.prettyType(symbol->type(),
separateScope ? symbol->unqualifiedName() : 0);
appendItem(separateScope ? type : scopedName,
separateScope ? _scope : type,
QString type = overview.prettyType(symbol->type());
appendItem(name, type, _scope,
symbol->type()->asFunctionType() ? ModelItemInfo::Method
: ModelItemInfo::Declaration,
symbol);
@@ -169,9 +154,7 @@ bool SearchSymbols::visit(Class *symbol)
QString scopedName = scopedSymbolName(name);
QString previousScope = switchScope(scopedName);
if (symbolsToSearchFor & SymbolSearcher::Classes) {
appendItem(separateScope ? name : scopedName,
separateScope ? previousScope : QString(),
ModelItemInfo::Class, symbol);
appendItem(name, QString(), previousScope, ModelItemInfo::Class, symbol);
}
for (unsigned i = 0; i < symbol->memberCount(); ++i) {
accept(symbol->memberAt(i));
@@ -305,18 +288,13 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
return symbolName;
}
void SearchSymbols::appendItem(const QString &name,
const QString &info,
ModelItemInfo::ItemType type,
void SearchSymbols::appendItem(const QString &symbolName, const QString &symbolType,
const QString &symbolScope, ModelItemInfo::ItemType itemType,
Symbol *symbol)
{
if (!symbol->name())
return;
QStringList fullyQualifiedName;
foreach (const Name *name, LookupContext::fullyQualifiedName(symbol))
fullyQualifiedName.append(findOrInsert(overview.prettyName(name)));
QString path = m_paths.value(symbol->fileId(), QString());
if (path.isEmpty()) {
path = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
@@ -324,8 +302,10 @@ void SearchSymbols::appendItem(const QString &name,
}
const QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(findOrInsert(name), findOrInsert(info), type,
fullyQualifiedName,
items.append(ModelItemInfo(findOrInsert(symbolName),
findOrInsert(symbolType),
findOrInsert(symbolScope),
itemType,
path,
symbol->line(),
symbol->column() - 1, // 1-based vs 0-based column