CppEditor: Add second "Find References" Action

This one includes access type categorization, while the "normal" one
does not.
We need this now, because with clangd, the categorization is too slow to
enable it by default.

Change-Id: I2eb4608630d34452ae28f0836befd5d9053f42bf
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-05-26 17:24:18 +02:00
parent a09851ff1f
commit a5ba33cbeb
9 changed files with 102 additions and 64 deletions

View File

@@ -45,13 +45,15 @@
using namespace CPlusPlus; using namespace CPlusPlus;
FindUsages::FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot) FindUsages::FindUsages(const QByteArray &originalSource, Document::Ptr doc,
const Snapshot &snapshot, bool categorize)
: ASTVisitor(doc->translationUnit()), : ASTVisitor(doc->translationUnit()),
_doc(doc), _doc(doc),
_snapshot(snapshot), _snapshot(snapshot),
_context(doc, snapshot), _context(doc, snapshot),
_originalSource(originalSource), _originalSource(originalSource),
_source(_doc->utf8Source()) _source(_doc->utf8Source()),
_categorize(categorize)
{ {
_snapshot.insert(_doc); _snapshot.insert(_doc);
typeofExpression.init(_doc, _snapshot, _context.bindings()); typeofExpression.init(_doc, _snapshot, _context.bindings());
@@ -465,6 +467,8 @@ private:
Usage::Type FindUsages::getType(int line, int column, int tokenIndex) Usage::Type FindUsages::getType(int line, int column, int tokenIndex)
{ {
if (!_categorize)
return Usage::Type::Other;
return GetUsageType(this, ASTPath(_doc)(line, column), tokenIndex).getUsageType(); return GetUsageType(this, ASTPath(_doc)(line, column), tokenIndex).getUsageType();
} }

View File

@@ -56,7 +56,8 @@ public:
class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor class CPLUSPLUS_EXPORT FindUsages: protected ASTVisitor
{ {
public: public:
FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot); FindUsages(const QByteArray &originalSource, Document::Ptr doc, const Snapshot &snapshot,
bool categorize);
FindUsages(const LookupContext &context); FindUsages(const LookupContext &context);
void operator()(Symbol *symbol); void operator()(Symbol *symbol);
@@ -302,6 +303,7 @@ private:
QSet<unsigned> _processed; QSet<unsigned> _processed;
TypeOfExpression typeofExpression; TypeOfExpression typeofExpression;
Scope *_currentScope = nullptr; Scope *_currentScope = nullptr;
const bool _categorize = false;
class GetUsageType; class GetUsageType;
}; };

View File

@@ -386,6 +386,7 @@ public:
Utils::optional<ReplacementData> replacementData; Utils::optional<ReplacementData> replacementData;
quint64 key; quint64 key;
bool canceled = false; bool canceled = false;
bool categorize = CppTools::codeModelSettings()->categorizeFindReferences();
}; };
using SymbolData = QPair<QString, Utils::Link>; using SymbolData = QPair<QString, Utils::Link>;
@@ -594,6 +595,7 @@ void ClangdClient::findUsages(TextEditor::TextDocument *document, const QTextCur
replacement ? SearchResultWindow::SearchAndReplace : SearchResultWindow::SearchOnly, replacement ? SearchResultWindow::SearchAndReplace : SearchResultWindow::SearchOnly,
SearchResultWindow::PreserveCaseDisabled, SearchResultWindow::PreserveCaseDisabled,
"CppEditor"); "CppEditor");
if (refData.categorize)
refData.search->setFilter(new CppTools::CppSearchResultFilter); refData.search->setFilter(new CppTools::CppSearchResultFilter);
if (refData.replacementData) { if (refData.replacementData) {
refData.search->setTextToReplace(refData.replacementData->newSymbolName); refData.search->setTextToReplace(refData.replacementData->newSymbolName);
@@ -699,7 +701,7 @@ void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Loca
qCDebug(clangdLog) << "document count is" << refData->fileData.size(); qCDebug(clangdLog) << "document count is" << refData->fileData.size();
if (refData->replacementData || q->versionNumber() < QVersionNumber(13) if (refData->replacementData || q->versionNumber() < QVersionNumber(13)
|| refData->fileData.size() > 15) { // TODO: If we need to keep this, make it configurable. || !refData->categorize) {
qCDebug(clangdLog) << "skipping AST retrieval"; qCDebug(clangdLog) << "skipping AST retrieval";
reportAllSearchResultsAndFinish(*refData); reportAllSearchResultsAndFinish(*refData);
return; return;

View File

@@ -147,6 +147,7 @@ ClangdTestFindReferences::ClangdTestFindReferences()
void ClangdTestFindReferences::initTestCase() void ClangdTestFindReferences::initTestCase()
{ {
ClangdTest::initTestCase(); ClangdTest::initTestCase();
CppTools::codeModelSettings()->setCategorizeFindReferences(true);
connect(client(), &ClangdClient::foundReferences, this, connect(client(), &ClangdClient::foundReferences, this,
[this](const QList<SearchResultItem> &results) { [this](const QList<SearchResultItem> &results) {
if (results.isEmpty()) if (results.isEmpty())

View File

@@ -56,8 +56,10 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/navigationwidget.h> #include <coreplugin/navigationwidget.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cpphoverhandler.h> #include <cpptools/cpphoverhandler.h>
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <cpptools/cpptoolsreuse.h>
#include <projectexplorer/projectpanelfactory.h> #include <projectexplorer/projectpanelfactory.h>
#include <texteditor/colorpreviewhoverhandler.h> #include <texteditor/colorpreviewhoverhandler.h>
#include <texteditor/snippets/snippetprovider.h> #include <texteditor/snippets/snippetprovider.h>
@@ -81,6 +83,13 @@ namespace Internal {
enum { QUICKFIX_INTERVAL = 20 }; enum { QUICKFIX_INTERVAL = 20 };
static CppEditorWidget *currentCppEditorWidget()
{
if (IEditor *currentEditor = EditorManager::currentEditor())
return qobject_cast<CppEditorWidget*>(currentEditor->widget());
return nullptr;
}
//////////////////////////// CppEditorFactory ///////////////////////////// //////////////////////////// CppEditorFactory /////////////////////////////
class CppEditorFactory : public TextEditorFactory class CppEditorFactory : public TextEditorFactory
@@ -123,6 +132,7 @@ public:
void inspectCppCodeModel(); void inspectCppCodeModel();
QAction *m_reparseExternallyChangedFiles = nullptr; QAction *m_reparseExternallyChangedFiles = nullptr;
QAction *m_findRefsCategorizedAction = nullptr;
QAction *m_openTypeHierarchyAction = nullptr; QAction *m_openTypeHierarchyAction = nullptr;
QAction *m_openIncludeHierarchyAction = nullptr; QAction *m_openIncludeHierarchyAction = nullptr;
@@ -241,6 +251,19 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST); contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
cppToolsMenu->addAction(cmd); cppToolsMenu->addAction(cmd);
d->m_findRefsCategorizedAction = new QAction(tr("Find References With Access Type"), this);
cmd = ActionManager::registerAction(d->m_findRefsCategorizedAction,
"CppEditor.FindRefsCategorized", context);
connect(d->m_findRefsCategorizedAction, &QAction::triggered, this, [] {
if (const auto w = currentCppEditorWidget()) {
codeModelSettings()->setCategorizeFindReferences(true);
w->findUsages();
codeModelSettings()->setCategorizeFindReferences(false);
}
});
contextMenu->addAction(cmd, Constants::G_CONTEXT_FIRST);
cppToolsMenu->addAction(cmd);
d->m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this); d->m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this);
cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context); cmd = ActionManager::registerAction(d->m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+T") : tr("Ctrl+Shift+T"))); cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? tr("Meta+Shift+T") : tr("Ctrl+Shift+T")));
@@ -313,13 +336,6 @@ void CppEditorPlugin::extensionsInitialized()
} }
} }
static CppEditorWidget *currentCppEditorWidget()
{
if (IEditor *currentEditor = EditorManager::currentEditor())
return qobject_cast<CppEditorWidget*>(currentEditor->widget());
return nullptr;
}
void CppEditorPlugin::switchDeclarationDefinition() void CppEditorPlugin::switchDeclarationDefinition()
{ {
if (CppEditorWidget *editorWidget = currentCppEditorWidget()) if (CppEditorWidget *editorWidget = currentCppEditorWidget())

View File

@@ -85,6 +85,9 @@ public:
void setClangdFilePath(const Utils::FilePath &filePath) { m_clangdFilePath = filePath; } void setClangdFilePath(const Utils::FilePath &filePath) { m_clangdFilePath = filePath; }
Utils::FilePath clangdFilePath() const; Utils::FilePath clangdFilePath() const;
void setCategorizeFindReferences(bool categorize) { m_categorizeFindReferences = categorize; }
bool categorizeFindReferences() const { return m_categorizeFindReferences; }
signals: signals:
void clangDiagnosticConfigsInvalidated(const QVector<Utils::Id> &configId); void clangDiagnosticConfigsInvalidated(const QVector<Utils::Id> &configId);
void changed(); void changed();
@@ -99,6 +102,7 @@ private:
bool m_enableLowerClazyLevels = true; // For UI behavior only bool m_enableLowerClazyLevels = true; // For UI behavior only
Utils::FilePath m_clangdFilePath; Utils::FilePath m_clangdFilePath;
bool m_useClangd = false; bool m_useClangd = false;
bool m_categorizeFindReferences = false; // Ephemeral!
}; };
} // namespace CppTools } // namespace CppTools

View File

@@ -25,9 +25,11 @@
#include "cppfindreferences.h" #include "cppfindreferences.h"
#include "cppcodemodelsettings.h"
#include "cppfilesettingspage.h" #include "cppfilesettingspage.h"
#include "cpptoolsconstants.h" #include "cpptoolsconstants.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cpptoolsreuse.h"
#include "cppworkingcopy.h" #include "cppworkingcopy.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -295,6 +297,7 @@ class ProcessFile
CPlusPlus::Document::Ptr symbolDocument; CPlusPlus::Document::Ptr symbolDocument;
CPlusPlus::Symbol *symbol; CPlusPlus::Symbol *symbol;
QFutureInterface<CPlusPlus::Usage> *future; QFutureInterface<CPlusPlus::Usage> *future;
const bool categorize;
public: public:
// needed by QtConcurrent // needed by QtConcurrent
@@ -305,12 +308,14 @@ public:
const CPlusPlus::Snapshot snapshot, const CPlusPlus::Snapshot snapshot,
CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Document::Ptr symbolDocument,
CPlusPlus::Symbol *symbol, CPlusPlus::Symbol *symbol,
QFutureInterface<CPlusPlus::Usage> *future) QFutureInterface<CPlusPlus::Usage> *future,
bool categorize)
: workingCopy(workingCopy), : workingCopy(workingCopy),
snapshot(snapshot), snapshot(snapshot),
symbolDocument(symbolDocument), symbolDocument(symbolDocument),
symbol(symbol), symbol(symbol),
future(future) future(future),
categorize(categorize)
{ } { }
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName) QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName)
@@ -342,7 +347,7 @@ public:
if (doc != symbolDocument) if (doc != symbolDocument)
doc->check(); doc->check();
CPlusPlus::FindUsages process(unpreprocessedSource, doc, snapshot); CPlusPlus::FindUsages process(unpreprocessedSource, doc, snapshot, categorize);
process(symbol); process(symbol);
usages = process.usages(); usages = process.usages();
@@ -395,7 +400,8 @@ QList<int> CppFindReferences::references(CPlusPlus::Symbol *symbol,
static void find_helper(QFutureInterface<CPlusPlus::Usage> &future, static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
const WorkingCopy workingCopy, const WorkingCopy workingCopy,
const CPlusPlus::LookupContext &context, const CPlusPlus::LookupContext &context,
CPlusPlus::Symbol *symbol) CPlusPlus::Symbol *symbol,
bool categorize)
{ {
const CPlusPlus::Identifier *symbolId = symbol->identifier(); const CPlusPlus::Identifier *symbolId = symbol->identifier();
QTC_ASSERT(symbolId != nullptr, return); QTC_ASSERT(symbolId != nullptr, return);
@@ -428,7 +434,7 @@ static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
future.setProgressRange(0, files.size()); future.setProgressRange(0, files.size());
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future); ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future, categorize);
UpdateUI reduce(&future); UpdateUI reduce(&future);
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count // This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
// so the blockingMappedReduced can use one more thread, and increase it again afterwards. // so the blockingMappedReduced can use one more thread, and increase it again afterwards.
@@ -458,6 +464,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
SearchResultWindow::PreserveCaseDisabled, SearchResultWindow::PreserveCaseDisabled,
QLatin1String("CppEditor")); QLatin1String("CppEditor"));
search->setTextToReplace(replacement); search->setTextToReplace(replacement);
if (codeModelSettings()->categorizeFindReferences())
search->setFilter(new CppSearchResultFilter); search->setFilter(new CppSearchResultFilter);
auto renameFilesCheckBox = new QCheckBox(); auto renameFilesCheckBox = new QCheckBox();
renameFilesCheckBox->setVisible(false); renameFilesCheckBox->setVisible(false);
@@ -469,6 +476,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
CppFindReferencesParameters parameters; CppFindReferencesParameters parameters;
parameters.symbolId = fullIdForSymbol(symbol); parameters.symbolId = fullIdForSymbol(symbol);
parameters.symbolFileName = QByteArray(symbol->fileName()); parameters.symbolFileName = QByteArray(symbol->fileName());
parameters.categorize = codeModelSettings()->categorizeFindReferences();
if (symbol->isClass() || symbol->isForwardClassDeclaration()) { if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
CPlusPlus::Overview overview; CPlusPlus::Overview overview;
@@ -477,7 +485,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
} }
search->setUserData(QVariant::fromValue(parameters)); search->setUserData(QVariant::fromValue(parameters));
findAll_helper(search, symbol, context); findAll_helper(search, symbol, context, codeModelSettings()->categorizeFindReferences());
} }
void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol,
@@ -492,7 +500,7 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol,
} }
void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol *symbol, void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context) const CPlusPlus::LookupContext &context, bool categorize)
{ {
if (!(symbol && symbol->identifier())) { if (!(symbol && symbol->identifier())) {
search->finishSearch(false); search->finishSearch(false);
@@ -507,7 +515,7 @@ void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol *
const WorkingCopy workingCopy = m_modelManager->workingCopy(); const WorkingCopy workingCopy = m_modelManager->workingCopy();
QFuture<CPlusPlus::Usage> result; QFuture<CPlusPlus::Usage> result;
result = Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper, result = Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
workingCopy, context, symbol); workingCopy, context, symbol, categorize);
createWatcher(result, search); createWatcher(result, search);
FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"), FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"),
@@ -553,7 +561,7 @@ void CppFindReferences::searchAgain()
search->finishSearch(false); search->finishSearch(false);
return; return;
} }
findAll_helper(search, symbol, context); findAll_helper(search, symbol, context, parameters.categorize);
} }
namespace { namespace {

View File

@@ -75,6 +75,7 @@ public:
QByteArray symbolFileName; QByteArray symbolFileName;
QString prettySymbolName; QString prettySymbolName;
QVector<ProjectExplorer::Node *> filesToRename; QVector<ProjectExplorer::Node *> filesToRename;
bool categorize = false;
}; };
class CppFindReferences: public QObject class CppFindReferences: public QObject
@@ -104,7 +105,7 @@ private:
void findMacroUses(const CPlusPlus::Macro &macro, const QString &replacement, void findMacroUses(const CPlusPlus::Macro &macro, const QString &replacement,
bool replace); bool replace);
void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol, void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context); const CPlusPlus::LookupContext &context, bool categorize);
void createWatcher(const QFuture<CPlusPlus::Usage> &future, Core::SearchResult *search); void createWatcher(const QFuture<CPlusPlus::Usage> &future, Core::SearchResult *search);
CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters &parameters, CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters &parameters,
const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context); const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context);

