From 4b0bcbdcb6b28e806de4ba31fa5fecd06fd9188e Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Mon, 9 Apr 2018 13:30:30 +0200 Subject: [PATCH] Clang: Locator filter for the symbol database There are no symbol queries for the locator filters. The signature generation is still not implemented but for simple cases it should work. Change-Id: Ic6b04fbe1e7e057892f194ac139615c47d6ec33f Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/clangsupport_global.h | 13 ++ .../refactoringdatabaseinitializer.h | 7 +- src/libs/utils/sizedarray.h | 7 + .../clangrefactoring-source.pri | 19 +-- .../clangrefactoring/clangrefactoring.pro | 14 +- .../clangrefactoringplugin.cpp | 39 ++++-- .../clangrefactoring/classesfilter.cpp | 66 --------- src/plugins/clangrefactoring/classesfilter.h | 49 ------- .../{include.h => editormanagerinterface.h} | 26 +++- src/plugins/clangrefactoring/enum.h | 33 ----- .../clangrefactoring/functionsfilter.cpp | 66 --------- .../clangrefactoring/functionsfilter.h | 49 ------- .../clangrefactoring/includesfilter.cpp | 67 --------- src/plugins/clangrefactoring/includesfilter.h | 49 ------- .../clangrefactoring/locatorfilter.cpp | 50 +++---- src/plugins/clangrefactoring/locatorfilter.h | 20 ++- .../clangrefactoring/qtcreatorclassesfilter.h | 41 ------ ...sfilter.cpp => qtcreatoreditormanager.cpp} | 18 ++- .../{class.h => qtcreatoreditormanager.h} | 24 +++- .../qtcreatorfunctionsfilter.cpp | 40 ------ .../qtcreatorfunctionsfilter.h | 41 ------ .../qtcreatorincludesfilter.cpp | 38 ------ .../qtcreatorincludesfilter.h | 41 ------ .../qtcreatorlocatorfilter.cpp | 40 ------ .../clangrefactoring/qtcreatorlocatorfilter.h | 41 ------ .../qtcreatorsymbolsfindfilter.cpp | 6 +- .../qtcreatorsymbolsfindfilter.h | 4 +- .../querysqlitestatementfactory.h | 12 ++ .../clangrefactoring/sourcelocations.h | 16 ++- src/plugins/clangrefactoring/symbol.h | 25 +++- src/plugins/clangrefactoring/symbolquery.h | 48 ++++++- .../clangrefactoring/symbolqueryinterface.h | 18 +-- .../collectmacrospreprocessorcallbacks.h | 14 +- .../source/indexdataconsumer.cpp | 12 +- .../source/sourcelocationentry.h | 19 +-- .../source/storagesqlitestatementfactory.h | 5 +- .../source/symbolstorage.h | 11 +- tests/unit/unittest/classesfilter-test.cpp | 64 --------- tests/unit/unittest/functionsfilter-test.cpp | 64 --------- .../unit/unittest/gtest-creator-printing.cpp | 45 +++++-- tests/unit/unittest/gtest-creator-printing.h | 6 + tests/unit/unittest/includesfilter-test.cpp | 64 --------- tests/unit/unittest/locatorfilter-test.cpp | 95 ++++++++++--- .../unit/unittest/mockeditormanager.h | 21 +-- .../unit/unittest/mocksqlitereadstatement.cpp | 42 ++++++ tests/unit/unittest/mocksqlitereadstatement.h | 43 ++++++ .../unit/unittest/mocksqlitewritestatement.h | 3 + tests/unit/unittest/mocksymbolquery.h | 12 +- .../refactoringdatabaseinitializer-test.cpp | 14 +- tests/unit/unittest/sizedarray-test.cpp | 9 ++ .../storagesqlitestatementfactory-test.cpp | 8 +- tests/unit/unittest/symbolindexer-test.cpp | 4 +- tests/unit/unittest/symbolindexing-test.cpp | 4 +- tests/unit/unittest/symbolquery-test.cpp | 127 ++++++++++++++---- tests/unit/unittest/symbolscollector-test.cpp | 32 ++--- tests/unit/unittest/symbolstorage-test.cpp | 14 +- tests/unit/unittest/unittest.pro | 8 +- 57 files changed, 649 insertions(+), 1118 deletions(-) delete mode 100644 src/plugins/clangrefactoring/classesfilter.cpp delete mode 100644 src/plugins/clangrefactoring/classesfilter.h rename src/plugins/clangrefactoring/{include.h => editormanagerinterface.h} (65%) delete mode 100644 src/plugins/clangrefactoring/enum.h delete mode 100644 src/plugins/clangrefactoring/functionsfilter.cpp delete mode 100644 src/plugins/clangrefactoring/functionsfilter.h delete mode 100644 src/plugins/clangrefactoring/includesfilter.cpp delete mode 100644 src/plugins/clangrefactoring/includesfilter.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorclassesfilter.h rename src/plugins/clangrefactoring/{qtcreatorclassesfilter.cpp => qtcreatoreditormanager.cpp} (70%) rename src/plugins/clangrefactoring/{class.h => qtcreatoreditormanager.h} (71%) delete mode 100644 src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorincludesfilter.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorlocatorfilter.h delete mode 100644 tests/unit/unittest/classesfilter-test.cpp delete mode 100644 tests/unit/unittest/functionsfilter-test.cpp delete mode 100644 tests/unit/unittest/includesfilter-test.cpp rename src/plugins/clangrefactoring/function.h => tests/unit/unittest/mockeditormanager.h (79%) diff --git a/src/libs/clangsupport/clangsupport_global.h b/src/libs/clangsupport/clangsupport_global.h index d675d5fb11c..03f4528ee97 100644 --- a/src/libs/clangsupport/clangsupport_global.h +++ b/src/libs/clangsupport/clangsupport_global.h @@ -198,6 +198,17 @@ struct HighlightingTypes { MixinHighlightingTypes mixinHighlightingTypes; }; +enum class SourceLocationKind : uchar +{ + None = 0, + Declaration, + DeclarationReference, + Definition, + MacroDefinition = 128, + MacroUsage, + MacroUndefinition +}; + enum class SymbolKind : uchar { None = 0, @@ -208,6 +219,8 @@ enum class SymbolKind : uchar Macro }; +using SymbolKinds = Utils::SizedArray; + enum class SymbolTag : uchar { None = 0, diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index 1123c7c930d..0b212c3a58a 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -62,10 +62,11 @@ public: table.setName("symbols"); table.addColumn("symbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); - table.addColumn("symbolName", Sqlite::ColumnType::Text); + const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text); const Sqlite::Column &symbolKindColumn = table.addColumn("symbolKind", Sqlite::ColumnType::Integer); + table.addColumn("signature", Sqlite::ColumnType::Text); table.addIndex({usrColumn}); - table.addIndex({symbolKindColumn}); + table.addIndex({symbolKindColumn, symbolNameColumn}); table.initialize(database); } @@ -79,7 +80,9 @@ public: const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + const Sqlite::Column &locationKindColumn = table.addColumn("locationKind", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); + table.addIndex({sourceIdColumn, locationKindColumn}); table.initialize(database); } diff --git a/src/libs/utils/sizedarray.h b/src/libs/utils/sizedarray.h index 3be92560d5f..af7363b4a59 100644 --- a/src/libs/utils/sizedarray.h +++ b/src/libs/utils/sizedarray.h @@ -54,6 +54,13 @@ public: using std::array::rend; using std::array::crend; + constexpr SizedArray() = default; + constexpr SizedArray(std::initializer_list list) + : m_size(list.size()) + { + std::copy(list.begin(), list.end(), begin()); + } + constexpr size_type size() const { return m_size; diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri index 198f736e43f..b12d4a9b986 100644 --- a/src/plugins/clangrefactoring/clangrefactoring-source.pri +++ b/src/plugins/clangrefactoring/clangrefactoring-source.pri @@ -6,10 +6,6 @@ HEADERS += \ $$PWD/clangqueryhighlighter.h \ $$PWD/clangqueryhighlightmarker.h \ $$PWD/clangqueryprojectsfindfilter.h \ - $$PWD/classesfilter.h \ - $$PWD/functionsfilter.h \ - $$PWD/includesfilter.h \ - $$PWD/locatorfilter.h \ $$PWD/projectpartutilities.h \ $$PWD/refactoringclient.h \ $$PWD/refactoringconnectionclient.h \ @@ -20,24 +16,19 @@ HEADERS += \ $$PWD/symbolsfindfilter.h \ $$PWD/symbolqueryinterface.h \ $$PWD/symbol.h \ - $$PWD/class.h \ - $$PWD/enum.h \ - $$PWD/function.h \ - $$PWD/include.h \ - $$PWD/projectpartproviderinterface.h + $$PWD/projectpartproviderinterface.h \ + $$PWD/editormanagerinterface.h \ + $$PWD/locatorfilter.h SOURCES += \ $$PWD/clangqueryexamplehighlighter.cpp \ $$PWD/clangqueryhighlighter.cpp \ $$PWD/clangqueryprojectsfindfilter.cpp \ - $$PWD/classesfilter.cpp \ - $$PWD/functionsfilter.cpp \ - $$PWD/includesfilter.cpp \ - $$PWD/locatorfilter.cpp \ $$PWD/projectpartutilities.cpp \ $$PWD/refactoringclient.cpp \ $$PWD/refactoringconnectionclient.cpp \ $$PWD/refactoringengine.cpp \ $$PWD/refactoringprojectupdater.cpp \ $$PWD/searchhandle.cpp \ - $$PWD/symbolsfindfilter.cpp + $$PWD/symbolsfindfilter.cpp \ + $$PWD/locatorfilter.cpp diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro index cad6bac9792..e859631cbf7 100644 --- a/src/plugins/clangrefactoring/clangrefactoring.pro +++ b/src/plugins/clangrefactoring/clangrefactoring.pro @@ -14,17 +14,14 @@ HEADERS += \ clangqueryprojectsfindfilterwidget.h \ clangquerytexteditorwidget.h \ qtcreatorclangqueryfindfilter.h \ - qtcreatorclassesfilter.h \ - qtcreatorfunctionsfilter.h \ - qtcreatorincludesfilter.h \ - qtcreatorlocatorfilter.h \ qtcreatorsearch.h \ qtcreatorsearchhandle.h \ qtcreatorsymbolsfindfilter.h \ querysqlitestatementfactory.h \ sourcelocations.h \ symbolsfindfilterconfigwidget.h \ - symbolquery.h + symbolquery.h \ + qtcreatoreditormanager.h SOURCES += \ clangrefactoringplugin.cpp \ @@ -34,14 +31,11 @@ SOURCES += \ clangqueryprojectsfindfilterwidget.cpp \ clangquerytexteditorwidget.cpp \ qtcreatorclangqueryfindfilter.cpp \ - qtcreatorclassesfilter.cpp \ - qtcreatorincludesfilter.cpp \ - qtcreatorfunctionsfilter.cpp \ - qtcreatorlocatorfilter.cpp \ qtcreatorsearch.cpp \ qtcreatorsearchhandle.cpp \ qtcreatorsymbolsfindfilter.cpp \ - symbolsfindfilterconfigwidget.cpp + symbolsfindfilterconfigwidget.cpp \ + qtcreatoreditormanager.cpp FORMS += \ clangqueryprojectsfindfilter.ui diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp index afbc2f1a9cc..93dcfa910c6 100644 --- a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp +++ b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp @@ -24,11 +24,9 @@ ****************************************************************************/ #include "clangrefactoringplugin.h" -#include "qtcreatorclassesfilter.h" -#include "qtcreatorfunctionsfilter.h" -#include "qtcreatorincludesfilter.h" -#include "qtcreatorlocatorfilter.h" +#include "locatorfilter.h" #include "qtcreatorsymbolsfindfilter.h" +#include "qtcreatoreditormanager.h" #include "querysqlitestatementfactory.h" #include "sqlitedatabase.h" #include "sqlitereadstatement.h" @@ -41,6 +39,7 @@ #include #include +#include #include #include @@ -77,11 +76,11 @@ class ClangRefactoringPluginData public: using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory; - Sqlite::Database database{Utils::PathString{Core::ICore::userResourcePath() + "/symbol-experimental-v1.db"}, 1000ms}; ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; ClangBackEnd::FilePathCaching filePathCache{database}; RefactoringClient refactoringClient; + QtCreatorEditorManager editorManager{filePathCache}; ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient}; QuerySqliteReadStatementFactory statementFactory{database}; SymbolQuery symbolQuery{statementFactory}; @@ -110,7 +109,7 @@ static bool useClangFilters() bool ClangRefactoringPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/) { - d.reset(new ClangRefactoringPluginData); + d = std::make_unique(); d->refactoringClient.setRefactoringEngine(&d->engine); d->refactoringClient.setRefactoringConnectionClient(&d->connectionClient); @@ -175,11 +174,29 @@ void ClangRefactoringPlugin::initializeFilters() return; CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); - modelManager->setLocatorFilter(std::make_unique(d->symbolQuery)); - modelManager->setClassesFilter(std::make_unique(d->symbolQuery)); - modelManager->setIncludesFilter(std::make_unique(d->symbolQuery)); - modelManager->setFunctionsFilter(std::make_unique(d->symbolQuery)); - modelManager->setSymbolsFindFilter(std::make_unique()); + modelManager->setClassesFilter(std::make_unique( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record}, + CppTools::Constants::CLASSES_FILTER_ID, + CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME, + "c")); + modelManager->setFunctionsFilter(std::make_unique( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Function}, + CppTools::Constants::FUNCTIONS_FILTER_ID, + CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME, + "m")); + modelManager->setLocatorFilter(std::make_unique( + d->symbolQuery, + d->editorManager, + ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record, + ClangBackEnd::SymbolKind::Enumeration, + ClangBackEnd::SymbolKind::Function}, + CppTools::Constants::LOCATOR_FILTER_ID, + CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME, + ":")); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/classesfilter.cpp b/src/plugins/clangrefactoring/classesfilter.cpp deleted file mode 100644 index fb8a229afbb..00000000000 --- a/src/plugins/clangrefactoring/classesfilter.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "classesfilter.h" - -#include - -#include - -namespace ClangRefactoring { - -ClassesFilter::ClassesFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::CLASSES_FILTER_ID); - setDisplayName(CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME); - setShortcutString(QLatin1String("c")); - setIncludedByDefault(false); -} - -QList ClassesFilter::matchesFor( - QFutureInterface &, const QString &entry) -{ - using EntryList = QList; - const SymbolString entryString(entry); - const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString); - return Utils::transform(classes, [this](const Class &classInfo) { - Core::LocatorFilterEntry entry{this, - classInfo.name.toQString(), - qVariantFromValue(classInfo)}; - entry.extraInfo = classInfo.path.path().toQString(); - return entry; - }); -} - -void ClassesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void ClassesFilter::refresh(QFutureInterface &) -{ -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/classesfilter.h b/src/plugins/clangrefactoring/classesfilter.h deleted file mode 100644 index 00f827dff8d..00000000000 --- a/src/plugins/clangrefactoring/classesfilter.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include - -namespace ClangRefactoring { - -class ClassesFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - ClassesFilter(SymbolQueryInterface &symbolQuery); - - QList matchesFor(QFutureInterface &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/include.h b/src/plugins/clangrefactoring/editormanagerinterface.h similarity index 65% rename from src/plugins/clangrefactoring/include.h rename to src/plugins/clangrefactoring/editormanagerinterface.h index 6f6bc9ebe4b..fbb196460e7 100644 --- a/src/plugins/clangrefactoring/include.h +++ b/src/plugins/clangrefactoring/editormanagerinterface.h @@ -25,9 +25,29 @@ #pragma once -#include "symbol.h" +#include + +#include +#include + +namespace Core { +class IEditor; +} namespace ClangRefactoring { -using Include = Symbol; -using Includes = std::vector; + +class EditorManagerInterface +{ +public: + EditorManagerInterface() = default; + EditorManagerInterface(const EditorManagerInterface&) = delete; + EditorManagerInterface &operator=(const EditorManagerInterface&) = delete; + EditorManagerInterface(EditorManagerInterface&&) = delete; + EditorManagerInterface &operator=(EditorManagerInterface&&) = delete; + + virtual Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) = 0; + +protected: + ~EditorManagerInterface() = default; +}; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/enum.h b/src/plugins/clangrefactoring/enum.h deleted file mode 100644 index 44de3c0b8c0..00000000000 --- a/src/plugins/clangrefactoring/enum.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "class.h" - -namespace ClangRefactoring { -using Enum = Class; -using Enums = std::vector; -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/functionsfilter.cpp b/src/plugins/clangrefactoring/functionsfilter.cpp deleted file mode 100644 index 4383b0eff0a..00000000000 --- a/src/plugins/clangrefactoring/functionsfilter.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "functionsfilter.h" - -#include - -#include - -namespace ClangRefactoring { - -FunctionsFilter::FunctionsFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::FUNCTIONS_FILTER_ID); - setDisplayName(CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char('m'))); - setIncludedByDefault(false); -} - -QList FunctionsFilter::matchesFor( - QFutureInterface &, const QString &entry) -{ - using EntryList = QList; - const SymbolString entryString(entry); - const Functions functions = m_symbolQuery.functionsContaining(entryString); - return Utils::transform(functions, [this](const Function &function) { - const auto data = qVariantFromValue(static_cast(function)); - Core::LocatorFilterEntry entry{this, function.name.toQString(), data}; - entry.extraInfo = function.path.path().toQString(); - return entry; - }); -} - -void FunctionsFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void FunctionsFilter::refresh(QFutureInterface &) -{ -} - - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/functionsfilter.h b/src/plugins/clangrefactoring/functionsfilter.h deleted file mode 100644 index 6844350e2c3..00000000000 --- a/src/plugins/clangrefactoring/functionsfilter.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include - -namespace ClangRefactoring { - -class FunctionsFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - FunctionsFilter(SymbolQueryInterface &symbolQuery); - - QList matchesFor(QFutureInterface &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/includesfilter.cpp b/src/plugins/clangrefactoring/includesfilter.cpp deleted file mode 100644 index f7a586b3126..00000000000 --- a/src/plugins/clangrefactoring/includesfilter.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "includesfilter.h" - -#include - -#include - -namespace ClangRefactoring { - -IncludesFilter::IncludesFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::INCLUDES_FILTER_ID); - setDisplayName(CppTools::Constants::INCLUDES_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char('a'))); - setIncludedByDefault(true); - setPriority(ILocatorFilter::Low); -} - -QList IncludesFilter::matchesFor( - QFutureInterface &, const QString &entry) -{ - using EntryList = QList; - const SymbolString entryString(entry); - const Includes includes = m_symbolQuery.symbolsContaining(SymbolType::Include, entryString); - return Utils::transform(includes, [this](const Include &includeInfo) { - Core::LocatorFilterEntry entry{this, - includeInfo.name.toQString(), - qVariantFromValue(includeInfo)}; - entry.extraInfo = includeInfo.path.path().toQString(); - return entry; - }); -} - -void IncludesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const -{ -} - -void IncludesFilter::refresh(QFutureInterface &) -{ -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/includesfilter.h b/src/plugins/clangrefactoring/includesfilter.h deleted file mode 100644 index e28608dc4fa..00000000000 --- a/src/plugins/clangrefactoring/includesfilter.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "symbolqueryinterface.h" - -#include - -namespace ClangRefactoring { - -class IncludesFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - IncludesFilter(SymbolQueryInterface &symbolQuery); - - QList matchesFor(QFutureInterface &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface &future) override; -private: - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.cpp b/src/plugins/clangrefactoring/locatorfilter.cpp index be50fd008ae..15ecbb73d2f 100644 --- a/src/plugins/clangrefactoring/locatorfilter.cpp +++ b/src/plugins/clangrefactoring/locatorfilter.cpp @@ -31,50 +31,32 @@ namespace ClangRefactoring { -LocatorFilter::LocatorFilter(SymbolQueryInterface &symbolQuery) - : m_symbolQuery(symbolQuery) -{ - setId(CppTools::Constants::LOCATOR_FILTER_ID); - setDisplayName(CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME); - setShortcutString(QString(QLatin1Char(':'))); - setIncludedByDefault(false); -} + QList LocatorFilter::matchesFor( - QFutureInterface &, const QString &entry) + QFutureInterface &, const QString &searchTerm) { - SymbolString entryString(entry); - const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString); - const Enums enums = m_symbolQuery.symbolsContaining(SymbolType::Enum, entryString); - const Functions functions = m_symbolQuery.functionsContaining(entryString); - using EntryList = QList; - auto classEntries = Utils::transform(classes, [this](const Class &classInfo) { + Utils::SmallString sqlSearchTerm{searchTerm}; + sqlSearchTerm.replace('*', '%'); + sqlSearchTerm.append("%"); + const Symbols records = m_symbolQuery.symbols(m_symbolKinds, sqlSearchTerm); + return Utils::transform(records, [this](const Symbol &record) { Core::LocatorFilterEntry entry{this, - classInfo.name.toQString(), - qVariantFromValue(classInfo)}; - entry.extraInfo = classInfo.path.path().toQString(); + record.name.toQString(), + QVariant::fromValue(record)}; return entry; }); - auto enumEntries = Utils::transform(enums, [this](const Enum &enumInfo) { - Core::LocatorFilterEntry entry{this, - enumInfo.name.toQString(), - qVariantFromValue(enumInfo)}; - entry.extraInfo = enumInfo.path.path().toQString(); - return entry; - }); - auto functionEntries = Utils::transform(functions, [this](const Function &function) { - const auto data = qVariantFromValue(static_cast(function)); - Core::LocatorFilterEntry entry{this, function.name.toQString(), data}; - entry.extraInfo = function.path.path().toQString(); - return entry; - }); - - return classEntries + enumEntries + functionEntries; } -void LocatorFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const +void LocatorFilter::accept(Core::LocatorFilterEntry locatorFilterEntry, QString *, int *, int *) const { + const Symbol symbol = locatorFilterEntry.internalData.value(); + + const auto sourceLocation = m_symbolQuery.locationForSymbolId(symbol.symbolId, + ClangBackEnd::SourceLocationKind::Definition); + if (sourceLocation) + m_editorManager.openEditorAt(sourceLocation->filePathId, sourceLocation->lineColumn); } void LocatorFilter::refresh(QFutureInterface &) diff --git a/src/plugins/clangrefactoring/locatorfilter.h b/src/plugins/clangrefactoring/locatorfilter.h index d443d2c72a9..15eaf93f0e8 100644 --- a/src/plugins/clangrefactoring/locatorfilter.h +++ b/src/plugins/clangrefactoring/locatorfilter.h @@ -26,6 +26,7 @@ #pragma once #include "symbolqueryinterface.h" +#include "editormanagerinterface.h" #include @@ -35,7 +36,22 @@ class LocatorFilter : public Core::ILocatorFilter { Q_OBJECT public: - LocatorFilter(SymbolQueryInterface &symbolQuery); + LocatorFilter(SymbolQueryInterface &symbolQuery, + EditorManagerInterface &editorManager, + ClangBackEnd::SymbolKinds &&symbolKinds, + Core::Id id, + const QString &displayName, + const QString &shortCut, + bool includedByDefault=false) + : m_symbolQuery(symbolQuery), + m_editorManager(editorManager), + m_symbolKinds(std::move(symbolKinds)) + { + setId(id); + setDisplayName(displayName); + setShortcutString(shortCut); + setIncludedByDefault(includedByDefault); + } QList matchesFor(QFutureInterface &future, const QString &entry) override; @@ -44,6 +60,8 @@ public: void refresh(QFutureInterface &future) override; private: SymbolQueryInterface &m_symbolQuery; + EditorManagerInterface &m_editorManager; + ClangBackEnd::SymbolKinds m_symbolKinds; }; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.h b/src/plugins/clangrefactoring/qtcreatorclassesfilter.h deleted file mode 100644 index 96cac20ff2d..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorclassesfilter.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "classesfilter.h" - -namespace ClangRefactoring { - -class QtcreatorClassesFilter : public ClassesFilter -{ - Q_OBJECT -public: - QtcreatorClassesFilter(SymbolQueryInterface &symbolQuery) : ClassesFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp b/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp similarity index 70% rename from src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp rename to src/plugins/clangrefactoring/qtcreatoreditormanager.cpp index 3e1c9899e49..4aef8baa5da 100644 --- a/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp +++ b/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -23,18 +23,22 @@ ** ****************************************************************************/ -#include "qtcreatorclassesfilter.h" +#include "qtcreatoreditormanager.h" #include +#include + +#include + namespace ClangRefactoring { -void QtcreatorClassesFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const +Core::IEditor *ClangRefactoring::QtCreatorEditorManager::openEditorAt(ClangBackEnd::FilePathId filePathId, + Utils::LineColumn lineColumn) { - auto info = qvariant_cast(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); + const QString filePath = m_filePathCache.filePath(filePathId).toQString(); + + return Core::EditorManager::openEditorAt(filePath, lineColumn.line, lineColumn.column - 1); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/class.h b/src/plugins/clangrefactoring/qtcreatoreditormanager.h similarity index 71% rename from src/plugins/clangrefactoring/class.h rename to src/plugins/clangrefactoring/qtcreatoreditormanager.h index 4775c8c8ffc..5c09cae082e 100644 --- a/src/plugins/clangrefactoring/class.h +++ b/src/plugins/clangrefactoring/qtcreatoreditormanager.h @@ -25,9 +25,25 @@ #pragma once -#include "symbol.h" +#include "editormanagerinterface.h" + +namespace ClangBackEnd { +class FilePathCachingInterface; +}; namespace ClangRefactoring { -using Class = Symbol; -using Classes = std::vector; -} // namespace ClangRefactoring + +class QtCreatorEditorManager final : public EditorManagerInterface +{ +public: + QtCreatorEditorManager(ClangBackEnd::FilePathCachingInterface &filePathCache) + : m_filePathCache(filePathCache) + {} + + Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) override; + +private: + ClangBackEnd::FilePathCachingInterface &m_filePathCache; +}; + +} diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp deleted file mode 100644 index 6a5a7938ce3..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "qtcreatorfunctionsfilter.h" - -#include - -namespace ClangRefactoring { - -void QtcreatorFunctionsFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - auto info = qvariant_cast(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h deleted file mode 100644 index 8c60db81d4a..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "functionsfilter.h" - -namespace ClangRefactoring { - -class QtcreatorFunctionsFilter : public FunctionsFilter -{ - Q_OBJECT -public: - QtcreatorFunctionsFilter(SymbolQueryInterface &symbolQuery) : FunctionsFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp b/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp deleted file mode 100644 index 0acf39d02e6..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "qtcreatorincludesfilter.h" - -#include - -namespace ClangRefactoring { - -void QtcreatorIncludesFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - Core::EditorManager::openEditorAt(selection.displayName, 1, 1); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.h b/src/plugins/clangrefactoring/qtcreatorincludesfilter.h deleted file mode 100644 index 3c28f0eed89..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorincludesfilter.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "includesfilter.h" - -namespace ClangRefactoring { - -class QtcreatorIncludesFilter : public IncludesFilter -{ - Q_OBJECT -public: - QtcreatorIncludesFilter(SymbolQueryInterface &symbolQuery) : IncludesFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp deleted file mode 100644 index b2cae53e8cf..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "qtcreatorlocatorfilter.h" - -#include - -namespace ClangRefactoring { - -void QtcreatorLocatorFilter::accept(Core::LocatorFilterEntry selection, - QString *, int *, int *) const -{ - auto info = qvariant_cast(selection.internalData); - Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, - info.lineColumn.column); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h deleted file mode 100644 index 5543d997f53..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include "locatorfilter.h" - -namespace ClangRefactoring { - -class QtcreatorLocatorFilter : public LocatorFilter -{ - Q_OBJECT -public: - QtcreatorLocatorFilter(SymbolQueryInterface &symbolQuery) : LocatorFilter(symbolQuery) {} - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp index 9e5bd7a7500..eb049d8516a 100644 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp +++ b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp @@ -29,11 +29,7 @@ namespace ClangRefactoring { -QtcreatorSymbolsFindFilter::QtcreatorSymbolsFindFilter() -{ -} - -QWidget *QtcreatorSymbolsFindFilter::createConfigWidget() +QWidget *QtCreatorSymbolsFindFilter::createConfigWidget() { return new SymbolsFindFilterConfigWidget(this); } diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h index db9a856ffd2..cd09463088d 100644 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h +++ b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h @@ -29,11 +29,11 @@ namespace ClangRefactoring { -class QtcreatorSymbolsFindFilter : public SymbolsFindFilter +class QtCreatorSymbolsFindFilter : public SymbolsFindFilter { Q_OBJECT public: - QtcreatorSymbolsFindFilter(); + QtCreatorSymbolsFindFilter() = default; QWidget *createConfigWidget() override; }; diff --git a/src/plugins/clangrefactoring/querysqlitestatementfactory.h b/src/plugins/clangrefactoring/querysqlitestatementfactory.h index 231287e84c1..21a1f022ec3 100644 --- a/src/plugins/clangrefactoring/querysqlitestatementfactory.h +++ b/src/plugins/clangrefactoring/querysqlitestatementfactory.h @@ -49,6 +49,18 @@ public: "FROM locations NATURAL JOIN sources NATURAL JOIN directories " "WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?)", database}; + ReadStatement selectSymbolsForKindAndStartsWith{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName LIKE ?", + database}; + ReadStatement selectSymbolsForKindAndStartsWith2{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND symbolName LIKE ?", + database}; + ReadStatement selectSymbolsForKindAndStartsWith3{ + "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND symbolName LIKE ?", + database}; + ReadStatement selectLocationOfSymbol{ + "SELECT (SELECT directoryId FROM sources WHERE sourceId = l.sourceId), sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?", + database}; }; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/sourcelocations.h b/src/plugins/clangrefactoring/sourcelocations.h index fd0dcf7d7fa..9766a779b5d 100644 --- a/src/plugins/clangrefactoring/sourcelocations.h +++ b/src/plugins/clangrefactoring/sourcelocations.h @@ -29,6 +29,8 @@ #include +#include + #include namespace ClangRefactoring { @@ -36,24 +38,26 @@ namespace ClangRefactoring { class SourceLocation { public: + SourceLocation() = default; + SourceLocation(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) + : filePathId{filePathId}, lineColumn{lineColumn} + {} SourceLocation(ClangBackEnd::FilePathId filePathId, int line, int column) - : filePathId(filePathId), line(line), column(column) + : filePathId{filePathId}, lineColumn{line, column} {} SourceLocation(int directoryId, int sourceId, int line, int column) - : filePathId{directoryId, sourceId}, line(line), column(column) + : filePathId{directoryId, sourceId}, lineColumn{line, column} {} friend bool operator==(SourceLocation first, SourceLocation second) { return first.filePathId == second.filePathId - && first.line == second.line - && first.column == second.column; + && first.lineColumn == second.lineColumn; } public: ClangBackEnd::FilePathId filePathId; - int line; - int column; + Utils::LineColumn lineColumn; }; using SourceLocations = std::vector; diff --git a/src/plugins/clangrefactoring/symbol.h b/src/plugins/clangrefactoring/symbol.h index 4f502248fe8..5c2df292720 100644 --- a/src/plugins/clangrefactoring/symbol.h +++ b/src/plugins/clangrefactoring/symbol.h @@ -31,15 +31,32 @@ namespace ClangRefactoring { -// Use proper name -using SymbolString = Utils::PathString; +using SymbolString = Utils::BasicSmallString<63>; +using SignatureString = Utils::BasicSmallString<126>; +using SymbolId = long long; struct Symbol { + Symbol() = default; + Symbol(SymbolId symbolId, Utils::SmallStringView name) + : name(name), symbolId(symbolId) + {} + Symbol(SymbolId symbolId, Utils::SmallStringView name, Utils::SmallStringView signature) + : signature(signature), name(name), symbolId(symbolId) + {} + SignatureString signature; SymbolString name; - ClangBackEnd::FilePath path; - Utils::LineColumn lineColumn; + SymbolId symbolId; + + friend + bool operator==(const Symbol &first, const Symbol &second) + { + return first.symbolId == second.symbolId + && first.name == second.name + && first.signature == second.signature; + } }; + using Symbols = std::vector; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h index 96e9af891f4..507d032f06f 100644 --- a/src/plugins/clangrefactoring/symbolquery.h +++ b/src/plugins/clangrefactoring/symbolquery.h @@ -75,19 +75,53 @@ public: utf8Column); } - Symbols symbolsContaining(SymbolType /*symbolType*/, - Utils::SmallStringView/*regularExpression*/) const override + Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind, + Utils::SmallStringView searchTerm) const { - // TODO: implement - return Classes(); + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith; + + return statement.template values(100, int(symbolKind), searchTerm); } - Functions functionsContaining(Utils::SmallStringView/*regularExpression*/) const override + Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, + ClangBackEnd::SymbolKind symbolKind2, + Utils::SmallStringView searchTerm) const { - // TODO: implement - return Functions(); + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2; + + return statement.template values(100, int(symbolKind1), int(symbolKind2), searchTerm); } + Symbols symbolsWithThreeSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, + ClangBackEnd::SymbolKind symbolKind2, + ClangBackEnd::SymbolKind symbolKind3, + Utils::SmallStringView searchTerm) const + { + ReadStatement &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3; + + return statement.template values(100, int(symbolKind1), int(symbolKind2), int(symbolKind3), searchTerm); + } + + Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, + Utils::SmallStringView searchTerm) const override + { + switch (symbolKinds.size()) + { + case 1: return symbolsWithOneSymbolKinds(symbolKinds[0], searchTerm); + case 2: return symbolsWithTwoSymbolKinds(symbolKinds[0], symbolKinds[1], searchTerm); + case 3: return symbolsWithThreeSymbolKinds(symbolKinds[0], symbolKinds[1], symbolKinds[2], searchTerm); + } + + return Symbols(); + } + + Utils::optional locationForSymbolId(SymbolId symbolId, + ClangBackEnd::SourceLocationKind kind) const override + { + ReadStatement &statement = m_statementFactory.selectLocationOfSymbol; + + return statement.template value(symbolId, int(kind)); + } private: StatementFactory &m_statementFactory; }; diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h index 362ba5cc05c..568d26568fe 100644 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ b/src/plugins/clangrefactoring/symbolqueryinterface.h @@ -27,23 +27,12 @@ #include "sourcelocations.h" -#include "class.h" -#include "enum.h" -#include "function.h" -#include "include.h" #include "symbol.h" #include namespace ClangRefactoring { -enum class SymbolType -{ - Class = 0, - Enum = 1, - Include = 2 -}; - class SymbolQueryInterface { public: @@ -57,9 +46,10 @@ public: virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; - virtual Symbols symbolsContaining(SymbolType symbolType, - Utils::SmallStringView regularExpression) const = 0; - virtual Functions functionsContaining(Utils::SmallStringView regularExpression) const = 0; + virtual Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, + Utils::SmallStringView searchTerm) const = 0; + virtual Utils::optional locationForSymbolId(SymbolId symbolId, + ClangBackEnd::SourceLocationKind kind) const = 0; protected: ~SymbolQueryInterface() = default; diff --git a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h index b3f86ae539c..36592ca5aa1 100644 --- a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h +++ b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h @@ -112,7 +112,7 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void Ifdef(clang::SourceLocation, @@ -122,7 +122,7 @@ public: addUsedMacro( macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void Defined(const clang::Token ¯oNameToken, @@ -132,13 +132,13 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void MacroDefined(const clang::Token ¯oNameToken, const clang::MacroDirective *macroDirective) override { - addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SymbolType::MacroDefinition); + addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SourceLocationKind::MacroDefinition); } void MacroUndefined(const clang::Token ¯oNameToken, @@ -147,7 +147,7 @@ public: { addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUndefinition); + SourceLocationKind::MacroUndefinition); } void MacroExpands(const clang::Token ¯oNameToken, @@ -158,7 +158,7 @@ public: addUsedMacro(macroNameToken, macroDefinition); addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDefinition.getLocalDirective()), - SymbolType::MacroUsage); + SourceLocationKind::MacroUsage); } void EndOfMainFile() override @@ -228,7 +228,7 @@ public: void addMacroAsSymbol(const clang::Token ¯oNameToken, const clang::MacroInfo *macroInfo, - SymbolType symbolType) + SourceLocationKind symbolType) { clang::SourceLocation sourceLocation = macroNameToken.getLocation(); if (macroInfo && sourceLocation.isFileID()) { diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp index a1aba16555b..008dd749a49 100644 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp @@ -47,16 +47,16 @@ Utils::SmallString symbolName(const clang::NamedDecl *declaration) return declarationName.getAsString(); } -SymbolType symbolType(clang::index::SymbolRoleSet roles) +SourceLocationKind sourceLocationKind(clang::index::SymbolRoleSet roles) { if (hasSymbolRole(clang::index::SymbolRole::Reference, roles)) - return SymbolType::DeclarationReference; + return SourceLocationKind::DeclarationReference; else if (hasSymbolRole(clang::index::SymbolRole::Declaration, roles)) - return SymbolType::Declaration; + return SourceLocationKind::Declaration; else if (hasSymbolRole(clang::index::SymbolRole::Definition, roles)) - return SymbolType::Definition; + return SourceLocationKind::Definition; - return SymbolType::None; + return SourceLocationKind::None; } using SymbolKindAndTags = std::pair; @@ -133,7 +133,7 @@ bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration, m_sourceLocationEntries.emplace_back(globalId, filePathId(sourceLocation), lineColum(sourceLocation), - symbolType(symbolRoles)); + sourceLocationKind(symbolRoles)); } return true; diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h index 21e107be71b..5d4a4bbf77f 100644 --- a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h +++ b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h @@ -36,17 +36,6 @@ using uint = unsigned int; namespace ClangBackEnd { -enum class SymbolType -{ - None = 0, - Declaration, - DeclarationReference, - Definition, - MacroDefinition = 1024, - MacroUsage, - MacroUndefinition -}; - using SymbolIndex = long long; class SourceLocationEntry @@ -55,24 +44,24 @@ public: SourceLocationEntry(SymbolIndex symbolId, FilePathId filePathId, Utils::LineColumn lineColumn, - SymbolType symbolType) + SourceLocationKind kind) : symbolId(symbolId), filePathId(filePathId), lineColumn(lineColumn), - symbolType(symbolType) + kind(kind) {} SymbolIndex symbolId = 0; FilePathId filePathId; Utils::LineColumn lineColumn; - SymbolType symbolType; + SourceLocationKind kind; friend bool operator==(const SourceLocationEntry &first, const SourceLocationEntry &second) { return first.symbolId == second.symbolId && first.filePathId == second.filePathId && first.lineColumn == second.lineColumn - && first.symbolType == second.symbolType; + && first.kind == second.kind; } }; diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index 7cd05ee27bc..7652795acb5 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -73,6 +73,7 @@ public: const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); + table.addColumn("locationKind", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); table.initialize(database); @@ -119,7 +120,7 @@ public: "INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)", database}; WriteStatement insertLocationsToNewLocationsStatement{ - "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", + "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)", database }; ReadStatement selectNewSourceIdsStatement{ @@ -145,7 +146,7 @@ public: database }; WriteStatement insertNewLocationsInLocationsStatement{ - "INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations", + "INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations", database }; WriteStatement deleteNewSymbolsTableStatement{ diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 9c307a8664a..dccc8f06fbe 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -210,11 +210,12 @@ public: { WriteStatement &statement = m_statementFactory.insertLocationsToNewLocationsStatement; - for (const auto &locationsEntry : sourceLocations) { - statement.write(locationsEntry.symbolId, - locationsEntry.lineColumn.line, - locationsEntry.lineColumn.column, - locationsEntry.filePathId.filePathId); + for (const auto &locationEntry : sourceLocations) { + statement.write(locationEntry.symbolId, + locationEntry.lineColumn.line, + locationEntry.lineColumn.column, + locationEntry.filePathId.filePathId, + int(locationEntry.kind)); } } diff --git a/tests/unit/unittest/classesfilter-test.cpp b/tests/unit/unittest/classesfilter-test.cpp deleted file mode 100644 index 82b62cb19fc..00000000000 --- a/tests/unit/unittest/classesfilter-test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mocksymbolquery.h" - -#include - -namespace { - -class ClassesFilter : public ::testing::Test -{ -protected: - MockSymbolQuery mockSymbolQuery; - ClangRefactoring::ClassesFilter classesFilter {mockSymbolQuery}; -}; - -TEST_F(ClassesFilter, MatchesFor) -{ - QFutureInterface dummy; - - auto matches = classesFilter.matchesFor(dummy, QString()); -} - -TEST_F(ClassesFilter, Accept) -{ - int start = 0; - int length = 0; - QString newText; - - classesFilter.accept(Core::LocatorFilterEntry(), &newText, &start, &length); -} - -TEST_F(ClassesFilter, Refresh) -{ - QFutureInterface dummy; - - classesFilter.refresh(dummy); -} - -} diff --git a/tests/unit/unittest/functionsfilter-test.cpp b/tests/unit/unittest/functionsfilter-test.cpp deleted file mode 100644 index 62dfe08c103..00000000000 --- a/tests/unit/unittest/functionsfilter-test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mocksymbolquery.h" - -#include - -namespace { - -class FunctionsFilter : public ::testing::Test -{ -protected: - MockSymbolQuery mockSymbolQuery; - ClangRefactoring::FunctionsFilter functionsFilter {mockSymbolQuery}; -}; - -TEST_F(FunctionsFilter, MatchesFor) -{ - QFutureInterface dummy; - - auto matches = functionsFilter.matchesFor(dummy, QString()); -} - -TEST_F(FunctionsFilter, Accept) -{ - int start = 0; - int length = 0; - QString newText; - - functionsFilter.accept(Core::LocatorFilterEntry(), &newText, &start, &length); -} - -TEST_F(FunctionsFilter, Refresh) -{ - QFutureInterface dummy; - - functionsFilter.refresh(dummy); -} - -} diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 56f36b18902..9475235485d 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,7 @@ #include #include +#include void PrintTo(const Utf8String &text, ::std::ostream *os) { @@ -63,6 +65,20 @@ void PrintTo(const Utf8String &text, ::std::ostream *os) } namespace Core { + +std::ostream &operator<<(std::ostream &out, const LocatorFilterEntry &entry) +{ + out << "(" + << entry.displayName << ", "; + + if (entry.internalData.canConvert()) + out << entry.internalData.value(); + + out << ")"; + + return out; +} + namespace Search { using testing::PrintToString; @@ -165,15 +181,17 @@ std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths) return out; } -#define RETURN_TEXT_FOR_CASE(enumValue) case SymbolType::enumValue: return #enumValue -static const char *symbolTypeToCStringLiteral(SymbolType type) +#define RETURN_TEXT_FOR_CASE(enumValue) case SourceLocationKind::enumValue: return #enumValue +static const char *symbolTypeToCStringLiteral(ClangBackEnd::SourceLocationKind kind) { - switch (type) { - RETURN_TEXT_FOR_CASE(Declaration); - RETURN_TEXT_FOR_CASE(DeclarationReference); - RETURN_TEXT_FOR_CASE(MacroDefinition); - RETURN_TEXT_FOR_CASE(MacroUsage); - RETURN_TEXT_FOR_CASE(MacroUndefinition); + switch (kind) { + RETURN_TEXT_FOR_CASE(None); + RETURN_TEXT_FOR_CASE(Declaration); + RETURN_TEXT_FOR_CASE(DeclarationReference); + RETURN_TEXT_FOR_CASE(Definition); + RETURN_TEXT_FOR_CASE(MacroDefinition); + RETURN_TEXT_FOR_CASE(MacroUsage); + RETURN_TEXT_FOR_CASE(MacroUndefinition); } return ""; @@ -186,7 +204,7 @@ std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry) << entry.symbolId << ", " << entry.filePathId << ", " << entry.lineColumn << ", " - << symbolTypeToCStringLiteral(entry.symbolType) << ")"; + << symbolTypeToCStringLiteral(entry.kind) << ")"; return out; } @@ -1038,9 +1056,14 @@ std::ostream &operator<<(std::ostream &os, const SourceRangeContainer &container namespace ClangRefactoring { std::ostream &operator<<(std::ostream &out, const SourceLocation &location) { - return out << "(" << location.filePathId << ", " << location.line << ", " << location.column << ")"; + return out << "(" << location.filePathId << ", " << location.lineColumn << ")"; } -} // namespace ClangBackEnd + +std::ostream &operator<<(std::ostream &out, const Symbol &symbol) +{ + return out << "(" << symbol.name << ", " << symbol.symbolId << ", " << symbol.signature << ")"; +} +} // namespace ClangRefactoring namespace CppTools { diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index aa46ef32e59..6404764544b 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -40,6 +40,10 @@ class Utf8String; void PrintTo(const Utf8String &text, ::std::ostream *os); namespace Core { +class LocatorFilterEntry; + +std::ostream &operator<<(std::ostream &out, const LocatorFilterEntry &entry); + namespace Search { class TextPosition; @@ -257,8 +261,10 @@ std::ostream &operator<<(std::ostream &out, const SourceRangeContainer &containe namespace ClangRefactoring { class SourceLocation; +class Symbol; std::ostream &operator<<(std::ostream &out, const SourceLocation &location); +std::ostream &operator<<(std::ostream &out, const Symbol &symbol); } // namespace ClangRefactoring diff --git a/tests/unit/unittest/includesfilter-test.cpp b/tests/unit/unittest/includesfilter-test.cpp deleted file mode 100644 index 2ea30757602..00000000000 --- a/tests/unit/unittest/includesfilter-test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mocksymbolquery.h" - -#include - -namespace { - -class IncludesFilter : public ::testing::Test -{ -protected: - MockSymbolQuery mockSymbolQuery; - ClangRefactoring::IncludesFilter includesFilter {mockSymbolQuery}; -}; - -TEST_F(IncludesFilter, MatchesFor) -{ - QFutureInterface dummy; - - auto matches = includesFilter.matchesFor(dummy, QString()); -} - -TEST_F(IncludesFilter, Accept) -{ - int start = 0; - int length = 0; - QString newText; - - includesFilter.accept(Core::LocatorFilterEntry(), &newText, &start, &length); -} - -TEST_F(IncludesFilter, Refresh) -{ - QFutureInterface dummy; - - includesFilter.refresh(dummy); -} - -} diff --git a/tests/unit/unittest/locatorfilter-test.cpp b/tests/unit/unittest/locatorfilter-test.cpp index bae95a09b0e..00bdbbd1aea 100644 --- a/tests/unit/unittest/locatorfilter-test.cpp +++ b/tests/unit/unittest/locatorfilter-test.cpp @@ -25,40 +25,99 @@ #include "googletest.h" +#include "mockeditormanager.h" #include "mocksymbolquery.h" -#include +#include +#include namespace { +using ClangBackEnd::SymbolKind; +using ClangBackEnd::SourceLocationKind; +using ClangRefactoring::Symbol; + +MATCHER_P2(HasNameAndSymbol, name, symbol, + std::string(negation ? "hasn't " : "has ") + + PrintToString(name) + + " and " + + PrintToString(symbol)) +{ + const Core::LocatorFilterEntry &entry = arg; + + return entry.displayName == QString::fromUtf8(name) && entry.internalData.value() == symbol; +} + class LocatorFilter : public ::testing::Test { protected: - MockSymbolQuery mockSymbolQuery; - ClangRefactoring::LocatorFilter locatorFilter {mockSymbolQuery}; -}; + static Core::LocatorFilterEntry createSymbolLocatorFilterEntry() + { + ClangRefactoring::Symbol symbol{42, "symbolName"}; + Core::LocatorFilterEntry entry; + entry.internalData = QVariant::fromValue(symbol); -TEST_F(LocatorFilter, MatchesFor) -{ - QFutureInterface dummy; + return entry; + } - auto matches = locatorFilter.matchesFor(dummy, QString()); -} - -TEST_F(LocatorFilter, Accept) -{ +protected: + MockEditorManager mockEditorManager; + NiceMock mockSymbolQuery; + ClangRefactoring::LocatorFilter filter{mockSymbolQuery, mockEditorManager, {SymbolKind::Record}, "", "", ""}; + Core::LocatorFilterEntry entry{createSymbolLocatorFilterEntry()}; int start = 0; int length = 0; QString newText; + Utils::LineColumn lineColumn{4, 3}; + ClangBackEnd::FilePathId filePathId{42, 64}; + ClangRefactoring::SourceLocation sourceLocation{filePathId, lineColumn}; +}; - locatorFilter.accept(Core::LocatorFilterEntry(), &newText, &start, &length); -} - -TEST_F(LocatorFilter, Refresh) +TEST_F(LocatorFilter, MatchesForCallSymbols) { - QFutureInterface dummy; + QFutureInterface dummy; - locatorFilter.refresh(dummy); + EXPECT_CALL(mockSymbolQuery, symbols(ElementsAre(ClangBackEnd::SymbolKind::Record), Eq("search%Term%"))); + + filter.matchesFor(dummy, "search*Term"); +} + +TEST_F(LocatorFilter, MatchesForReturnsLocatorFilterEntries) +{ + ClangRefactoring::Symbols symbols{{12, "Foo", "class Foo final : public Bar"}, + {22, "Poo", "class Poo final : public Bar"}}; + ON_CALL(mockSymbolQuery, symbols(ElementsAre(ClangBackEnd::SymbolKind::Record), Eq("search%Term%"))) + .WillByDefault(Return(symbols)); + QFutureInterface dummy; + + auto entries = filter.matchesFor(dummy, "search*Term"); + + ASSERT_THAT(entries, + ElementsAre( + HasNameAndSymbol("Foo", symbols[0]), + HasNameAndSymbol("Poo", symbols[1]))); +} + +TEST_F(LocatorFilter, AcceptDontCallsLocationAndOpensEditorIfItGetInvalidResultFromDatabase) +{ + InSequence s; + + EXPECT_CALL(mockSymbolQuery, locationForSymbolId(42, SourceLocationKind::Definition)) + .WillOnce(Return(Utils::optional{})); + EXPECT_CALL(mockEditorManager, openEditorAt(Eq(filePathId), Eq(lineColumn))).Times(0); + + filter.accept(entry, &newText, &start, &length); +} + +TEST_F(LocatorFilter, AcceptCallsLocationAndOpensEditor) +{ + InSequence s; + + EXPECT_CALL(mockSymbolQuery, locationForSymbolId(42, SourceLocationKind::Definition)) + .WillOnce(Return(sourceLocation)); + EXPECT_CALL(mockEditorManager, openEditorAt(Eq(filePathId), Eq(lineColumn))); + + filter.accept(entry, &newText, &start, &length); } } diff --git a/src/plugins/clangrefactoring/function.h b/tests/unit/unittest/mockeditormanager.h similarity index 79% rename from src/plugins/clangrefactoring/function.h rename to tests/unit/unittest/mockeditormanager.h index 863ac1b3529..25ead76e9b3 100644 --- a/src/plugins/clangrefactoring/function.h +++ b/tests/unit/unittest/mockeditormanager.h @@ -25,14 +25,19 @@ #pragma once -#include "symbol.h" +#include "googletest.h" -namespace ClangRefactoring { -struct Function : public Symbol +#include + +namespace Core { +class IEditor {}; +} + +class MockEditorManager final : public ClangRefactoring::EditorManagerInterface { - SymbolString parentName; - SymbolString returnValue; - SymbolString paramsList; +public: + MOCK_METHOD2(openEditorAt, + Core::IEditor*(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn)); + }; -using Functions = std::vector; -} // namespace ClangRefactoring + diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp index bb604b34e12..eb114e3a47a 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.cpp +++ b/tests/unit/unittest/mocksqlitereadstatement.cpp @@ -46,6 +46,41 @@ MockSqliteReadStatement::values( return valuesReturnSourceUsages(reserveSize, sourceId, line, column); } +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int &symbolKind, + const Utils::SmallStringView &searchTerm) +{ + return valuesReturnSymbols(reserveSize, symbolKind, searchTerm); +} + +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int &symbolKind1, + const int &symbolKind2, + const Utils::SmallStringView &searchTerm) +{ + return valuesReturnSymbols(reserveSize, symbolKind1, symbolKind2, searchTerm); + +} + +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int &symbolKind1, + const int &symbolKind2, + const int &symbolKind3, + const Utils::SmallStringView &searchTerm) +{ + return valuesReturnSymbols(reserveSize, symbolKind1, symbolKind2, symbolKind3, searchTerm); + +} + template <> std::vector MockSqliteReadStatement::values(std::size_t reserveSize) { @@ -120,3 +155,10 @@ MockSqliteReadStatement::value(const int &sourceId) { return valueReturnSmallString(sourceId); } + +template <> +Utils::optional +MockSqliteReadStatement::value(const long long &symbolId, const int &locationKind) +{ + return valueReturnSourceLocation(symbolId, locationKind); +} diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h index 5ab53705cf0..2ad17ee07f2 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.h +++ b/tests/unit/unittest/mocksqlitereadstatement.h @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -47,6 +48,8 @@ using std::int64_t; using ClangRefactoring::SourceLocation; using ClangRefactoring::SourceLocations; namespace Sources = ClangBackEnd::Sources; +using ClangRefactoring::Symbol; +using ClangRefactoring::Symbols; class MockSqliteDatabase; @@ -94,6 +97,18 @@ public: MOCK_METHOD1(valueReturnProjectPartPch, Utils::optional(int)); + MOCK_METHOD3(valuesReturnSymbols, + Symbols(std::size_t, int, Utils::SmallStringView)); + + MOCK_METHOD4(valuesReturnSymbols, + Symbols(std::size_t, int, int, Utils::SmallStringView)); + + MOCK_METHOD5(valuesReturnSymbols, + Symbols(std::size_t, int, int, int, Utils::SmallStringView)); + + MOCK_METHOD2(valueReturnSourceLocation, + SourceLocation(long long, int)); + template @@ -136,6 +151,30 @@ MockSqliteReadStatement::values( const int &line, const int &column); +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int&, + const Utils::SmallStringView&); + +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int&, + const int&, + const Utils::SmallStringView&); + +template <> +Symbols +MockSqliteReadStatement::values( + std::size_t reserveSize, + const int&, + const int&, + const int&, + const Utils::SmallStringView&); + template <> std::vector MockSqliteReadStatement::values(std::size_t reserveSize); @@ -177,3 +216,7 @@ MockSqliteReadStatement::value(const int&); template <> Utils::optional MockSqliteReadStatement::value(const int&); + +template <> +Utils::optional +MockSqliteReadStatement::value(const long long &symbolId, const int &locationKind); diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h index af6f5a58189..05d2404d914 100644 --- a/tests/unit/unittest/mocksqlitewritestatement.h +++ b/tests/unit/unittest/mocksqlitewritestatement.h @@ -57,6 +57,9 @@ public: MOCK_METHOD4(write, void (long long, int, int, int)); + MOCK_METHOD5(write, + void (long long, int, int, int, int)); + MOCK_METHOD2(write, void (uint, Utils::SmallStringView)); diff --git a/tests/unit/unittest/mocksymbolquery.h b/tests/unit/unittest/mocksymbolquery.h index 63927c3f241..0b3f4d59843 100644 --- a/tests/unit/unittest/mocksymbolquery.h +++ b/tests/unit/unittest/mocksymbolquery.h @@ -32,8 +32,12 @@ class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface { public: - MOCK_CONST_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); - MOCK_CONST_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); - MOCK_CONST_METHOD2(symbolsContaining, ClangRefactoring::Symbols(ClangRefactoring::SymbolType symbolType, Utils::SmallStringView regEx)); - MOCK_CONST_METHOD1(functionsContaining, ClangRefactoring::Functions(Utils::SmallStringView regEx)); + MOCK_CONST_METHOD3(locationsAt, + ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); + MOCK_CONST_METHOD3(sourceUsagesAt, + CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); + MOCK_CONST_METHOD2(symbols, + ClangRefactoring::Symbols(const ClangBackEnd::SymbolKinds &symbolKinds, Utils::SmallStringView searchTerm)); + MOCK_CONST_METHOD2(locationForSymbolId, + Utils::optional(ClangRefactoring::SymbolId symbolId, ClangBackEnd::SourceLocationKind kind)); }; diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index f225a0890e9..6b9257facf0 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -46,9 +46,9 @@ TEST_F(RefactoringDatabaseInitializer, AddSymbolsTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind ON symbols(symbolKind)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))); initializer.createSymbolsTable(); } @@ -57,8 +57,9 @@ TEST_F(RefactoringDatabaseInitializer, AddLocationsTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))); initializer.createLocationsTable(); } @@ -148,11 +149,12 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) InSequence s; EXPECT_CALL(mockDatabase, immediateBegin()); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind ON symbols(symbolKind)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); diff --git a/tests/unit/unittest/sizedarray-test.cpp b/tests/unit/unittest/sizedarray-test.cpp index b3637a23a19..03cec127b35 100644 --- a/tests/unit/unittest/sizedarray-test.cpp +++ b/tests/unit/unittest/sizedarray-test.cpp @@ -145,4 +145,13 @@ TEST(SizedArray, ConstREndIteratorIsOneAfterRBeginForOneSizedArray) ASSERT_THAT(std::next(array.crbegin(), 1), array.crend()); } +TEST(SizedArray, InitializerListSize) +{ + SizedArray array{'a', 'b'}; + + auto size = array.size(); + + ASSERT_THAT(size, 2); +} + } // anonymous namespace diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp index 6bf4acdafe9..4990438c509 100644 --- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp @@ -59,7 +59,7 @@ TEST_F(StorageSqliteStatementFactory, AddNewLocationsTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); factory.createNewLocationsTable(); @@ -93,7 +93,7 @@ TEST_F(StorageSqliteStatementFactory, AddTablesInConstructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON newUsedMacros(sourceId, macroName)"))); @@ -113,7 +113,7 @@ TEST_F(StorageSqliteStatementFactory, InsertNewSymbolsStatement) TEST_F(StorageSqliteStatementFactory, InsertNewLocationsToLocations) { ASSERT_THAT(factory.insertLocationsToNewLocationsStatement.sqlStatement, - Eq("INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)")); + Eq("INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)")); } TEST_F(StorageSqliteStatementFactory, SelectNewSourceIdsStatement) @@ -149,7 +149,7 @@ TEST_F(StorageSqliteStatementFactory, DeleteAllLocationsFromUpdatedFiles) TEST_F(StorageSqliteStatementFactory, InsertNewLocationsInLocations) { ASSERT_THAT(factory.insertNewLocationsInLocationsStatement.sqlStatement, - Eq("INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations")); + Eq("INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations")); } TEST_F(StorageSqliteStatementFactory, DeleteNewSymbolsTableStatement) diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 62859a9b4e2..08293a05877 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -58,7 +58,7 @@ using ClangBackEnd::SourceDependencies; using ClangBackEnd::SourceLocationEntries; using ClangBackEnd::SourceLocationEntry; using ClangBackEnd::SymbolKind; -using ClangBackEnd::SymbolType; +using ClangBackEnd::SourceLocationKind; using ClangBackEnd::UsedMacros; using OptionalProjectPartArtefact = Utils::optional; @@ -144,7 +144,7 @@ protected: "void f();", {}}}; SymbolEntries symbolEntries{{1, {"function", "function", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SymbolType::Declaration}}; + SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SourceLocationKind::Declaration}}; FilePathIds sourceFileIds{{1, 1}, {42, 23}}; UsedMacros usedMacros{{"Foo", {1, 1}}}; FileStatuses fileStatus{{{1, 2}, 3, 4, false}}; diff --git a/tests/unit/unittest/symbolindexing-test.cpp b/tests/unit/unittest/symbolindexing-test.cpp index e72e43149ad..1d6c8d720be 100644 --- a/tests/unit/unittest/symbolindexing-test.cpp +++ b/tests/unit/unittest/symbolindexing-test.cpp @@ -65,8 +65,8 @@ MATCHER_P3(IsLocation, filePathId, line, column, const ClangRefactoring::SourceLocation &location = arg; return location.filePathId == filePathId - && location.line == line - && location.column == column; + && location.lineColumn.line == line + && location.lineColumn.column == column; }; class SymbolIndexing : public testing::Test diff --git a/tests/unit/unittest/symbolquery-test.cpp b/tests/unit/unittest/symbolquery-test.cpp index 13463f256ee..53eb9d1c686 100644 --- a/tests/unit/unittest/symbolquery-test.cpp +++ b/tests/unit/unittest/symbolquery-test.cpp @@ -40,7 +40,8 @@ namespace { using ClangRefactoring::QuerySqliteStatementFactory; using Sqlite::Database; - +using ClangBackEnd::SourceLocationKind; +using ClangBackEnd::SymbolKind; using MockStatementFactory = QuerySqliteStatementFactory; using MockQuery = ClangRefactoring::SymbolQuery; @@ -52,44 +53,55 @@ using RealQuery = ClangRefactoring::SymbolQuery; class SymbolQuery : public testing::Test { protected: - void SetUp() override - { - database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\", 1)"); - database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)"); - database.execute("INSERT INTO directories VALUES (1, \"/path/to\")"); - database.execute("INSERT INTO locations VALUES (1, 2, 3, 1)"); - database.execute("INSERT INTO locations VALUES (1, 4, 6, 2)"); - database.execute("INSERT INTO symbols VALUES (1, \"functionusr\", \"function\", 2)"); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - RealStatementFactory realStatementFactory{database}; - RealQuery realQuery{realStatementFactory}; NiceMock mockDatabase; MockStatementFactory mockStatementFactory{mockDatabase}; MockSqliteReadStatement &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation; MockSqliteReadStatement &selectSourceUsagesForSymbolLocation = mockStatementFactory.selectSourceUsagesForSymbolLocation; + MockSqliteReadStatement &selectSymbolsForKindAndStartsWith = mockStatementFactory.selectSymbolsForKindAndStartsWith; + MockSqliteReadStatement &selectSymbolsForKindAndStartsWith2 = mockStatementFactory.selectSymbolsForKindAndStartsWith2; + MockSqliteReadStatement &selectSymbolsForKindAndStartsWith3 = mockStatementFactory.selectSymbolsForKindAndStartsWith3; + MockSqliteReadStatement &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol; SourceLocations locations{{{1, 1}, 1, 1}, {{1, 1}, 2, 3}, {{1, 2}, 1, 1}, {{1, 2}, 3, 1}, {{1, 4}, 1, 1}, {{1, 4}, 1, 3}}; - MockQuery mockQuery{mockStatementFactory}; + MockQuery query{mockStatementFactory}; +}; + +class SymbolQuerySlowTest : public testing::Test +{ +protected: + void SetUp() override + { + database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\", 1)"); + database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)"); + database.execute("INSERT INTO directories VALUES (1, \"/path/to\")"); + database.execute("INSERT INTO locations VALUES (1, 2, 3, 1, 1)"); + database.execute("INSERT INTO locations VALUES (1, 4, 6, 2, 3)"); + database.execute("INSERT INTO symbols VALUES (1, \"functionusr\", \"Function\", 3, \"void function(int)\")"); + database.execute("INSERT INTO symbols VALUES (2, \"classusr\", \"Class\", 2, \"class Class final\")"); + database.execute("INSERT INTO symbols VALUES (3, \"enumusr\", \"Enum\", 1, \"enum Enum : char\")"); + } + +protected: + Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; + ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; + RealStatementFactory realStatementFactory{database}; + RealQuery query{realStatementFactory}; }; TEST_F(SymbolQuery, LocationsAtCallsValues) { EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7)); - mockQuery.locationsAt({1, 42}, 14, 7); + query.locationsAt({1, 42}, 14, 7); } -TEST_F(SymbolQuery, LocationsAt) +TEST_F(SymbolQuerySlowTest, LocationsAt) { - auto locations = realQuery.locationsAt({1, 2}, 4, 6); + auto locations = query.locationsAt({1, 2}, 4, 6); ASSERT_THAT(locations, UnorderedElementsAre(SourceLocation({1, 1}, 2, 3), @@ -100,16 +112,85 @@ TEST_F(SymbolQuery, SourceUsagesAtCallsValues) { EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7)); - mockQuery.sourceUsagesAt({1, 42}, 14, 7); + query.sourceUsagesAt({1, 42}, 14, 7); } -TEST_F(SymbolQuery, SourceUsagesAt) +TEST_F(SymbolQuerySlowTest, SourceUsagesAt) { - auto usages = realQuery.sourceUsagesAt({1, 2}, 4, 6); + auto usages = query.sourceUsagesAt({1, 2}, 4, 6); ASSERT_THAT(usages, UnorderedElementsAre(CppTools::Usage("/path/to/filename.h", 2, 3), CppTools::Usage("/path/to/filename.cpp", 4, 6))); } +TEST_F(SymbolQuery, SymbolsCallsValuesWithOneKindParameter) +{ + EXPECT_CALL(selectSymbolsForKindAndStartsWith, valuesReturnSymbols(100, int(SymbolKind::Record), Eq("foo"))); + + query.symbols({SymbolKind::Record}, "foo"); +} + +TEST_F(SymbolQuerySlowTest, SymbolsWithOneKindParameters) +{ + auto symbols = query.symbols({SymbolKind::Record}, "Cla%"); + + ASSERT_THAT(symbols, + UnorderedElementsAre(Symbol{2, "Class", "class Class final"})); +} + +TEST_F(SymbolQuerySlowTest, SymbolsWithEmptyKinds) +{ + auto symbols = query.symbols({}, "%"); + + ASSERT_THAT(symbols, IsEmpty()); +} + +TEST_F(SymbolQuery, SymbolsCallsValuesWithTwoKindParameters) +{ + EXPECT_CALL(selectSymbolsForKindAndStartsWith2, valuesReturnSymbols(100, int(SymbolKind::Record), int(SymbolKind::Function), Eq("foo"))); + + query.symbols({SymbolKind::Record, SymbolKind::Function}, "foo"); +} + +TEST_F(SymbolQuerySlowTest, SymbolsWithTwoKindParameters) +{ + auto symbols = query.symbols({SymbolKind::Record, SymbolKind::Function}, "%c%"); + + ASSERT_THAT(symbols, + UnorderedElementsAre(Symbol{2, "Class", "class Class final"}, + Symbol{1, "Function", "void function(int)"})); +} + +TEST_F(SymbolQuery, SymbolsCallsValuesWithThreeKindParameters) +{ + EXPECT_CALL(selectSymbolsForKindAndStartsWith3, valuesReturnSymbols(100, int(SymbolKind::Record), int(SymbolKind::Function), int(SymbolKind::Enumeration), Eq("foo"))); + + query.symbols({SymbolKind::Record, SymbolKind::Function, SymbolKind::Enumeration}, "foo"); +} + +TEST_F(SymbolQuerySlowTest, SymbolsWithThreeKindParameters) +{ + auto symbols = query.symbols({SymbolKind::Record, SymbolKind::Function, SymbolKind::Enumeration}, "%"); + + ASSERT_THAT(symbols, + UnorderedElementsAre(Symbol{2, "Class", "class Class final"}, + Symbol{1, "Function", "void function(int)"}, + Symbol{3, "Enum", "enum Enum : char"})); +} + +TEST_F(SymbolQuery, LocationForSymbolIdCallsValueReturningSourceLocation) +{ + EXPECT_CALL(selectLocationOfSymbol, valueReturnSourceLocation(1, int(SourceLocationKind::Definition))); + + query.locationForSymbolId(1, SourceLocationKind::Definition); +} + +TEST_F(SymbolQuerySlowTest, LocationForSymbolId) +{ + auto location = query.locationForSymbolId(1, SourceLocationKind::Definition); + + ASSERT_THAT(location.value(), Eq(SourceLocation({1, 2}, {4, 6}))); +} + } diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp index 4bbfcbee1cc..1dcc4d95c77 100644 --- a/tests/unit/unittest/symbolscollector-test.cpp +++ b/tests/unit/unittest/symbolscollector-test.cpp @@ -55,7 +55,7 @@ using ClangBackEnd::SourceLocationEntry; using ClangBackEnd::SymbolEntry; using ClangBackEnd::SymbolKind; using ClangBackEnd::SymbolTag; -using ClangBackEnd::SymbolType; +using ClangBackEnd::SourceLocationKind; using ClangBackEnd::SymbolIndex; using ClangBackEnd::UsedMacro; @@ -63,9 +63,9 @@ using Sqlite::Database; namespace { -MATCHER_P5(IsSourceLocationEntry, symbolId, filePathId, line, column, symbolType, +MATCHER_P5(IsSourceLocationEntry, symbolId, filePathId, line, column, kind, std::string(negation ? "isn't" : "is") - + PrintToString(SourceLocationEntry{symbolId, filePathId, {line, column}, symbolType}) + + PrintToString(SourceLocationEntry{symbolId, filePathId, {line, column}, kind}) ) { const SourceLocationEntry &entry = arg; @@ -73,7 +73,7 @@ MATCHER_P5(IsSourceLocationEntry, symbolId, filePathId, line, column, symbolType return entry.filePathId == filePathId && entry.lineColumn.line == line && entry.lineColumn.column == column - && entry.symbolType == symbolType + && entry.kind == kind && entry.symbolId == symbolId; } @@ -205,7 +205,7 @@ TEST_F(SymbolsCollector, CollectFilePath) Contains( AllOf(Field(&SourceLocationEntry::filePathId, filePathId(TESTDATA_DIR"/symbolscollector_simple.cpp")), - Field(&SourceLocationEntry::symbolType, SymbolType::Declaration)))); + Field(&SourceLocationEntry::kind, SourceLocationKind::Declaration)))); } TEST_F(SymbolsCollector, CollectLineColumn) @@ -217,7 +217,7 @@ TEST_F(SymbolsCollector, CollectLineColumn) ASSERT_THAT(collector.sourceLocations(), Contains( AllOf(HasLineColumn(1, 6), - Field(&SourceLocationEntry::symbolType, SymbolType::Declaration)))); + Field(&SourceLocationEntry::kind, SourceLocationKind::Declaration)))); } TEST_F(SymbolsCollector, CollectReference) @@ -229,7 +229,7 @@ TEST_F(SymbolsCollector, CollectReference) ASSERT_THAT(collector.sourceLocations(), Contains( AllOf(HasLineColumn(14, 5), - Field(&SourceLocationEntry::symbolType, SymbolType::DeclarationReference)))); + Field(&SourceLocationEntry::kind, SourceLocationKind::DeclarationReference)))); } TEST_F(SymbolsCollector, ReferencedSymboldMatchesLocation) @@ -452,7 +452,7 @@ TEST_F(SymbolsCollector, CollectMacroDefinitionSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 4, 9, SymbolType::MacroDefinition))); + Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 4, 9, SourceLocationKind::MacroDefinition))); } TEST_F(SymbolsCollector, CollectMacroUsageInIfNotDefSourceLocation) @@ -463,7 +463,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageInIfNotDefSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 6, 9, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 6, 9, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectSecondMacroUsageInIfNotDefSourceLocation) @@ -474,7 +474,7 @@ TEST_F(SymbolsCollector, CollectSecondMacroUsageInIfNotDefSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 9, 9, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 9, 9, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroUsageCompilerArgumentSourceLocation) @@ -485,7 +485,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageCompilerArgumentSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("COMPILER_ARGUMENT"), fileId, 12, 9, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("COMPILER_ARGUMENT"), fileId, 12, 9, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroUsageInIfDefSourceLocation) @@ -496,7 +496,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageInIfDefSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_DEFINE"), fileId, 17, 8, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("IF_DEFINE"), fileId, 17, 8, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroUsageInDefinedSourceLocation) @@ -507,7 +507,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageInDefinedSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("DEFINED"), fileId, 22, 13, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("DEFINED"), fileId, 22, 13, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroUsageExpansionSourceLocation) @@ -518,7 +518,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageExpansionSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("MACRO_EXPANSION"), fileId, 27, 10, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("MACRO_EXPANSION"), fileId, 27, 10, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroUsageUndefSourceLocation) @@ -529,7 +529,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageUndefSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("UN_DEFINE"), fileId, 34, 8, SymbolType::MacroUndefinition))); + Contains(IsSourceLocationEntry(symbolId("UN_DEFINE"), fileId, 34, 8, SourceLocationKind::MacroUndefinition))); } TEST_F(SymbolsCollector, CollectMacroUsageBuiltInSourceLocation) @@ -540,7 +540,7 @@ TEST_F(SymbolsCollector, CollectMacroUsageBuiltInSourceLocation) collector.collectSymbols(); ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("__clang__"), fileId, 29, 9, SymbolType::MacroUsage))); + Contains(IsSourceLocationEntry(symbolId("__clang__"), fileId, 29, 9, SourceLocationKind::MacroUsage))); } TEST_F(SymbolsCollector, CollectMacroDefinitionSymbols) diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp index 779887f779f..95fa71c2797 100644 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ b/tests/unit/unittest/symbolstorage-test.cpp @@ -47,7 +47,7 @@ using ClangBackEnd::SourceLocationEntries; using ClangBackEnd::SourceLocationEntry; using ClangBackEnd::StorageSqliteStatementFactory; using ClangBackEnd::SymbolIndex; -using ClangBackEnd::SymbolType; +using ClangBackEnd::SourceLocationKind; using ClangBackEnd::SymbolKind; using Sqlite::Database; using Sqlite::Table; @@ -92,8 +92,8 @@ protected: SymbolEntries symbolEntries{{1, {"functionUSR", "function", SymbolKind::Function}}, {2, {"function2USR", "function2", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SymbolType::Declaration}, - {2, {1, 4}, {7, 11}, SymbolType::Declaration}}; + SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SourceLocationKind::Declaration}, + {2, {1, 4}, {7, 11}, SourceLocationKind::Definition}}; ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\"}", "[\"/includes\"]", 74}; Storage storage{statementFactory, filePathCache}; }; @@ -102,8 +102,8 @@ TEST_F(SymbolStorage, CreateAndFillTemporaryLocationsTable) { InSequence sequence; - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3))); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3), TypedEq(int(SourceLocationKind::Declaration)))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4), TypedEq(int(SourceLocationKind::Definition)))); storage.fillTemporaryLocationsTable(sourceLocations); } @@ -162,8 +162,8 @@ TEST_F(SymbolStorage, AddSymbolsAndSourceLocationsCallsWrite) InSequence sequence; EXPECT_CALL(insertSymbolsToNewSymbolsStatement, write(An(), An(), An(), An())).Times(2); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3))); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3), TypedEq(int(SourceLocationKind::Declaration)))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4), TypedEq(int(SourceLocationKind::Definition)))); EXPECT_CALL(addNewSymbolsToSymbolsStatement, execute()); EXPECT_CALL(syncNewSymbolsFromSymbolsStatement, execute()); EXPECT_CALL(syncSymbolsIntoNewLocationsStatement, execute()); diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 25b29ddea45..5e61b48f6ef 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -42,7 +42,6 @@ SOURCES += \ clangpathwatcher-test.cpp \ clangqueryexamplehighlightmarker-test.cpp \ clangqueryhighlightmarker-test.cpp \ - classesfilter-test.cpp \ clientserverinprocess-test.cpp \ clientserveroutsideprocess-test.cpp \ cppprojectfilecategorizer-test.cpp \ @@ -51,10 +50,8 @@ SOURCES += \ fakeprocess.cpp \ filepath-test.cpp \ filepathview-test.cpp \ - functionsfilter-test.cpp \ gtest-creator-printing.cpp \ gtest-qt-printing.cpp \ - includesfilter-test.cpp \ lineprefixer-test.cpp \ locatorfilter-test.cpp \ matchingtext-test.cpp \ @@ -227,12 +224,13 @@ HEADERS += \ mocksqlitestatement.h \ unittest-utility-functions.h \ mocksymbolquery.h \ - runprojectcreateorupdate-utility.h \ + runprojectcreateorupdate-qutility.h \ rundocumentparse-utility.h \ mocktimer.h \ mocksqlitetransactionbackend.h \ mockprojectpartprovider.h \ - mockprecompiledheaderstorage.h + mockprecompiledheaderstorage.h \ + mockeditormanager.h !isEmpty(LIBCLANG_LIBS) { HEADERS += \ chunksreportedmonitor.h \