From c3e0c387f55f0ba910da36964dcd9eb7bac855cc Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 2 Jan 2023 13:43:28 +0100 Subject: [PATCH] SymbolSearcher: Flatten class hierarchy Don't make SymbolSearcher a pure virtual class as there is only one subclass. Change-Id: I85a9d0fd3574e29620c1e6bfdb3b3421e19a4f76 Reviewed-by: Christian Kandeler Reviewed-by: Qt CI Bot Reviewed-by: --- src/plugins/cppeditor/cppindexingsupport.cpp | 137 ++++++++----------- src/plugins/cppeditor/cppindexingsupport.h | 12 +- 2 files changed, 65 insertions(+), 84 deletions(-) diff --git a/src/plugins/cppeditor/cppindexingsupport.cpp b/src/plugins/cppeditor/cppindexingsupport.cpp index 6ec66c41f55..048adbb0334 100644 --- a/src/plugins/cppeditor/cppindexingsupport.cpp +++ b/src/plugins/cppeditor/cppindexingsupport.cpp @@ -27,12 +27,12 @@ namespace CppEditor { static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg) -SymbolSearcher::SymbolSearcher(QObject *parent) - : QObject(parent) -{ -} - -SymbolSearcher::~SymbolSearcher() = default; +SymbolSearcher::SymbolSearcher(const SymbolSearcher::Parameters ¶meters, + const QSet &fileNames) + : m_snapshot(CppModelManager::instance()->snapshot()) + , m_parameters(parameters) + , m_fileNames(fileNames) +{} namespace { @@ -241,83 +241,64 @@ void parse(QFutureInterface &indexingFuture, const ParseParams params) } // anonymous namespace - -class BuiltinSymbolSearcher: public SymbolSearcher +void SymbolSearcher::runSearch(QFutureInterface &future) { -public: - BuiltinSymbolSearcher(const CPlusPlus::Snapshot &snapshot, - const Parameters ¶meters, const QSet &fileNames) - : m_snapshot(snapshot) - , m_parameters(parameters) - , m_fileNames(fileNames) - {} + future.setProgressRange(0, m_snapshot.size()); + future.setProgressValue(0); + int progress = 0; - ~BuiltinSymbolSearcher() override = default; + SearchSymbols search; + search.setSymbolsToSearchFor(m_parameters.types); + CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin(); - void runSearch(QFutureInterface &future) override - { - future.setProgressRange(0, m_snapshot.size()); - future.setProgressValue(0); - int progress = 0; - - SearchSymbols search; - search.setSymbolsToSearchFor(m_parameters.types); - CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin(); - - QString findString = (m_parameters.flags & Core::FindRegularExpression - ? m_parameters.text : QRegularExpression::escape(m_parameters.text)); - if (m_parameters.flags & Core::FindWholeWords) - findString = QString::fromLatin1("\\b%1\\b").arg(findString); - QRegularExpression matcher(findString, (m_parameters.flags & Core::FindCaseSensitively - ? QRegularExpression::NoPatternOption - : QRegularExpression::CaseInsensitiveOption)); - matcher.optimize(); - while (it != m_snapshot.end()) { - if (future.isPaused()) - future.waitForResume(); - if (future.isCanceled()) - break; - if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) { - QVector resultItems; - auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult { - if (matcher.match(info->symbolName()).hasMatch()) { - QString text = info->symbolName(); - QString scope = info->symbolScope(); - if (info->type() == IndexItem::Function) { - QString name; - info->unqualifiedNameAndScope(info->symbolName(), &name, &scope); - text = name + info->symbolType(); - } else if (info->type() == IndexItem::Declaration){ - text = info->representDeclaration(); - } - - Core::SearchResultItem item; - item.setPath(scope.split(QLatin1String("::"), Qt::SkipEmptyParts)); - item.setLineText(text); - item.setIcon(info->icon()); - item.setUserData(QVariant::fromValue(info)); - resultItems << item; - } - - return IndexItem::Recurse; - }; - search(it.value())->visitAllChildren(filter); - if (!resultItems.isEmpty()) - future.reportResults(resultItems); - } - ++it; - ++progress; - future.setProgressValue(progress); - } + QString findString = (m_parameters.flags & Core::FindRegularExpression + ? m_parameters.text : QRegularExpression::escape(m_parameters.text)); + if (m_parameters.flags & Core::FindWholeWords) + findString = QString::fromLatin1("\\b%1\\b").arg(findString); + QRegularExpression matcher(findString, (m_parameters.flags & Core::FindCaseSensitively + ? QRegularExpression::NoPatternOption + : QRegularExpression::CaseInsensitiveOption)); + matcher.optimize(); + while (it != m_snapshot.end()) { if (future.isPaused()) future.waitForResume(); - } + if (future.isCanceled()) + break; + if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) { + QVector resultItems; + auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult { + if (matcher.match(info->symbolName()).hasMatch()) { + QString text = info->symbolName(); + QString scope = info->symbolScope(); + if (info->type() == IndexItem::Function) { + QString name; + info->unqualifiedNameAndScope(info->symbolName(), &name, &scope); + text = name + info->symbolType(); + } else if (info->type() == IndexItem::Declaration){ + text = info->representDeclaration(); + } -private: - const CPlusPlus::Snapshot m_snapshot; - const Parameters m_parameters; - const QSet m_fileNames; -}; + Core::SearchResultItem item; + item.setPath(scope.split(QLatin1String("::"), Qt::SkipEmptyParts)); + item.setLineText(text); + item.setIcon(info->icon()); + item.setUserData(QVariant::fromValue(info)); + resultItems << item; + } + + return IndexItem::Recurse; + }; + search(it.value())->visitAllChildren(filter); + if (!resultItems.isEmpty()) + future.reportResults(resultItems); + } + ++it; + ++progress; + future.setProgressValue(progress); + } + if (future.isPaused()) + future.waitForResume(); +} CppIndexingSupport::CppIndexingSupport() { @@ -356,7 +337,7 @@ QFuture CppIndexingSupport::refreshSourceFiles(const QSet &source SymbolSearcher *CppIndexingSupport::createSymbolSearcher( const SymbolSearcher::Parameters ¶meters, const QSet &fileNames) { - return new BuiltinSymbolSearcher(CppModelManager::instance()->snapshot(), parameters, fileNames); + return new SymbolSearcher(parameters, fileNames); } } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppindexingsupport.h b/src/plugins/cppeditor/cppindexingsupport.h index 410de9b04e4..abf9311787d 100644 --- a/src/plugins/cppeditor/cppindexingsupport.h +++ b/src/plugins/cppeditor/cppindexingsupport.h @@ -7,11 +7,9 @@ #include "cppmodelmanager.h" -#include #include #include -#include namespace Core { class SearchResultItem; } @@ -45,11 +43,13 @@ public: SearchScope scope; }; + SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet &fileNames); + void runSearch(QFutureInterface &future); -public: - SymbolSearcher(QObject *parent = nullptr); - ~SymbolSearcher() override = 0; - virtual void runSearch(QFutureInterface &future) = 0; +private: + const CPlusPlus::Snapshot m_snapshot; + const Parameters m_parameters; + const QSet m_fileNames; }; class CPPEDITOR_EXPORT CppIndexingSupport