View File

@@ -175,7 +175,7 @@ void tst_FindUsages::inlineMethod()
QVERIFY(arg); QVERIFY(arg);
QCOMPARE(arg->identifier()->chars(), "arg"); QCOMPARE(arg->identifier()->chars(), "arg");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(arg); findUsages(arg);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -210,7 +210,7 @@ void tst_FindUsages::lambdaCaptureByValue()
QVERIFY(d); QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "test"); QCOMPARE(d->name()->identifier()->chars(), "test");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(d); findUsages(d);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -245,7 +245,7 @@ void tst_FindUsages::lambdaCaptureByReference()
QVERIFY(d); QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "test"); QCOMPARE(d->name()->identifier()->chars(), "test");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(d); findUsages(d);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -279,7 +279,7 @@ void tst_FindUsages::shadowedNames_1()
QVERIFY(d); QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "a"); QCOMPARE(d->name()->identifier()->chars(), "a");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(d); findUsages(d);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -314,7 +314,7 @@ void tst_FindUsages::shadowedNames_2()
QVERIFY(d); QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "a"); QCOMPARE(d->name()->identifier()->chars(), "a");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(d); findUsages(d);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -363,7 +363,7 @@ void tst_FindUsages::staticVariables()
QVERIFY(d); QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "Foo"); QCOMPARE(d->name()->identifier()->chars(), "Foo");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(d); findUsages(d);
QCOMPARE(findUsages.usages().size(), 5); QCOMPARE(findUsages.usages().size(), 5);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -398,7 +398,7 @@ void foo2(int b=bar()){} // 3rd result
Snapshot snapshot; Snapshot snapshot;
snapshot.insert(doc); snapshot.insert(doc);
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(s); find(s);
QCOMPARE(find.usages().size(), 3); QCOMPARE(find.usages().size(), 3);
@@ -465,7 +465,7 @@ struct Struct{
Snapshot snapshot; Snapshot snapshot;
snapshot.insert(doc); snapshot.insert(doc);
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(memberFunctionFoo); find(memberFunctionFoo);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
@@ -539,7 +539,7 @@ int main() {
Snapshot snapshot; Snapshot snapshot;
snapshot.insert(doc); snapshot.insert(doc);
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 7); QCOMPARE(find.usages().size(), 7);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -598,7 +598,7 @@ int main()
Snapshot snapshot; Snapshot snapshot;
snapshot.insert(doc); snapshot.insert(doc);
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 7); QCOMPARE(find.usages().size(), 7);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -663,7 +663,7 @@ void tst_FindUsages::objc_args()
Argument *arg = methodImpl->argumentAt(0)->asArgument(); Argument *arg = methodImpl->argumentAt(0)->asArgument();
QCOMPARE(arg->identifier()->chars(), "arg"); QCOMPARE(arg->identifier()->chars(), "arg");
FindUsages findUsages(objcSource, doc, snapshot); FindUsages findUsages(objcSource, doc, snapshot, true);
findUsages(arg); findUsages(arg);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.references().size(), 2); QCOMPARE(findUsages.references().size(), 2);
@@ -701,7 +701,7 @@ void tst_FindUsages::qproperty_1()
QCOMPARE(setX_method->identifier()->chars(), "setX"); QCOMPARE(setX_method->identifier()->chars(), "setX");
QCOMPARE(setX_method->argumentCount(), 1); QCOMPARE(setX_method->argumentCount(), 1);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(setX_method); findUsages(setX_method);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Other); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Other);
@@ -747,7 +747,7 @@ void tst_FindUsages::instantiateTemplateWithNestedClass()
QVERIFY(barDeclaration); QVERIFY(barDeclaration);
QCOMPARE(barDeclaration->name()->identifier()->chars(), "bar"); QCOMPARE(barDeclaration->name()->identifier()->chars(), "bar");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(barDeclaration); findUsages(barDeclaration);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -793,7 +793,7 @@ void tst_FindUsages::operatorAsteriskOfNestedClassOfTemplateClass_QTCREATORBUG90
QVERIFY(fooDeclaration); QVERIFY(fooDeclaration);
QCOMPARE(fooDeclaration->name()->identifier()->chars(), "foo"); QCOMPARE(fooDeclaration->name()->identifier()->chars(), "foo");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(fooDeclaration); findUsages(fooDeclaration);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
@@ -838,7 +838,7 @@ void tst_FindUsages::anonymousClass_QTCREATORBUG8963()
QVERIFY(isNotIntDeclaration); QVERIFY(isNotIntDeclaration);
QCOMPARE(isNotIntDeclaration->name()->identifier()->chars(), "isNotInt"); QCOMPARE(isNotIntDeclaration->name()->identifier()->chars(), "isNotInt");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(isNotIntDeclaration); findUsages(isNotIntDeclaration);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
@@ -881,7 +881,7 @@ void tst_FindUsages::anonymousClass_QTCREATORBUG11859()
QVERIFY(fooAsMemberOfAnonymousStruct); QVERIFY(fooAsMemberOfAnonymousStruct);
QCOMPARE(fooAsMemberOfAnonymousStruct->name()->identifier()->chars(), "Foo"); QCOMPARE(fooAsMemberOfAnonymousStruct->name()->identifier()->chars(), "Foo");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(fooAsStruct); findUsages(fooAsStruct);
QCOMPARE(findUsages.references().size(), 1); QCOMPARE(findUsages.references().size(), 1);
QCOMPARE(findUsages.usages().size(), 1); QCOMPARE(findUsages.usages().size(), 1);
@@ -927,7 +927,7 @@ void tst_FindUsages::using_insideGlobalNamespace()
Class *structSymbol = nsSymbol->memberAt(0)->asClass(); Class *structSymbol = nsSymbol->memberAt(0)->asClass();
QVERIFY(structSymbol); QVERIFY(structSymbol);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(structSymbol); findUsages(structSymbol);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
@@ -973,7 +973,7 @@ void tst_FindUsages::using_insideNamespace()
Class *structSymbol = nsSymbol->memberAt(0)->asClass(); Class *structSymbol = nsSymbol->memberAt(0)->asClass();
QVERIFY(structSymbol); QVERIFY(structSymbol);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(structSymbol); findUsages(structSymbol);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
@@ -1016,7 +1016,7 @@ void tst_FindUsages::using_insideFunction()
Class *structSymbol = nsSymbol->memberAt(0)->asClass(); Class *structSymbol = nsSymbol->memberAt(0)->asClass();
QVERIFY(structSymbol); QVERIFY(structSymbol);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(structSymbol); findUsages(structSymbol);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
@@ -1064,7 +1064,7 @@ void tst_FindUsages::operatorArrowOfNestedClassOfTemplateClass_QTCREATORBUG9005(
QVERIFY(fooDeclaration); QVERIFY(fooDeclaration);
QCOMPARE(fooDeclaration->name()->identifier()->chars(), "foo"); QCOMPARE(fooDeclaration->name()->identifier()->chars(), "foo");
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(fooDeclaration); findUsages(fooDeclaration);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1101,7 +1101,7 @@ void tst_FindUsages::templateClassParameters()
TypenameArgument *templArgument = templateClassTS->templateParameterAt(0)->asTypenameArgument(); TypenameArgument *templArgument = templateClassTS->templateParameterAt(0)->asTypenameArgument();
QVERIFY(templArgument); QVERIFY(templArgument);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(templArgument); findUsages(templArgument);
QCOMPARE(findUsages.usages().size(), 5); QCOMPARE(findUsages.usages().size(), 5);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1147,7 +1147,7 @@ void tst_FindUsages::templateClass_className()
QVERIFY(classTS); QVERIFY(classTS);
QCOMPARE(classTS->memberCount(), 2); QCOMPARE(classTS->memberCount(), 2);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(classTS); findUsages(classTS);
QCOMPARE(findUsages.usages().size(), 7); QCOMPARE(findUsages.usages().size(), 7);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1187,7 +1187,7 @@ void tst_FindUsages::templateFunctionParameters()
TypenameArgument *templArgument = templateFunctionTS->templateParameterAt(0)->asTypenameArgument(); TypenameArgument *templArgument = templateFunctionTS->templateParameterAt(0)->asTypenameArgument();
QVERIFY(templArgument); QVERIFY(templArgument);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(templArgument); findUsages(templArgument);
QCOMPARE(findUsages.usages().size(), 4); QCOMPARE(findUsages.usages().size(), 4);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1221,7 +1221,7 @@ void tst_FindUsages::templatedFunction_QTCREATORBUG9749()
QCOMPARE(funcTempl->memberCount(), 2); QCOMPARE(funcTempl->memberCount(), 2);
Function *func = funcTempl->memberAt(1)->asFunction(); Function *func = funcTempl->memberAt(1)->asFunction();
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(func); findUsages(func);
QCOMPARE(findUsages.usages().size(), 2); QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1262,7 +1262,7 @@ void tst_FindUsages::usingInDifferentNamespace_QTCREATORBUG7978()
QCOMPARE(ns->memberCount(), 1); QCOMPARE(ns->memberCount(), 1);
Template *templateClass = ns->memberAt(0)->asTemplate(); Template *templateClass = ns->memberAt(0)->asTemplate();
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(templateClass); findUsages(templateClass);
QCOMPARE(findUsages.usages().size(), 3); QCOMPARE(findUsages.usages().size(), 3);
QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(findUsages.usages().at(0).type, Usage::Type::Declaration);
@@ -1291,7 +1291,7 @@ void tst_FindUsages::unicodeIdentifier()
Declaration *declaration = doc->globalSymbolAt(0)->asDeclaration(); Declaration *declaration = doc->globalSymbolAt(0)->asDeclaration();
QVERIFY(declaration); QVERIFY(declaration);
FindUsages findUsages(src, doc, snapshot); FindUsages findUsages(src, doc, snapshot, true);
findUsages(declaration); findUsages(declaration);
const QList<Usage> usages = findUsages.usages(); const QList<Usage> usages = findUsages.usages();
QCOMPARE(usages.size(), 2); QCOMPARE(usages.size(), 2);
@@ -1323,7 +1323,7 @@ void tst_FindUsages::inAlignas()
QVERIFY(c); QVERIFY(c);
QCOMPARE(c->name()->identifier()->chars(), "One"); QCOMPARE(c->name()->identifier()->chars(), "One");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(c); find(c);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages()[0].type, Usage::Type::Declaration); QCOMPARE(find.usages()[0].type, Usage::Type::Declaration);
@@ -1366,7 +1366,7 @@ void tst_FindUsages::memberAccessAsTemplate()
QVERIFY(c); QVERIFY(c);
QCOMPARE(c->name()->identifier()->chars(), "Foo"); QCOMPARE(c->name()->identifier()->chars(), "Foo");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(c); find(c);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages()[0].type, Usage::Type::Declaration); QCOMPARE(find.usages()[0].type, Usage::Type::Declaration);
@@ -1387,7 +1387,7 @@ void tst_FindUsages::memberAccessAsTemplate()
QVERIFY(f); QVERIFY(f);
QCOMPARE(f->name()->identifier()->chars(), "templateFunc"); QCOMPARE(f->name()->identifier()->chars(), "templateFunc");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(f); find(f);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages()[0].type, Usage::Type::Declaration); QCOMPARE(find.usages()[0].type, Usage::Type::Declaration);
@@ -1430,7 +1430,7 @@ void tst_FindUsages::variadicFunctionTemplate()
QVERIFY(v); QVERIFY(v);
QCOMPARE(v->name()->identifier()->chars(), "value"); QCOMPARE(v->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(v); find(v);
QCOMPARE(find.usages().size(), 4); QCOMPARE(find.usages().size(), 4);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -1481,7 +1481,7 @@ void tst_FindUsages::typeTemplateParameterWithDefault()
QVERIFY(sv); QVERIFY(sv);
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(xv); find(xv);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -1525,7 +1525,7 @@ void tst_FindUsages::resolveOrder_for_templateFunction_vs_function()
QVERIFY(xv); QVERIFY(xv);
QCOMPARE(xv->name()->identifier()->chars(), "value"); QCOMPARE(xv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(xv); find(xv);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -1567,7 +1567,7 @@ void tst_FindUsages::templateArrowOperator_with_defaultType()
QVERIFY(sv); QVERIFY(sv);
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 3); QCOMPARE(find.usages().size(), 3);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -1639,7 +1639,7 @@ void tst_FindUsages::templateSpecialization_with_IntArgument()
QCOMPARE(sv[1]->name()->identifier()->chars(), "value"); QCOMPARE(sv[1]->name()->identifier()->chars(), "value");
QCOMPARE(sv[2]->name()->identifier()->chars(), "value"); QCOMPARE(sv[2]->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv[0]); find(sv[0]);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
@@ -1726,7 +1726,7 @@ void tst_FindUsages::templateSpecialization_with_BoolArgument()
QCOMPARE(sv[0]->name()->identifier()->chars(), "value"); QCOMPARE(sv[0]->name()->identifier()->chars(), "value");
QCOMPARE(sv[1]->name()->identifier()->chars(), "value"); QCOMPARE(sv[1]->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv[0]); find(sv[0]);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
@@ -1802,7 +1802,7 @@ void tst_FindUsages::templatePartialSpecialization()
QCOMPARE(sv[0]->name()->identifier()->chars(), "value"); QCOMPARE(sv[0]->name()->identifier()->chars(), "value");
QCOMPARE(sv[1]->name()->identifier()->chars(), "value"); QCOMPARE(sv[1]->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv[0]); find(sv[0]);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
@@ -1858,7 +1858,7 @@ int main()
Snapshot snapshot; Snapshot snapshot;
snapshot.insert(doc); snapshot.insert(doc);
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
Class *s[3]; Class *s[3];
Declaration *sv[3]; Declaration *sv[3];
@@ -1923,7 +1923,7 @@ int main(){
QVERIFY(sv); QVERIFY(sv);
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages().at(0).type, Usage::Type::Initialization); QCOMPARE(find.usages().at(0).type, Usage::Type::Initialization);
@@ -1968,7 +1968,7 @@ int main(){
QVERIFY(sv); QVERIFY(sv);
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -2008,7 +2008,7 @@ int main(){}
QVERIFY(sv); QVERIFY(sv);
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 2); QCOMPARE(find.usages().size(), 2);
QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration); QCOMPARE(find.usages().at(0).type, Usage::Type::Declaration);
@@ -2121,7 +2121,7 @@ int main()
QCOMPARE(sv->name()->identifier()->chars(), "value"); QCOMPARE(sv->name()->identifier()->chars(), "value");
// Access to struct member // Access to struct member
FindUsages find(src, doc, snapshot); FindUsages find(src, doc, snapshot, true);
find(sv); find(sv);
QCOMPARE(find.usages().size(), 31); QCOMPARE(find.usages().size(), 31);
QCOMPARE(find.usages().at(0).type, Usage::Type::Read); QCOMPARE(find.usages().at(0).type, Usage::Type::Read);