diff options
author | hjk <hjk@qt.io> | 2023-07-12 09:47:29 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-07-12 13:08:09 +0000 |
commit | 0b83f110f4ca1a620e8faf2db423886aab255602 (patch) | |
tree | 278ae53b2dcf4ec2441a386626581e00e2a0b06e /src/plugins | |
parent | 8f82e76ba1c4c3c05aa9e14c2c7937809ec775d2 (diff) |
CppEditor: Make a few CppModelManager functions static
... to simplify code using it.
Change-Id: Ib2bfbb5a17a1d48088a9cf4973d4c3f006cd34e4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins')
80 files changed, 516 insertions, 630 deletions
diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index 1211b7f5e48..6e12778ded2 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -392,7 +392,7 @@ void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode) const int line = currentEditor->currentLine(); const FilePath filePath = currentEditor->textDocument()->filePath(); - const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); const CPlusPlus::Document::Ptr doc = snapshot.document(filePath); if (doc.isNull()) // not part of C++ snapshot return; diff --git a/src/plugins/autotest/boost/boosttestparser.cpp b/src/plugins/autotest/boost/boosttestparser.cpp index 8c701942ada..47b190ecffe 100644 --- a/src/plugins/autotest/boost/boosttestparser.cpp +++ b/src/plugins/autotest/boost/boosttestparser.cpp @@ -104,9 +104,8 @@ bool BoostTestParser::processDocument(QPromise<TestParseResultPtr> &promise, if (doc.isNull() || !includesBoostTest(doc, m_cppSnapshot) || !hasBoostTestMacros(doc)) return false; - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); const QList<CppEditor::ProjectPart::ConstPtr> projectParts - = modelManager->projectPart(fileName); + = CppEditor::CppModelManager::projectPart(fileName); if (projectParts.isEmpty()) // happens if shutting down while parsing return false; const CppEditor::ProjectPart::ConstPtr projectPart = projectParts.first(); diff --git a/src/plugins/autotest/boost/boosttesttreeitem.cpp b/src/plugins/autotest/boost/boosttesttreeitem.cpp index 957ff73021a..d1fcdcdedd9 100644 --- a/src/plugins/autotest/boost/boosttesttreeitem.cpp +++ b/src/plugins/autotest/boost/boosttesttreeitem.cpp @@ -178,10 +178,9 @@ QList<ITestConfiguration *> BoostTestTreeItem::getAllTestConfigurations() const ++funcChildren; }); if (funcChildren) { - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); testsPerProjectfile[item->proFile()].testCases += funcChildren; - testsPerProjectfile[item->proFile()].internalTargets.unite(cppMM->internalTargets(item->filePath())); + testsPerProjectfile[item->proFile()].internalTargets.unite( + CppEditor::CppModelManager::internalTargets(item->filePath())); } }); @@ -219,8 +218,6 @@ QList<ITestConfiguration *> BoostTestTreeItem::getTestConfigurations( if (!item->enabled()) // ignore child tests known to be disabled when using run selected return; if (predicate(item)) { - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); QString tcName = item->name(); if (item->state().testFlag(BoostTestTreeItem::Templated)) tcName.append("<*"); @@ -229,7 +226,8 @@ QList<ITestConfiguration *> BoostTestTreeItem::getTestConfigurations( tcName = handleSpecialFunctionNames(tcName); testCasesForProjectFile[item->proFile()].testCases.append( item->prependWithParentsSuitePaths(tcName)); - testCasesForProjectFile[item->proFile()].internalTargets.unite(cppMM->internalTargets(item->filePath())); + testCasesForProjectFile[item->proFile()].internalTargets.unite( + CppEditor::CppModelManager::internalTargets(item->filePath())); } }); @@ -265,8 +263,6 @@ ITestConfiguration *BoostTestTreeItem::testConfiguration() const { ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); QTC_ASSERT(project, return nullptr); - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return nullptr); const Type itemType = type(); if (itemType == TestSuite || itemType == TestCase) { @@ -300,7 +296,7 @@ ITestConfiguration *BoostTestTreeItem::testConfiguration() const config->setProjectFile(proFile()); config->setProject(project); config->setTestCases(testCases); - config->setInternalTargets(cppMM->internalTargets(filePath())); + config->setInternalTargets(CppEditor::CppModelManager::internalTargets(filePath())); return config; } return nullptr; diff --git a/src/plugins/autotest/catch/catchtestparser.cpp b/src/plugins/autotest/catch/catchtestparser.cpp index 172304eb953..fac35df11d3 100644 --- a/src/plugins/autotest/catch/catchtestparser.cpp +++ b/src/plugins/autotest/catch/catchtestparser.cpp @@ -99,7 +99,6 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise, if (doc.isNull() || !includesCatchHeader(doc, m_cppSnapshot)) return false; - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); const QString &filePath = doc->filePath().toString(); const QByteArray &fileContent = getFileContent(fileName); @@ -115,7 +114,8 @@ bool CatchTestParser::processDocument(QPromise<TestParseResultPtr> &promise, } - const QList<CppEditor::ProjectPart::ConstPtr> projectParts = modelManager->projectPart(fileName); + const QList<CppEditor::ProjectPart::ConstPtr> projectParts + = CppEditor::CppModelManager::projectPart(fileName); if (projectParts.isEmpty()) // happens if shutting down while parsing return false; FilePath proFile; diff --git a/src/plugins/autotest/catch/catchtreeitem.cpp b/src/plugins/autotest/catch/catchtreeitem.cpp index 034c7ab1d04..9f1d7c8e17c 100644 --- a/src/plugins/autotest/catch/catchtreeitem.cpp +++ b/src/plugins/autotest/catch/catchtreeitem.cpp @@ -145,8 +145,6 @@ ITestConfiguration *CatchTreeItem::testConfiguration() const { ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); QTC_ASSERT(project, return nullptr); - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return nullptr); if (type() != TestCase) return nullptr; @@ -157,7 +155,7 @@ ITestConfiguration *CatchTreeItem::testConfiguration() const config->setProjectFile(proFile()); config->setProject(project); config->setTestCases(QStringList(testCasesString())); - config->setInternalTargets(cppMM->internalTargets(filePath())); + config->setInternalTargets(CppEditor::CppModelManager::internalTargets(filePath())); return config; } @@ -180,8 +178,6 @@ static void collectTestInfo(const TestTreeItem *item, bool ignoreCheckState) { QTC_ASSERT(item, return); - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); const int childCount = item->childCount(); if (item->type() == TestTreeItem::GroupNode) { item->forFirstLevelChildItems([&testCasesForProfile, ignoreCheckState](TestTreeItem *it) { @@ -198,15 +194,16 @@ static void collectTestInfo(const TestTreeItem *item, CatchTreeItem *current = static_cast<CatchTreeItem *>(it); testCasesForProfile[projectFile].names.append(current->testCasesString()); }); - testCasesForProfile[projectFile].internalTargets.unite(cppMM->internalTargets(item->filePath())); + testCasesForProfile[projectFile].internalTargets.unite( + CppEditor::CppModelManager::internalTargets(item->filePath())); } else if (item->checked() == Qt::PartiallyChecked) { - item->forFirstLevelChildItems([&testCasesForProfile, cppMM](TestTreeItem *child) { + item->forFirstLevelChildItems([&testCasesForProfile](TestTreeItem *child) { QTC_ASSERT(child->type() == TestTreeItem::TestCase, return); if (child->checked() == Qt::Checked) { CatchTreeItem *current = static_cast<CatchTreeItem *>(child); testCasesForProfile[child->proFile()].names.append(current->testCasesString()); testCasesForProfile[child->proFile()].internalTargets.unite( - cppMM->internalTargets(child->filePath())); + CppEditor::CppModelManager::internalTargets(child->filePath())); } }); @@ -222,13 +219,11 @@ static void collectFailedTestInfo(const CatchTreeItem *item, item->forAllChildItems([&testCasesForProfile](TestTreeItem *it) { QTC_ASSERT(it, return); QTC_ASSERT(it->parentItem(), return); - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); if (it->type() == TestTreeItem::TestCase && it->data(0, FailedRole).toBool()) { CatchTreeItem *current = static_cast<CatchTreeItem *>(it); testCasesForProfile[it->proFile()].names.append(current->testCasesString()); testCasesForProfile[it->proFile()].internalTargets.unite( - cppMM->internalTargets(it->filePath())); + CppEditor::CppModelManager::internalTargets(it->filePath())); } }); } @@ -270,8 +265,6 @@ QList<ITestConfiguration *> CatchTreeItem::getFailedTestConfigurations() const QList<ITestConfiguration *> CatchTreeItem::getTestConfigurationsForFile(const FilePath &fileName) const { QList<ITestConfiguration *> result; - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return result); ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); if (!project || type() != Root) @@ -296,7 +289,8 @@ QList<ITestConfiguration *> CatchTreeItem::getTestConfigurationsForFile(const Fi testConfig->setTestCases(testCases); testConfig->setProjectFile(item->proFile()); testConfig->setProject(ProjectExplorer::ProjectManager::startupProject()); - testConfig->setInternalTargets(cppMM->internalTargets(item->filePath())); + testConfig->setInternalTargets( + CppEditor::CppModelManager::internalTargets(item->filePath())); result << testConfig; } diff --git a/src/plugins/autotest/gtest/gtestparser.cpp b/src/plugins/autotest/gtest/gtestparser.cpp index bb2285bd43a..8fc292a9224 100644 --- a/src/plugins/autotest/gtest/gtestparser.cpp +++ b/src/plugins/autotest/gtest/gtestparser.cpp @@ -86,7 +86,6 @@ bool GTestParser::processDocument(QPromise<TestParseResultPtr> &promise, } const FilePath filePath = doc->filePath(); - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName); document->check(); CPlusPlus::AST *ast = document->translationUnit()->ast(); @@ -95,7 +94,8 @@ bool GTestParser::processDocument(QPromise<TestParseResultPtr> &promise, const QMap<GTestCaseSpec, GTestCodeLocationList> result = visitor.gtestFunctions(); FilePath proFile; - const QList<CppEditor::ProjectPart::ConstPtr> &ppList = modelManager->projectPart(filePath); + const QList<CppEditor::ProjectPart::ConstPtr> &ppList = + CppEditor::CppModelManager::projectPart(filePath); if (!ppList.isEmpty()) proFile = FilePath::fromString(ppList.first()->projectFile); else diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index ddeb8b8c4bf..fdcf150f9c0 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -504,14 +504,14 @@ QString GTestTreeItem::nameSuffix() const QSet<QString> internalTargets(const TestTreeItem &item) { QSet<QString> result; - const auto cppMM = CppEditor::CppModelManager::instance(); - const auto projectInfo = cppMM->projectInfo(ProjectExplorer::ProjectManager::startupProject()); + const auto projectInfo = CppEditor::CppModelManager::projectInfo( + ProjectExplorer::ProjectManager::startupProject()); if (!projectInfo) return {}; const FilePath filePath = item.filePath(); const QVector<CppEditor::ProjectPart::ConstPtr> projectParts = projectInfo->projectParts(); if (projectParts.isEmpty()) - return cppMM->dependingInternalTargets(item.filePath()); + return CppEditor::CppModelManager::dependingInternalTargets(item.filePath()); for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectParts) { if (FilePath::fromString(projectPart->projectFile) == item.proFile() && Utils::anyOf(projectPart->files, [&filePath](const CppEditor::ProjectFile &pf) { @@ -519,7 +519,7 @@ QSet<QString> internalTargets(const TestTreeItem &item) })) { result.insert(projectPart->buildSystemTarget); if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) - result.unite(cppMM->dependingInternalTargets(filePath)); + result.unite(CppEditor::CppModelManager::dependingInternalTargets(filePath)); } } return result; diff --git a/src/plugins/autotest/itestparser.cpp b/src/plugins/autotest/itestparser.cpp index 79fde2a0bb1..99b760f78bd 100644 --- a/src/plugins/autotest/itestparser.cpp +++ b/src/plugins/autotest/itestparser.cpp @@ -28,14 +28,14 @@ void CppParser::init(const QSet<FilePath> &filesToParse, bool fullParse) { Q_UNUSED(filesToParse) Q_UNUSED(fullParse) - m_cppSnapshot = CppEditor::CppModelManager::instance()->snapshot(); - m_workingCopy = CppEditor::CppModelManager::instance()->workingCopy(); + m_cppSnapshot = CppEditor::CppModelManager::snapshot(); + m_workingCopy = CppEditor::CppModelManager::workingCopy(); } bool CppParser::selectedForBuilding(const FilePath &fileName) { QList<CppEditor::ProjectPart::ConstPtr> projParts = - CppEditor::CppModelManager::instance()->projectPart(fileName); + CppEditor::CppModelManager::projectPart(fileName); return !projParts.isEmpty() && projParts.at(0)->selectedForBuilding; } @@ -62,8 +62,8 @@ bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot, const QString &cacheString, const std::function<bool(const FilePath &)> &checker) { - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); - const QList<CppEditor::ProjectPart::ConstPtr> projectParts = modelManager->projectPart(filePath); + const QList<CppEditor::ProjectPart::ConstPtr> projectParts + = CppEditor::CppModelManager::projectPart(filePath); if (projectParts.isEmpty()) return false; const QStringList precompiledHeaders = projectParts.first()->precompiledHeaders; diff --git a/src/plugins/autotest/qtest/qttestparser.cpp b/src/plugins/autotest/qtest/qttestparser.cpp index 57c85b08a9e..824f4860a45 100644 --- a/src/plugins/autotest/qtest/qttestparser.cpp +++ b/src/plugins/autotest/qtest/qttestparser.cpp @@ -74,7 +74,7 @@ static bool includesQtTest(const CPlusPlus::Document::Ptr &doc, const CPlusPlus: static bool qtTestLibDefined(const FilePath &fileName) { const QList<CppEditor::ProjectPart::ConstPtr> parts = - CppEditor::CppModelManager::instance()->projectPart(fileName); + CppEditor::CppModelManager::projectPart(fileName); if (parts.size() > 0) { return Utils::anyOf(parts.at(0)->projectMacros, [](const ProjectExplorer::Macro ¯o) { return macro.key == "QT_TESTLIB_LIB"; @@ -83,11 +83,10 @@ static bool qtTestLibDefined(const FilePath &fileName) return false; } -TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager, - const FilePath &filePath) const +TestCases QtTestParser::testCases(const FilePath &filePath) const { const QByteArray &fileContent = getFileContent(filePath); - CPlusPlus::Document::Ptr document = modelManager->document(filePath); + CPlusPlus::Document::Ptr document = CppEditor::CppModelManager::document(filePath); if (document.isNull()) return {}; @@ -305,8 +304,7 @@ bool QtTestParser::processDocument(QPromise<TestParseResultPtr> &promise, return false; } - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); - TestCases testCaseList(testCases(modelManager, fileName)); + TestCases testCaseList(testCases(fileName)); bool reported = false; // we might be in a reparse without the original entry point with the QTest::qExec() if (testCaseList.isEmpty() && !oldTestCases.empty()) @@ -319,7 +317,7 @@ bool QtTestParser::processDocument(QPromise<TestParseResultPtr> &promise, continue; QList<CppEditor::ProjectPart::ConstPtr> projectParts - = modelManager->projectPart(fileName); + = CppEditor::CppModelManager::projectPart(fileName); if (projectParts.isEmpty()) // happens if shutting down while parsing return false; diff --git a/src/plugins/autotest/qtest/qttestparser.h b/src/plugins/autotest/qtest/qttestparser.h index abd8b2b0aaa..ece2bc639c5 100644 --- a/src/plugins/autotest/qtest/qttestparser.h +++ b/src/plugins/autotest/qtest/qttestparser.h @@ -10,8 +10,6 @@ #include <optional> -namespace CppEditor { class CppModelManager; } - namespace Autotest { namespace Internal { @@ -40,8 +38,7 @@ public: const Utils::FilePath &fileName) override; private: - TestCases testCases(const CppEditor::CppModelManager *modelManager, - const Utils::FilePath &fileName) const; + TestCases testCases(const Utils::FilePath &fileName) const; QHash<QString, QtTestCodeLocationList> checkForDataTags(const Utils::FilePath &fileName) const; struct TestCaseData { Utils::FilePath fileName; diff --git a/src/plugins/autotest/qtest/qttesttreeitem.cpp b/src/plugins/autotest/qtest/qttesttreeitem.cpp index 81f95c17752..b44c79eed37 100644 --- a/src/plugins/autotest/qtest/qttesttreeitem.cpp +++ b/src/plugins/autotest/qtest/qttesttreeitem.cpp @@ -120,8 +120,6 @@ ITestConfiguration *QtTestTreeItem::testConfiguration() const { ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); QTC_ASSERT(project, return nullptr); - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return nullptr); QtTestConfiguration *config = nullptr; switch (type()) { @@ -155,15 +153,13 @@ ITestConfiguration *QtTestTreeItem::testConfiguration() const return nullptr; } if (config) - config->setInternalTargets(cppMM->internalTargets(filePath())); + config->setInternalTargets(CppEditor::CppModelManager::internalTargets(filePath())); return config; } static void fillTestConfigurationsFromCheckState(const TestTreeItem *item, QList<ITestConfiguration *> &testConfigurations) { - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); QTC_ASSERT(item, return); if (item->type() == TestTreeItem::GroupNode) { for (int row = 0, count = item->childCount(); row < count; ++row) @@ -198,15 +194,14 @@ static void fillTestConfigurationsFromCheckState(const TestTreeItem *item, testConfig->setTestCases(testCases); testConfig->setProjectFile(item->proFile()); testConfig->setProject(ProjectExplorer::ProjectManager::startupProject()); - testConfig->setInternalTargets(cppMM->internalTargets(item->filePath())); + testConfig->setInternalTargets( + CppEditor::CppModelManager::internalTargets(item->filePath())); testConfigurations << testConfig; } } static void collectFailedTestInfo(TestTreeItem *item, QList<ITestConfiguration *> &testConfigs) { - const auto cppMM = CppEditor::CppModelManager::instance(); - QTC_ASSERT(cppMM, return); QTC_ASSERT(item, return); if (item->type() == TestTreeItem::GroupNode) { for (int row = 0, count = item->childCount(); row < count; ++row) @@ -232,7 +227,8 @@ static void collectFailedTestInfo(TestTreeItem *item, QList<ITestConfiguration * testConfig->setTestCases(testCases); testConfig->setProjectFile(item->proFile()); testConfig->setProject(ProjectExplorer::ProjectManager::startupProject()); - testConfig->setInternalTargets(cppMM->internalTargets(item->filePath())); + testConfig->setInternalTargets( + CppEditor::CppModelManager::internalTargets(item->filePath())); testConfigs << testConfig; } diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 64b98e1aa28..6482f1613f3 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -82,9 +82,10 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc, return false; } -static QString quickTestSrcDir(const CppEditor::CppModelManager *cppMM, const FilePath &fileName) +static QString quickTestSrcDir(const FilePath &fileName) { - const QList<CppEditor::ProjectPart::ConstPtr> parts = cppMM->projectPart(fileName); + const QList<CppEditor::ProjectPart::ConstPtr> parts = + CppEditor::CppModelManager::projectPart(fileName); if (parts.size() > 0) { const ProjectExplorer::Macros ¯os = parts.at(0)->projectMacros; auto found = std::find_if(macros.cbegin(), macros.cend(), @@ -252,17 +253,17 @@ bool QuickTestParser::handleQtQuickTest(QPromise<TestParseResultPtr> &promise, CPlusPlus::Document::Ptr document, ITestFramework *framework) { - const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); if (quickTestName(document).isEmpty()) return false; - QList<CppEditor::ProjectPart::ConstPtr> ppList = modelManager->projectPart(document->filePath()); + QList<CppEditor::ProjectPart::ConstPtr> ppList = + CppEditor::CppModelManager::projectPart(document->filePath()); if (ppList.isEmpty()) // happens if shutting down while parsing return false; const FilePath cppFileName = document->filePath(); const FilePath proFile = FilePath::fromString(ppList.at(0)->projectFile); m_mainCppFiles.insert(cppFileName, proFile); - const FilePath srcDir = FilePath::fromString(quickTestSrcDir(modelManager, cppFileName)); + const FilePath srcDir = FilePath::fromString(quickTestSrcDir(cppFileName)); if (srcDir.isEmpty()) return false; diff --git a/src/plugins/autotest/quick/quicktesttreeitem.cpp b/src/plugins/autotest/quick/quicktesttreeitem.cpp index 88f43e15419..5252f8ea27b 100644 --- a/src/plugins/autotest/quick/quicktesttreeitem.cpp +++ b/src/plugins/autotest/quick/quicktesttreeitem.cpp @@ -370,8 +370,8 @@ bool QuickTestTreeItem::isGroupable() const QSet<QString> internalTargets(const FilePath &proFile) { QSet<QString> result; - const auto cppMM = CppEditor::CppModelManager::instance(); - const auto projectInfo = cppMM->projectInfo(ProjectExplorer::ProjectManager::startupProject()); + const auto projectInfo = + CppEditor::CppModelManager::projectInfo(ProjectExplorer::ProjectManager::startupProject()); if (!projectInfo) return {}; for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectInfo->projectParts()) { diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index 2648d63cd03..5dfecdadf15 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -337,7 +337,7 @@ void TestCodeParser::scanForTests(const QSet<FilePath> &filePaths, qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "StartParsing"; m_parsingTimer.restart(); QSet<QString> extensions; - const auto cppSnapshot = CppEditor::CppModelManager::instance()->snapshot(); + const auto cppSnapshot = CppEditor::CppModelManager::snapshot(); for (ITestParser *parser : codeParsers) { parser->init(files, isFullParse); diff --git a/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp b/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp index faa32fea086..6b3bd5b42ed 100644 --- a/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp +++ b/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp @@ -65,7 +65,7 @@ static void extractAllFiles(const DebuggerRunTool *runTool, QStringList &include FilePaths &headers, FilePaths &sources, FilePaths &assemblers) { const auto project = runTool->runControl()->project(); - const CppEditor::ProjectInfo::ConstPtr info = CppModelManager::instance()->projectInfo(project); + const CppEditor::ProjectInfo::ConstPtr info = CppModelManager::projectInfo(project); if (!info) return; const QVector<ProjectPart::ConstPtr> parts = info->projectParts(); diff --git a/src/plugins/clangcodemodel/clangcodemodelplugin.cpp b/src/plugins/clangcodemodel/clangcodemodelplugin.cpp index d9830ec8aa3..f178dc2824e 100644 --- a/src/plugins/clangcodemodel/clangcodemodelplugin.cpp +++ b/src/plugins/clangcodemodel/clangcodemodelplugin.cpp @@ -53,7 +53,7 @@ void ClangCodeModelPlugin::generateCompilationDB() if (!target) return; - const auto projectInfo = CppModelManager::instance()->projectInfo(target->project()); + const auto projectInfo = CppModelManager::projectInfo(target->project()); if (!projectInfo) return; FilePath baseDir = projectInfo->buildRoot(); @@ -78,7 +78,7 @@ ClangCodeModelPlugin::~ClangCodeModelPlugin() void ClangCodeModelPlugin::initialize() { TaskHub::addCategory({Constants::TASK_CATEGORY_DIAGNOSTICS, Tr::tr("Clang Code Model")}); - CppEditor::CppModelManager::instance()->activateClangCodeModel( + CppEditor::CppModelManager::activateClangCodeModel( std::make_unique<ClangModelManagerSupport>()); createCompilationDBAction(); @@ -135,8 +135,8 @@ void ClangCodeModelPlugin::createCompilationDBAction() "No active project."); return; } - const CppEditor::ProjectInfo::ConstPtr projectInfo = CppEditor::CppModelManager::instance() - ->projectInfo(project); + const CppEditor::ProjectInfo::ConstPtr projectInfo = + CppEditor::CppModelManager::projectInfo(project); if (!projectInfo || projectInfo->projectParts().isEmpty()) { MessageManager::writeDisrupting("Cannot generate compilation database: " "Project has no C/C++ project parts."); diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 11d0f47f894..f4ff68f52ee 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -407,7 +407,7 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir, c const Utils::FilePath includeDir = CppEditor::ClangdSettings(d->settings).clangdIncludePath(); CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder( - *CppEditor::CppModelManager::instance()->fallbackProjectPart(), + *CppEditor::CppModelManager::fallbackProjectPart(), warningsConfigForProject(nullptr), includeDir, {}); const CppEditor::UsePrecompiledHeaders usePch = CppEditor::getPchUsage(); const QJsonArray projectPartOptions = fullProjectPartOptions( @@ -755,7 +755,7 @@ bool ClangdClient::fileBelongsToProject(const Utils::FilePath &filePath) const RefactoringChangesData *ClangdClient::createRefactoringChangesBackend() const { return new CppEditor::CppRefactoringChangesData( - CppEditor::CppModelManager::instance()->snapshot()); + CppEditor::CppModelManager::snapshot()); } QVersionNumber ClangdClient::versionNumber() const @@ -875,8 +875,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, // TODO: Should we write the editor defines into the json file? It seems strange // that they should affect the index only while the file is open in the editor. const auto projectPart = !config.preferredProjectPartId.isEmpty() - ? CppEditor::CppModelManager::instance()->projectPartForId( - config.preferredProjectPartId) + ? CppEditor::CppModelManager::projectPartForId(config.preferredProjectPartId) : projectPartForFile(filePath); if (!projectPart) return; diff --git a/src/plugins/clangcodemodel/clangdcompletion.cpp b/src/plugins/clangcodemodel/clangdcompletion.cpp index 50a78c657d2..08179005bc7 100644 --- a/src/plugins/clangcodemodel/clangdcompletion.cpp +++ b/src/plugins/clangcodemodel/clangdcompletion.cpp @@ -609,7 +609,7 @@ QList<AssistProposalItemInterface *> ClangdCompletionAssistProcessor::generateCo if (!doc || pos < 0 || !Utils::anyOf(items, criterion)) return itemGenerator(items); const QString content = doc->toPlainText(); - const bool requiresSignal = CppModelManager::instance()->getSignalSlotType( + const bool requiresSignal = CppModelManager::getSignalSlotType( filePath(), content.toUtf8(), pos) == SignalSlotType::NewStyleSignal; if (requiresSignal) diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 98e855b4195..e9f37abb4e5 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -62,11 +62,6 @@ using namespace Utils; namespace ClangCodeModel::Internal { -static CppModelManager *cppModelManager() -{ - return CppModelManager::instance(); -} - static Project *fallbackProject() { if (Project * const p = ProjectTree::currentProject()) @@ -202,10 +197,10 @@ ClangModelManagerSupport::ClangModelManagerSupport() watchForInternalChanges(); setupClangdConfigFile(); checkSystemForClangdSuitability(); - cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>()); - cppModelManager()->setLocatorFilter(std::make_unique<ClangdAllSymbolsFilter>()); - cppModelManager()->setClassesFilter(std::make_unique<ClangdClassesFilter>()); - cppModelManager()->setFunctionsFilter(std::make_unique<ClangdFunctionsFilter>()); + CppModelManager::setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>()); + CppModelManager::setLocatorFilter(std::make_unique<ClangdAllSymbolsFilter>()); + CppModelManager::setClassesFilter(std::make_unique<ClangdClassesFilter>()); + CppModelManager::setFunctionsFilter(std::make_unique<ClangdFunctionsFilter>()); // Setup matchers LocatorMatcher::addMatcherCreator(MatcherType::AllSymbols, [] { return LanguageClient::languageClientMatchers( @@ -226,7 +221,7 @@ ClangModelManagerSupport::ClangModelManagerSupport() connect(editorManager, &EditorManager::currentEditorChanged, this, &ClangModelManagerSupport::onCurrentEditorChanged); - CppModelManager *modelManager = cppModelManager(); + CppModelManager *modelManager = CppModelManager::instance(); connect(modelManager, &CppModelManager::abstractEditorSupportContentsUpdated, this, &ClangModelManagerSupport::onAbstractEditorSupportContentsUpdated); connect(modelManager, &CppModelManager::abstractEditorSupportRemoved, @@ -382,7 +377,7 @@ void ClangModelManagerSupport::checkUnused(const Link &link, SearchResult *searc } } - CppModelManager::instance()->modelManagerSupport( + CppModelManager::modelManagerSupport( CppModelManager::Backend::Builtin)->checkUnused(link, search, callback); } @@ -409,7 +404,7 @@ void ClangModelManagerSupport::onCurrentEditorChanged(IEditor *editor) { // Update task hub issues for current CppEditorDocument TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); - if (!editor || !editor->document() || !cppModelManager()->isCppEditor(editor)) + if (!editor || !editor->document() || !CppModelManager::isCppEditor(editor)) return; const FilePath filePath = editor->document()->filePath(); @@ -460,12 +455,12 @@ static bool isProjectDataUpToDate(Project *project, ProjectInfoList projectInfo, return false; ProjectInfoList newProjectInfo; if (project) { - if (const ProjectInfo::ConstPtr pi = CppModelManager::instance()->projectInfo(project)) + if (const ProjectInfo::ConstPtr pi = CppModelManager::projectInfo(project)) newProjectInfo.append(pi); else return false; } else { - newProjectInfo = CppModelManager::instance()->projectInfos(); + newProjectInfo = CppModelManager::projectInfos(); } if (newProjectInfo.size() != projectInfo.size()) return false; @@ -486,8 +481,8 @@ void ClangModelManagerSupport::updateLanguageClient(Project *project) ProjectInfoList projectInfo; if (sessionModeEnabled()) { project = nullptr; - projectInfo = CppModelManager::instance()->projectInfos(); - } else if (const ProjectInfo::ConstPtr pi = CppModelManager::instance()->projectInfo(project)) { + projectInfo = CppModelManager::projectInfos(); + } else if (const ProjectInfo::ConstPtr pi = CppModelManager::projectInfo(project)) { projectInfo.append(pi); } else { return; @@ -771,7 +766,7 @@ void ClangModelManagerSupport::onEditorOpened(IEditor *editor) QTC_ASSERT(document, return); auto textDocument = qobject_cast<TextEditor::TextDocument *>(document); - if (textDocument && cppModelManager()->isCppEditor(editor)) { + if (textDocument && CppModelManager::isCppEditor(editor)) { connectToWidgetsMarkContextMenuRequested(editor->widget()); Project * project = ProjectManager::projectForFile(document->filePath()); diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index b9e9e7115ed..c89bdc15418 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -695,7 +695,7 @@ Tasking::Group ClangTool::runRecipe(const RunSettings &runSettings, } const ProjectInfo::ConstPtr projectInfoBeforeBuild - = CppModelManager::instance()->projectInfo(target->project()); + = CppModelManager::projectInfo(target->project()); const auto onTreeSetup = [this, storage, runSettings, diagnosticConfig, fileInfos, tempDir, environment, projectInfoBeforeBuild](TaskTree &taskTree) { @@ -710,7 +710,7 @@ Tasking::Group ClangTool::runRecipe(const RunSettings &runSettings, ProjectExplorerPlugin::saveModifiedFiles(); Project *project = m_runControl->project(); - const ProjectInfo::ConstPtr projectInfo = CppModelManager::instance()->projectInfo(project); + const ProjectInfo::ConstPtr projectInfo = CppModelManager::projectInfo(project); if (!projectInfo) { m_infoBarWidget->setError(InfoBarWidget::Error, failedMessage, [this] { showOutputPane(); }); @@ -892,7 +892,7 @@ FileInfos ClangTool::collectFileInfos(Project *project, FileSelection fileSelect return {}; } - const auto projectInfo = CppModelManager::instance()->projectInfo(project); + const auto projectInfo = CppModelManager::projectInfo(project); QTC_ASSERT(projectInfo, return FileInfos()); const FileInfos allFileInfos = sortedFileInfos(projectInfo->projectParts()); @@ -1024,7 +1024,7 @@ static bool canAnalyzeProject(Project *project) const bool projectSupportsLanguage = project->projectLanguages().contains(c) || project->projectLanguages().contains(cxx); return projectSupportsLanguage - && CppModelManager::instance()->projectInfo(project) + && CppModelManager::projectInfo(project) && ToolChainKitAspect::cxxToolChain(target->kit()); } return false; diff --git a/src/plugins/clangtools/documentclangtoolrunner.cpp b/src/plugins/clangtools/documentclangtoolrunner.cpp index 28ea234f9ad..5906cbc4e32 100644 --- a/src/plugins/clangtools/documentclangtoolrunner.cpp +++ b/src/plugins/clangtools/documentclangtoolrunner.cpp @@ -109,7 +109,7 @@ static VirtualFileSystemOverlay &vfso() static FileInfo getFileInfo(const FilePath &file, Project *project) { - const ProjectInfo::ConstPtr projectInfo = CppModelManager::instance()->projectInfo(project); + const ProjectInfo::ConstPtr projectInfo = CppModelManager::projectInfo(project); if (!projectInfo) return {}; diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index b766c0c4425..2906504eb7c 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -250,7 +250,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::D void Parser::updateDocuments(const QSet<FilePath> &documentPaths) { - updateDocumentsFromSnapshot(documentPaths, CppEditor::CppModelManager::instance()->snapshot()); + updateDocumentsFromSnapshot(documentPaths, CppEditor::CppModelManager::snapshot()); } void Parser::updateDocumentsFromSnapshot(const QSet<FilePath> &documentPaths, @@ -293,7 +293,7 @@ void Parser::resetData(const QHash<FilePath, QPair<QString, FilePaths>> &project d->m_projectCache.clear(); d->m_documentCache.clear(); - const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::snapshot(); for (auto it = projects.cbegin(); it != projects.cend(); ++it) { const auto projectData = it.value(); QSet<FilePath> commonFiles; @@ -313,7 +313,7 @@ void Parser::resetData(const QHash<FilePath, QPair<QString, FilePaths>> &project void Parser::addProject(const FilePath &projectPath, const QString &projectName, const FilePaths &filesInProject) { - const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::snapshot(); QSet<FilePath> commonFiles; for (const auto &fileInProject : filesInProject) { CPlusPlus::Document::Ptr doc = snapshot.document(fileInProject); diff --git a/src/plugins/cppcheck/cppchecktool.cpp b/src/plugins/cppcheck/cppchecktool.cpp index cd824b3db47..79e5a3e5b6e 100644 --- a/src/plugins/cppcheck/cppchecktool.cpp +++ b/src/plugins/cppcheck/cppchecktool.cpp @@ -180,7 +180,7 @@ void CppcheckTool::check(const Utils::FilePaths &files) return; const CppEditor::ProjectInfo::ConstPtr info - = CppEditor::CppModelManager::instance()->projectInfo(m_project); + = CppEditor::CppModelManager::projectInfo(m_project); if (!info) return; const QVector<CppEditor::ProjectPart::ConstPtr> parts = info->projectParts(); diff --git a/src/plugins/cppcheck/cppchecktrigger.cpp b/src/plugins/cppcheck/cppchecktrigger.cpp index 8be098df558..c7317a958d0 100644 --- a/src/plugins/cppcheck/cppchecktrigger.cpp +++ b/src/plugins/cppcheck/cppchecktrigger.cpp @@ -56,7 +56,7 @@ void CppcheckTrigger::checkEditors(const QList<IEditor *> &editors) using CppModelManager = CppEditor::CppModelManager; const CppEditor::ProjectInfo::ConstPtr info - = CppModelManager::instance()->projectInfo(m_currentProject); + = CppModelManager::projectInfo(m_currentProject); if (!info) return; diff --git a/src/plugins/cppeditor/abstracteditorsupport.cpp b/src/plugins/cppeditor/abstracteditorsupport.cpp index a275ed6b571..ff43c5895aa 100644 --- a/src/plugins/cppeditor/abstracteditorsupport.cpp +++ b/src/plugins/cppeditor/abstracteditorsupport.cpp @@ -16,26 +16,26 @@ using namespace Utils; namespace CppEditor { -AbstractEditorSupport::AbstractEditorSupport(CppModelManager *modelmanager, QObject *parent) : - QObject(parent), m_modelmanager(modelmanager), m_revision(1) +AbstractEditorSupport::AbstractEditorSupport(QObject *parent) : + QObject(parent), m_revision(1) { - modelmanager->addExtraEditorSupport(this); + CppModelManager::addExtraEditorSupport(this); } AbstractEditorSupport::~AbstractEditorSupport() { - m_modelmanager->removeExtraEditorSupport(this); + CppModelManager::removeExtraEditorSupport(this); } void AbstractEditorSupport::updateDocument() { ++m_revision; - m_modelmanager->updateSourceFiles({filePath()}); + CppModelManager::updateSourceFiles({filePath()}); } void AbstractEditorSupport::notifyAboutUpdatedContents() const { - m_modelmanager->emitAbstractEditorSupportContentsUpdated( + CppModelManager::emitAbstractEditorSupportContentsUpdated( filePath().toString(), sourceFilePath().toString(), contents()); } diff --git a/src/plugins/cppeditor/abstracteditorsupport.h b/src/plugins/cppeditor/abstracteditorsupport.h index 277001e0433..0f8a8d179b0 100644 --- a/src/plugins/cppeditor/abstracteditorsupport.h +++ b/src/plugins/cppeditor/abstracteditorsupport.h @@ -13,14 +13,12 @@ namespace ProjectExplorer { class Project; } namespace CppEditor { -class CppModelManager; - class CPPEDITOR_EXPORT AbstractEditorSupport : public QObject { Q_OBJECT public: - explicit AbstractEditorSupport(CppModelManager *modelmanager, QObject *parent = nullptr); + explicit AbstractEditorSupport(QObject *parent = nullptr); ~AbstractEditorSupport() override; /// \returns the contents, encoded as UTF-8 @@ -38,7 +36,6 @@ public: static bool usePragmaOnce(ProjectExplorer::Project *project); private: - CppModelManager *m_modelmanager; unsigned m_revision; }; diff --git a/src/plugins/cppeditor/baseeditordocumentparser.cpp b/src/plugins/cppeditor/baseeditordocumentparser.cpp index cbfa6f96859..109a478871f 100644 --- a/src/plugins/cppeditor/baseeditordocumentparser.cpp +++ b/src/plugins/cppeditor/baseeditordocumentparser.cpp @@ -92,8 +92,7 @@ ProjectPartInfo BaseEditorDocumentParser::projectPartInfo() const BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const FilePath &filePath) { - CppModelManager *cmmi = CppModelManager::instance(); - if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath)) { + if (CppEditorDocumentHandle *cppEditorDocument = CppModelManager::cppEditorDocument(filePath)) { if (BaseEditorDocumentProcessor *processor = cppEditorDocument->processor()) return processor->parser(); } @@ -109,14 +108,14 @@ ProjectPartInfo BaseEditorDocumentParser::determineProjectPart(const QString &fi { Internal::ProjectPartChooser chooser; chooser.setFallbackProjectPart([](){ - return CppModelManager::instance()->fallbackProjectPart(); + return CppModelManager::fallbackProjectPart(); }); chooser.setProjectPartsForFile([](const QString &filePath) { - return CppModelManager::instance()->projectPart(filePath); + return CppModelManager::projectPart(filePath); }); chooser.setProjectPartsFromDependenciesForFile([&](const QString &filePath) { const auto fileName = Utils::FilePath::fromString(filePath); - return CppModelManager::instance()->projectPartFromDependencies(fileName); + return CppModelManager::projectPartFromDependencies(fileName); }); const ProjectPartInfo chooserResult diff --git a/src/plugins/cppeditor/baseeditordocumentprocessor.cpp b/src/plugins/cppeditor/baseeditordocumentprocessor.cpp index c6c51675eb9..f48c5a710be 100644 --- a/src/plugins/cppeditor/baseeditordocumentprocessor.cpp +++ b/src/plugins/cppeditor/baseeditordocumentprocessor.cpp @@ -39,7 +39,7 @@ void BaseEditorDocumentProcessor::run(bool projectsUpdated) ? Utils::Language::C : Utils::Language::Cxx; - runImpl({CppModelManager::instance()->workingCopy(), + runImpl({CppModelManager::workingCopy(), ProjectExplorer::ProjectManager::startupProject(), languagePreference, projectsUpdated}); @@ -72,7 +72,7 @@ void BaseEditorDocumentProcessor::runParser(QPromise<void> &promise, } parser->update(promise, updateParams); - CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath().toString()}); + CppModelManager::finishedRefreshingSourceFiles({parser->filePath().toString()}); promise.setProgressValue(1); } diff --git a/src/plugins/cppeditor/builtincursorinfo.cpp b/src/plugins/cppeditor/builtincursorinfo.cpp index 4545ebe748d..15e1e0f4921 100644 --- a/src/plugins/cppeditor/builtincursorinfo.cpp +++ b/src/plugins/cppeditor/builtincursorinfo.cpp @@ -218,8 +218,8 @@ private: if (Symbol *s = Internal::CanonicalSymbol::canonicalSymbol( m_scope, m_expression, typeOfExpression)) { - const QList<int> tokenIndices = CppModelManager::instance() - ->references(s, typeOfExpression.context()); + const QList<int> tokenIndices = + CppModelManager::references(s, typeOfExpression.context()); result = toRanges(tokenIndices, m_document->translationUnit()); } diff --git a/src/plugins/cppeditor/builtineditordocumentparser.cpp b/src/plugins/cppeditor/builtineditordocumentparser.cpp index f6d7d6faf22..7c8444098e0 100644 --- a/src/plugins/cppeditor/builtineditordocumentparser.cpp +++ b/src/plugins/cppeditor/builtineditordocumentparser.cpp @@ -59,8 +59,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QPromise<void> &promise, bool invalidateSnapshot = false, invalidateConfig = false; - CppModelManager *modelManager = CppModelManager::instance(); - QByteArray configFile = modelManager->codeModelConfiguration(); + QByteArray configFile = CppModelManager::codeModelConfiguration(); ProjectExplorer::HeaderPaths headerPaths; FilePaths includedFiles; FilePaths precompiledHeaders; @@ -131,7 +130,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QPromise<void> &promise, else invalidateSnapshot = true; - Snapshot globalSnapshot = modelManager->snapshot(); + Snapshot globalSnapshot = CppModelManager::snapshot(); if (invalidateSnapshot) { state.snapshot = Snapshot(); @@ -172,19 +171,19 @@ void BuiltinEditorDocumentParser::updateImpl(const QPromise<void> &promise, Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) { const bool isInEditor = doc->filePath() == filePath(); - Document::Ptr otherDoc = modelManager->document(doc->filePath()); + Document::Ptr otherDoc = CppModelManager::document(doc->filePath()); unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1; if (isInEditor) newRev = qMax(rev + 1, newRev); doc->setRevision(newRev); - modelManager->emitDocumentUpdated(doc); + CppModelManager::emitDocumentUpdated(doc); if (releaseSourceAndAST_) doc->releaseSourceAndAST(); }); sourceProcessor.setFileSizeLimitInMb(m_fileSizeLimitInMb); sourceProcessor.setCancelChecker([&promise] { return promise.isCanceled(); }); - Snapshot globalSnapshot = modelManager->snapshot(); + Snapshot globalSnapshot = CppModelManager::snapshot(); globalSnapshot.remove(filePath()); sourceProcessor.setGlobalSnapshot(globalSnapshot); sourceProcessor.setWorkingCopy(workingCopy); diff --git a/src/plugins/cppeditor/builtineditordocumentprocessor.cpp b/src/plugins/cppeditor/builtineditordocumentprocessor.cpp index f4df1fcd0cd..cb94e84a67b 100644 --- a/src/plugins/cppeditor/builtineditordocumentprocessor.cpp +++ b/src/plugins/cppeditor/builtineditordocumentprocessor.cpp @@ -183,7 +183,7 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor() void BuiltinEditorDocumentProcessor::runImpl( const BaseEditorDocumentParser::UpdateParams &updateParams) { - m_parserFuture = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(), + m_parserFuture = Utils::asyncRun(CppModelManager::sharedThreadPool(), runParser, parser(), updateParams); } @@ -277,8 +277,7 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d continue; if (cppEditorDoc->filePath() == document->filePath()) continue; - CPlusPlus::Document::Ptr cppDoc = CppModelManager::instance()->document( - cppEditorDoc->filePath()); + CPlusPlus::Document::Ptr cppDoc = CppModelManager::document(cppEditorDoc->filePath()); if (!cppDoc) continue; if (!cppDoc->includedFiles().contains(document->filePath())) @@ -325,7 +324,7 @@ SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bo { QByteArray source; int revision = 0; - if (const auto entry = CppModelManager::instance()->workingCopy().get(filePath())) { + if (const auto entry = CppModelManager::workingCopy().get(filePath())) { source = entry->first; revision = entry->second; } diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp index 4cc69fe4392..01a208f7032 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp @@ -105,7 +105,7 @@ void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data, { SymbolFinder finder; m_followSymbol->findLink(data, processLinkCallback, - resolveTarget, CppModelManager::instance()->snapshot(), + resolveTarget, CppModelManager::snapshot(), data.editorWidget()->semanticInfo().doc, &finder, inNextSplit); } @@ -125,7 +125,7 @@ void BuiltinModelManagerSupport::switchDeclDef(const CursorInEditor &data, { SymbolFinder finder; m_followSymbol->switchDeclDef(data, processLinkCallback, - CppModelManager::instance()->snapshot(), data.editorWidget()->semanticInfo().doc, + CppModelManager::snapshot(), data.editorWidget()->semanticInfo().doc, &finder); } @@ -144,47 +144,39 @@ void BuiltinModelManagerSupport::globalRename(const CursorInEditor &data, const QString &replacement, const std::function<void()> &callback) { - CppModelManager *modelManager = CppModelManager::instance(); - if (!modelManager) - return; - CppEditorWidget *editorWidget = data.editorWidget(); QTC_ASSERT(editorWidget, return;); SemanticInfo info = editorWidget->semanticInfo(); - info.snapshot = modelManager->snapshot(); + info.snapshot = CppModelManager::snapshot(); info.snapshot.insert(info.doc); const QTextCursor &cursor = data.cursor(); if (const CPlusPlus::Macro *macro = findCanonicalMacro(cursor, info.doc)) { - modelManager->renameMacroUsages(*macro, replacement); + CppModelManager::renameMacroUsages(*macro, replacement); } else { Internal::CanonicalSymbol cs(info.doc, info.snapshot); CPlusPlus::Symbol *canonicalSymbol = cs(cursor); if (canonicalSymbol) - modelManager->renameUsages(canonicalSymbol, cs.context(), replacement, callback); + CppModelManager::renameUsages(canonicalSymbol, cs.context(), replacement, callback); } } void BuiltinModelManagerSupport::findUsages(const CursorInEditor &data) const { - CppModelManager *modelManager = CppModelManager::instance(); - if (!modelManager) - return; - CppEditorWidget *editorWidget = data.editorWidget(); QTC_ASSERT(editorWidget, return;); SemanticInfo info = editorWidget->semanticInfo(); - info.snapshot = modelManager->snapshot(); + info.snapshot = CppModelManager::snapshot(); info.snapshot.insert(info.doc); const QTextCursor &cursor = data.cursor(); if (const CPlusPlus::Macro *macro = findCanonicalMacro(cursor, info.doc)) { - modelManager->findMacroUsages(*macro); + CppModelManager::findMacroUsages(*macro); } else { Internal::CanonicalSymbol cs(info.doc, info.snapshot); CPlusPlus::Symbol *canonicalSymbol = cs(cursor); if (canonicalSymbol) - modelManager->findUsages(canonicalSymbol, cs.context()); + CppModelManager::findUsages(canonicalSymbol, cs.context()); } } @@ -199,7 +191,7 @@ void BuiltinModelManagerSupport::switchHeaderSource(const FilePath &filePath, void BuiltinModelManagerSupport::checkUnused(const Utils::Link &link, SearchResult *search, const Utils::LinkHandler &callback) { - CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); + CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); QFile file(link.targetFilePath.toString()); if (!file.open(QIODevice::ReadOnly)) return callback(link); diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 48ee4c80f1e..0b4c5d9af38 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -1642,8 +1642,6 @@ void CppCodeModelInspectorDialog::onWorkingCopyDocumentSelected(const QModelInde void CppCodeModelInspectorDialog::refresh() { - CppModelManager *cmmi = CppModelManager::instance(); - const int oldSnapshotIndex = m_snapshotSelector->currentIndex(); const bool selectEditorRelevant = m_selectEditorRelevantEntriesAfterRefreshCheckBox->isChecked(); @@ -1652,7 +1650,7 @@ void CppCodeModelInspectorDialog::refresh() m_snapshotInfos->clear(); m_snapshotSelector->clear(); - const Snapshot globalSnapshot = cmmi->snapshot(); + const Snapshot globalSnapshot = CppModelManager::snapshot(); CppCodeModelInspector::Dumper dumper(globalSnapshot); m_snapshotModel->setGlobalSnapshot(globalSnapshot); @@ -1666,7 +1664,7 @@ void CppCodeModelInspectorDialog::refresh() CppEditorDocumentHandle *cppEditorDocument = nullptr; if (editor) { const FilePath editorFilePath = editor->document()->filePath(); - cppEditorDocument = cmmi->cppEditorDocument(editorFilePath); + cppEditorDocument = CppModelManager::cppEditorDocument(editorFilePath); if (auto documentProcessor = CppModelManager::cppEditorDocumentProcessor(editorFilePath)) { const Snapshot editorSnapshot = documentProcessor->snapshot(); m_snapshotInfos->append(SnapshotInfo(editorSnapshot, SnapshotInfo::EditorSnapshot)); @@ -1721,7 +1719,7 @@ void CppCodeModelInspectorDialog::refresh() ? cppEditorDocument->processor()->parser()->projectPartInfo().projectPart : ProjectPart::ConstPtr(); - const QList<ProjectInfo::ConstPtr> projectInfos = cmmi->projectInfos(); + const QList<ProjectInfo::ConstPtr> projectInfos = CppModelManager::projectInfos(); dumper.dumpProjectInfos(projectInfos); m_projectPartsModel->configure(projectInfos, editorsProjectPart); m_projectPartsView->resizeColumns(ProjectPartsModel::ColumnCount); @@ -1737,7 +1735,7 @@ void CppCodeModelInspectorDialog::refresh() } // Working Copy - const WorkingCopy workingCopy = cmmi->workingCopy(); + const WorkingCopy workingCopy = CppModelManager::workingCopy(); dumper.dumpWorkingCopy(workingCopy); m_workingCopyModel->configure(workingCopy); m_workingCopyView->resizeColumns(WorkingCopyModel::ColumnCount); @@ -1752,8 +1750,8 @@ void CppCodeModelInspectorDialog::refresh() } // Merged entities - dumper.dumpMergedEntities(cmmi->headerPaths(), - ProjectExplorer::Macro::toByteArray(cmmi->definedMacros())); + dumper.dumpMergedEntities(CppModelManager::headerPaths(), + ProjectExplorer::Macro::toByteArray(CppModelManager::definedMacros())); } enum DocumentTabs { diff --git a/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp b/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp index e2c879b1835..28d96779d66 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp @@ -395,7 +395,7 @@ QString Utils::toString(const ProjectExplorer::Abi &abi) QString Utils::partsForFile(const ::Utils::FilePath &filePath) { const QList<ProjectPart::ConstPtr> parts - = CppModelManager::instance()->projectPart(filePath); + = CppModelManager::projectPart(filePath); QString result; for (const ProjectPart::ConstPtr &part : parts) result += part->displayName + QLatin1Char(','); diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 19ad8b5120c..82d15774330 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -417,7 +417,7 @@ std::unique_ptr<AssistInterface> InternalCompletionAssistProvider::createAssistI BuiltinEditorDocumentParser::get(filePath), languageFeatures, reason, - CppModelManager::instance()->workingCopy()); + CppModelManager::workingCopy()); } // ----------------- @@ -2076,7 +2076,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const m_gotCppSpecifics = true; if (m_parser) { - m_parser->update({CppModelManager::instance()->workingCopy(), + m_parser->update({CppModelManager::workingCopy(), nullptr, Utils::Language::Cxx, false}); diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index 9e7856b74b2..e03dc2b40fe 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -41,11 +41,6 @@ using namespace Utils; namespace CppEditor { namespace Internal { -static CppEditor::CppModelManager *mm() -{ - return CppEditor::CppModelManager::instance(); -} - enum { processDocumentIntervalInMs = 150 }; class CppEditorDocumentHandleImpl : public CppEditorDocumentHandle @@ -55,12 +50,12 @@ public: : m_cppEditorDocument(cppEditorDocument) , m_registrationFilePath(cppEditorDocument->filePath().toString()) { - mm()->registerCppEditorDocument(this); + CppModelManager::registerCppEditorDocument(this); } ~CppEditorDocumentHandleImpl() override { - mm()->unregisterCppEditorDocument(m_registrationFilePath); + CppModelManager::unregisterCppEditorDocument(m_registrationFilePath); } FilePath filePath() const override { return m_cppEditorDocument->filePath(); } @@ -101,7 +96,7 @@ CppEditorDocument::CppEditorDocument() connect(this, &IDocument::filePathChanged, this, &CppEditorDocument::onFilePathChanged); - connect(mm(), &CppModelManager::diagnosticsChanged, + connect(CppModelManager::instance(), &CppModelManager::diagnosticsChanged, this, &CppEditorDocument::onDiagnosticsChanged); connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged, @@ -187,7 +182,7 @@ void CppEditorDocument::onMimeTypeChanged() const QString &mt = mimeType(); m_isObjCEnabled = (mt == QLatin1String(Constants::OBJECTIVE_C_SOURCE_MIMETYPE) || mt == QLatin1String(Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)); - m_completionAssistProvider = mm()->completionAssistProvider(); + m_completionAssistProvider = CppModelManager::completionAssistProvider(); initializeTimer(); } @@ -380,7 +375,7 @@ void CppEditorDocument::updateOutline() { CPlusPlus::Document::Ptr document; if (!usesClangd()) - document = CppModelManager::instance()->snapshot().document(filePath()); + document = CppModelManager::snapshot().document(filePath()); m_overviewModel.update(document); } @@ -392,7 +387,7 @@ QFuture<CursorInfo> CppEditorDocument::cursorInfo(const CursorInfoParams ¶ms BaseEditorDocumentProcessor *CppEditorDocument::processor() { if (!m_processor) { - m_processor.reset(mm()->createEditorDocumentProcessor(this)); + m_processor.reset(CppModelManager::createEditorDocumentProcessor(this)); connect(m_processor.data(), &BaseEditorDocumentProcessor::projectPartInfoUpdated, [this](const ProjectPartInfo &info) { @@ -493,7 +488,7 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr const Utils::Id category = Utils::Id::fromString(kind); - for (const auto &diagnostic : mm()->diagnosticMessages()) { + for (const auto &diagnostic : CppModelManager::diagnosticMessages()) { if (diagnostic.filePath() == filePath()) { auto it = std::find_if(std::begin(removedMarks), std::end(removedMarks), diff --git a/src/plugins/cppeditor/cppeditoroutline.cpp b/src/plugins/cppeditor/cppeditoroutline.cpp index a34d2543612..4c39851274b 100644 --- a/src/plugins/cppeditor/cppeditoroutline.cpp +++ b/src/plugins/cppeditor/cppeditoroutline.cpp @@ -125,7 +125,7 @@ QWidget *CppEditorOutline::widget() const QSharedPointer<CPlusPlus::Document> getDocument(const Utils::FilePath &filePath) { - const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); return snapshot.document(filePath); } diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index 223ec0e09f7..40f1917a5a9 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -231,7 +231,7 @@ void CppEditorPlugin::initialize() d = new CppEditorPluginPrivate; d->initialize(); - CppModelManager::instance()->registerJsExtension(); + CppModelManager::registerJsExtension(); ExtensionSystem::PluginManager::addObject(&d->m_cppProjectUpdaterFactory); // Menus @@ -446,9 +446,8 @@ void CppEditorPlugin::initialize() cppToolsMenu->addSeparator(Core::Constants::G_DEFAULT_THREE); d->m_reparseExternallyChangedFiles = new QAction(Tr::tr("Reparse Externally Changed Files"), this); cmd = ActionManager::registerAction(d->m_reparseExternallyChangedFiles, Constants::UPDATE_CODEMODEL); - CppModelManager *cppModelManager = CppModelManager::instance(); connect(d->m_reparseExternallyChangedFiles, &QAction::triggered, - cppModelManager, &CppModelManager::updateModifiedSourceFiles); + CppModelManager::instance(), &CppModelManager::updateModifiedSourceFiles); cppToolsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE); ActionContainer *toolsDebug = ActionManager::actionContainer(Core::Constants::M_TOOLS_DEBUG); @@ -515,7 +514,7 @@ void CppEditorPlugin::extensionsInitialized() }); ProjectPanelFactory::registerFactory(fileNamesPanelFactory); - if (CppModelManager::instance()->isClangCodeModelActive()) { + if (CppModelManager::isClangCodeModelActive()) { d->m_clangdSettingsPage = new ClangdSettingsPage; const auto clangdPanelFactory = new ProjectPanelFactory; clangdPanelFactory->setPriority(100); @@ -528,7 +527,7 @@ void CppEditorPlugin::extensionsInitialized() // Add the hover handler factories here instead of in initialize() // so that the Clang Code Model has a chance to hook in. - d->m_cppEditorFactory.addHoverHandler(CppModelManager::instance()->createHoverHandler()); + d->m_cppEditorFactory.addHoverHandler(CppModelManager::createHoverHandler()); d->m_cppEditorFactory.addHoverHandler(new ColorPreviewHoverHandler); d->m_cppEditorFactory.addHoverHandler(new ResourcePreviewHoverHandler); @@ -876,8 +875,7 @@ FilePath correspondingHeaderOrSource(const FilePath &filePath, bool *wasHeader, // Find files in other projects } else { - CppModelManager *modelManager = CppModelManager::instance(); - const QList<ProjectInfo::ConstPtr> projectInfos = modelManager->projectInfos(); + const QList<ProjectInfo::ConstPtr> projectInfos = CppModelManager::projectInfos(); for (const ProjectInfo::ConstPtr &projectInfo : projectInfos) { const Project *project = projectForProjectInfo(*projectInfo); if (project == currentProject) diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index e8bf8750110..4ebcf3941ef 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -383,8 +383,6 @@ public: bool shouldOfferOutline() const { return !CppModelManager::usesClangd(m_cppEditorDocument); } public: - QPointer<CppModelManager> m_modelManager; - CppEditorDocument *m_cppEditorDocument; CppEditorOutline *m_cppEditorOutline = nullptr; @@ -405,8 +403,7 @@ public: }; CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q) - : m_modelManager(CppModelManager::instance()) - , m_cppEditorDocument(qobject_cast<CppEditorDocument *>(q->textDocument())) + : m_cppEditorDocument(qobject_cast<CppEditorDocument *>(q->textDocument())) , m_declDefLinkFinder(new FunctionDeclDefLinkFinder(q)) , m_localRenaming(q) , m_useSelectionsUpdater(q) @@ -611,7 +608,7 @@ void CppEditorWidget::findUsages(QTextCursor cursor) // 'this' in cursorInEditor is never used (and must never be used) asynchronously. const CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this, textDocument()}; QPointer<CppEditorWidget> cppEditorWidget = this; - d->m_modelManager->findUsages(cursorInEditor); + CppModelManager::findUsages(cursorInEditor); } void CppEditorWidget::renameUsages(const QString &replacement, QTextCursor cursor) @@ -626,7 +623,7 @@ void CppEditorWidget::renameUsages(const QString &replacement, QTextCursor curso showRenameWarningIfFileIsGenerated(link.targetFilePath); CursorInEditor cursorInEditor{cursor, textDocument()->filePath(), this, textDocument()}; QPointer<CppEditorWidget> cppEditorWidget = this; - d->m_modelManager->globalRename(cursorInEditor, replacement); + CppModelManager::globalRename(cursorInEditor, replacement); }; CppModelManager::followSymbol( CursorInEditor{cursor, textDocument()->filePath(), this, textDocument()}, @@ -640,7 +637,7 @@ void CppEditorWidget::renameUsages(const Utils::FilePath &filePath, const QStrin cursor = textCursor(); CursorInEditor cursorInEditor{cursor, filePath, this, textDocument()}; QPointer<CppEditorWidget> cppEditorWidget = this; - d->m_modelManager->globalRename(cursorInEditor, replacement, callback); + CppModelManager::globalRename(cursorInEditor, replacement, callback); } bool CppEditorWidget::selectBlockUp() @@ -695,15 +692,14 @@ bool CppEditorWidget::isWidgetHighlighted(QWidget *widget) namespace { -QList<ProjectPart::ConstPtr> fetchProjectParts(CppModelManager *modelManager, - const Utils::FilePath &filePath) +QList<ProjectPart::ConstPtr> fetchProjectParts(const Utils::FilePath &filePath) { - QList<ProjectPart::ConstPtr> projectParts = modelManager->projectPart(filePath); + QList<ProjectPart::ConstPtr> projectParts = CppModelManager::projectPart(filePath); if (projectParts.isEmpty()) - projectParts = modelManager->projectPartFromDependencies(filePath); + projectParts = CppModelManager::projectPartFromDependencies(filePath); if (projectParts.isEmpty()) - projectParts.append(modelManager->fallbackProjectPart()); + projectParts.append(CppModelManager::fallbackProjectPart()); return projectParts; } @@ -728,10 +724,10 @@ const ProjectPart *findProjectPartForCurrentProject( const ProjectPart *CppEditorWidget::projectPart() const { - if (!d->m_modelManager) + if (!CppModelManager::instance()) return nullptr; - auto projectParts = fetchProjectParts(d->m_modelManager, textDocument()->filePath()); + auto projectParts = fetchProjectParts(textDocument()->filePath()); return findProjectPartForCurrentProject(projectParts, ProjectExplorer::ProjectTree::currentProject()); @@ -868,11 +864,11 @@ void CppEditorWidget::renameSymbolUnderCursor() }; viewport()->setCursor(Qt::BusyCursor); - d->m_modelManager->startLocalRenaming(CursorInEditor{textCursor(), - textDocument()->filePath(), - this, textDocument()}, - projPart, - std::move(renameSymbols)); + CppModelManager::startLocalRenaming(CursorInEditor{textCursor(), + textDocument()->filePath(), + this, textDocument()}, + projPart, + std::move(renameSymbols)); } void CppEditorWidget::updatePreprocessorButtonTooltip() @@ -887,7 +883,7 @@ void CppEditorWidget::updatePreprocessorButtonTooltip() void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit) { - if (!d->m_modelManager) + if (!CppModelManager::instance()) return; const CursorInEditor cursor(textCursor(), textDocument()->filePath(), this, textDocument()); @@ -901,7 +897,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit) void CppEditorWidget::followSymbolToType(bool inNextSplit) { - if (!d->m_modelManager) + if (!CppModelManager::instance()) return; const CursorInEditor cursor(textCursor(), textDocument()->filePath(), this, textDocument()); @@ -968,7 +964,7 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor, bool resolveTarget, bool inNextSplit) { - if (!d->m_modelManager) + if (!CppModelManager::instance()) return processLinkCallback(Utils::Link()); if (followUrl(cursor, processLinkCallback)) @@ -1269,8 +1265,7 @@ std::unique_ptr<AssistInterface> CppEditorWidget::createAssistInterface(AssistKi return cap->createAssistInterface(textDocument()->filePath(), this, getFeatures(), reason); if (isOldStyleSignalOrSlot()) { - return CppModelManager::instance() - ->completionAssistProvider() + return CppModelManager::completionAssistProvider() ->createAssistInterface(textDocument()->filePath(), this, getFeatures(), reason); } } @@ -1331,7 +1326,7 @@ void CppEditorWidget::updateFunctionDeclDefLinkNow() if (!isSemanticInfoValidExceptLocalUses()) return; - Snapshot snapshot = d->m_modelManager->snapshot(); + Snapshot snapshot = CppModelManager::snapshot(); snapshot.insert(semanticDoc); d->m_declDefLinkFinder->startFindLinkAt(textCursor(), semanticDoc, snapshot); diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index 27b481cd0c7..2d5d1c4af48 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -475,7 +475,7 @@ static QFuture<QSharedPointer<CppElement>> exec(SourceFunction &&sourceFunction, ExecFunction &&execFunction, bool followTypedef = true) { - const Snapshot &snapshot = CppModelManager::instance()->snapshot(); + const Snapshot &snapshot = CppModelManager::snapshot(); Document::Ptr doc; QString expression; @@ -497,7 +497,7 @@ static QFuture<QSharedPointer<CppElement>> asyncExec( const CPlusPlus::LookupContext &lookupContext) { return Utils::asyncRun(&createTypeHierarchy, snapshot, lookupItem, lookupContext, - *CppModelManager::instance()->symbolFinder()); + *CppModelManager::symbolFinder()); } class FromExpressionFunctor @@ -589,7 +589,7 @@ QFuture<QSharedPointer<CppElement>> FromGuiFunctor::syncExec( QFutureInterface<QSharedPointer<CppElement>> futureInterface; futureInterface.reportStarted(); m_element = handleLookupItemMatch(snapshot, lookupItem, lookupContext, - *CppModelManager::instance()->symbolFinder()); + *CppModelManager::symbolFinder()); futureInterface.reportResult(m_element); futureInterface.reportFinished(); return futureInterface.future(); @@ -694,7 +694,7 @@ const QString &CppElementEvaluator::diagnosis() const Utils::Link CppElementEvaluator::linkFromExpression(const QString &expression, const FilePath &filePath) { - const Snapshot &snapshot = CppModelManager::instance()->snapshot(); + const Snapshot &snapshot = CppModelManager::snapshot(); Document::Ptr doc = snapshot.document(filePath); if (doc.isNull()) return Utils::Link(); diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index 460ad7d0b2d..78777021a7b 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -437,9 +437,9 @@ void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol * if (search->isInteractive()) SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); - const WorkingCopy workingCopy = m_modelManager->workingCopy(); + const WorkingCopy workingCopy = CppModelManager::workingCopy(); QFuture<CPlusPlus::Usage> result; - result = Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper, + result = Utils::asyncRun(CppModelManager::sharedThreadPool(), find_helper, workingCopy, context, symbol, categorize); createWatcher(result, search); @@ -484,7 +484,7 @@ void CppFindReferences::searchAgain(SearchResult *search) { CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>(); parameters.filesToRename.clear(); - CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); + CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); search->restart(); CPlusPlus::LookupContext context; CPlusPlus::Symbol *symbol = findSymbol(parameters, snapshot, &context); @@ -544,7 +544,7 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(parameters.symbolFilePath); // document is not parsed and has no bindings yet, do it - QByteArray source = getSource(newSymbolDocument->filePath(), m_modelManager->workingCopy()); + QByteArray source = getSource(newSymbolDocument->filePath(), CppModelManager::workingCopy()); CPlusPlus::Document::Ptr doc = snapshot.preprocessedDocument(source, newSymbolDocument->filePath()); doc->check(); @@ -747,8 +747,8 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri Core::EditorManager::openEditorAtSearchResult(item); }); - const CPlusPlus::Snapshot snapshot = m_modelManager->snapshot(); - const WorkingCopy workingCopy = m_modelManager->workingCopy(); + const CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); + const WorkingCopy workingCopy = CppModelManager::workingCopy(); // add the macro definition itself { @@ -768,7 +768,7 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri } QFuture<CPlusPlus::Usage> result; - result = Utils::asyncRun(m_modelManager->sharedThreadPool(), findMacroUses_helper, + result = Utils::asyncRun(CppModelManager::sharedThreadPool(), findMacroUses_helper, workingCopy, snapshot, macro); createWatcher(result, search); @@ -829,8 +829,8 @@ void CppFindReferences::checkUnused(Core::SearchResult *search, const Link &link }); connect(search, &SearchResult::canceled, watcher, [watcher] { watcher->cancel(); }); connect(search, &SearchResult::destroyed, watcher, [watcher] { watcher->cancel(); }); - watcher->setFuture(Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper, - m_modelManager->workingCopy(), context, symbol, true)); + watcher->setFuture(Utils::asyncRun(CppModelManager::sharedThreadPool(), find_helper, + CppModelManager::workingCopy(), context, symbol, true)); } void CppFindReferences::createWatcher(const QFuture<CPlusPlus::Usage> &future, SearchResult *search) diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index c36a83a3f6b..862866e01c5 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -209,7 +209,7 @@ Link findMacroLink(const QByteArray &name, const Document::Ptr &doc) { if (!name.isEmpty()) { if (doc) { - const Snapshot snapshot = CppModelManager::instance()->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); QSet<QString> processed; return findMacroLink_helper(name, doc, snapshot, &processed); } diff --git a/src/plugins/cppeditor/cppincludehierarchy.cpp b/src/plugins/cppeditor/cppincludehierarchy.cpp index caad2e0937b..6b543f6163a 100644 --- a/src/plugins/cppeditor/cppincludehierarchy.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy.cpp @@ -54,7 +54,7 @@ enum { static Snapshot globalSnapshot() { - return CppModelManager::instance()->snapshot(); + return CppModelManager::snapshot(); } struct FileAndLine diff --git a/src/plugins/cppeditor/cppincludesfilter.cpp b/src/plugins/cppeditor/cppincludesfilter.cpp index 9711b6f52de..e1df13f7a2d 100644 --- a/src/plugins/cppeditor/cppincludesfilter.cpp +++ b/src/plugins/cppeditor/cppincludesfilter.cpp @@ -90,7 +90,7 @@ CppIncludesFilter::CppIncludesFilter() if (entry) inputFilePaths.insert(entry->filePath()); } - const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); return [snapshot, inputFilePaths](const QFuture<void> &future) { // This body runs in non-main thread return generateFilePaths(future, snapshot, inputFilePaths); diff --git a/src/plugins/cppeditor/cppindexingsupport.cpp b/src/plugins/cppeditor/cppindexingsupport.cpp index 6aafb6043d7..8cb0677edd9 100644 --- a/src/plugins/cppeditor/cppindexingsupport.cpp +++ b/src/plugins/cppeditor/cppindexingsupport.cpp @@ -31,7 +31,7 @@ static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg) SymbolSearcher::SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames) - : m_snapshot(CppModelManager::instance()->snapshot()) + : m_snapshot(CppModelManager::snapshot()) , m_parameters(parameters) , m_fileNames(fileNames) {} @@ -138,8 +138,7 @@ void indexFindErrors(QPromise<void> &promise, const ParseParams params) // Parse the file as precisely as possible BuiltinEditorDocumentParser parser(FilePath::fromString(file)); parser.setReleaseSourceAndAST(false); - parser.update({CppModelManager::instance()->workingCopy(), nullptr, - Language::Cxx, false}); + parser.update({CppModelManager::workingCopy(), nullptr, Language::Cxx, false}); CPlusPlus::Document::Ptr document = parser.document(); QTC_ASSERT(document, return); @@ -181,8 +180,7 @@ void index(QPromise<void> &promise, const ParseParams params) const FilePath &conf = CppModelManager::configurationFileName(); bool processingHeaders = false; - CppModelManager *cmm = CppModelManager::instance(); - const ProjectExplorer::HeaderPaths fallbackHeaderPaths = cmm->headerPaths(); + const ProjectExplorer::HeaderPaths fallbackHeaderPaths = CppModelManager::headerPaths(); const CPlusPlus::LanguageFeatures defaultFeatures = CPlusPlus::LanguageFeatures::defaultFeatures(); @@ -192,7 +190,7 @@ void index(QPromise<void> &promise, const ParseParams params) break; const QString fileName = files.at(i); - const QList<ProjectPart::ConstPtr> parts = cmm->projectPart(fileName); + const QList<ProjectPart::ConstPtr> parts = CppModelManager::projectPart(fileName); const CPlusPlus::LanguageFeatures languageFeatures = parts.isEmpty() ? defaultFeatures : parts.first()->languageFeatures; @@ -236,7 +234,7 @@ void parse(QPromise<void> &promise, const ParseParams params) index(promise, params); promise.setProgressValue(files.size()); - CppModelManager::instance()->finishedRefreshingSourceFiles(files); + CppModelManager::finishedRefreshingSourceFiles(files); } } // anonymous namespace @@ -306,15 +304,13 @@ bool CppIndexingSupport::isFindErrorsIndexingActive() QFuture<void> CppIndexingSupport::refreshSourceFiles(const QSet<QString> &sourceFiles, CppModelManager::ProgressNotificationMode mode) { - CppModelManager *mgr = CppModelManager::instance(); - ParseParams params; params.indexerFileSizeLimitInMb = indexerFileSizeLimitInMb(); - params.headerPaths = mgr->headerPaths(); - params.workingCopy = mgr->workingCopy(); + params.headerPaths = CppModelManager::headerPaths(); + params.workingCopy = CppModelManager::workingCopy(); params.sourceFiles = sourceFiles; - QFuture<void> result = Utils::asyncRun(mgr->sharedThreadPool(), parse, params); + QFuture<void> result = Utils::asyncRun(CppModelManager::sharedThreadPool(), parse, params); m_synchronizer.addFuture(result); if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) { diff --git a/src/plugins/cppeditor/cpplocatorfilter.cpp b/src/plugins/cppeditor/cpplocatorfilter.cpp index cd1add7786e..383db4b94d3 100644 --- a/src/plugins/cppeditor/cpplocatorfilter.cpp +++ b/src/plugins/cppeditor/cpplocatorfilter.cpp @@ -41,7 +41,7 @@ void matchesFor(QPromise<void> &promise, const LocatorStorage &storage, const bool hasColonColon = input.contains("::"); const QRegularExpression shortRegexp = hasColonColon ? ILocatorFilter::createRegExp(input.mid(input.lastIndexOf("::") + 2)) : regexp; - CppLocatorData *locatorData = CppModelManager::instance()->locatorData(); + CppLocatorData *locatorData = CppModelManager::locatorData(); locatorData->filterAllFiles([&](const IndexItem::Ptr &info) { if (promise.isCanceled()) return IndexItem::Break; @@ -174,7 +174,7 @@ QList<IndexItem::Ptr> itemsOfCurrentDocument(const FilePath ¤tFileName) return {}; QList<IndexItem::Ptr> results; - const Snapshot snapshot = CppModelManager::instance()->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); if (const Document::Ptr thisDocument = snapshot.document(currentFileName)) { SearchSymbols search; search.setSymbolsToSearchFor(SymbolSearcher::Declarations | diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 7fb8115873e..3980f99ac89 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -215,6 +215,8 @@ public: QList<Document::DiagnosticMessage> m_diagnosticMessages; }; +static CppModelManagerPrivate *d; + } // namespace Internal using namespace Internal; @@ -296,14 +298,13 @@ QSet<FilePath> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr */ CppSourceProcessor *CppModelManager::createSourceProcessor() { - CppModelManager *that = instance(); - return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) { - const Document::Ptr previousDocument = that->document(doc->filePath()); + return new CppSourceProcessor(snapshot(), [](const Document::Ptr &doc) { + const Document::Ptr previousDocument = document(doc->filePath()); const unsigned newRevision = previousDocument.isNull() ? 1U : previousDocument->revision() + 1; doc->setRevision(newRevision); - that->emitDocumentUpdated(doc); + emitDocumentUpdated(doc); doc->releaseSourceAndAST(); }); } @@ -314,7 +315,7 @@ const FilePath &CppModelManager::editorConfigurationFileName() return config; } -ModelManagerSupport *CppModelManager::modelManagerSupport(Backend backend) const +ModelManagerSupport *CppModelManager::modelManagerSupport(Backend backend) { return backend == Backend::Builtin ? &d->m_builtinModelManagerSupport : d->m_activeModelManagerSupport; @@ -325,27 +326,26 @@ void CppModelManager::startLocalRenaming(const CursorInEditor &data, RenameCallback &&renameSymbolsCallback, Backend backend) { - instance()->modelManagerSupport(backend) + modelManagerSupport(backend) ->startLocalRenaming(data, projectPart, std::move(renameSymbolsCallback)); } void CppModelManager::globalRename(const CursorInEditor &data, const QString &replacement, const std::function<void()> &callback, Backend backend) { - instance()->modelManagerSupport(backend)->globalRename(data, replacement, callback); + modelManagerSupport(backend)->globalRename(data, replacement, callback); } void CppModelManager::findUsages(const CursorInEditor &data, Backend backend) { - instance()->modelManagerSupport(backend)->findUsages(data); + modelManagerSupport(backend)->findUsages(data); } void CppModelManager::switchHeaderSource(bool inNextSplit, Backend backend) { const IDocument *currentDocument = EditorManager::currentDocument(); QTC_ASSERT(currentDocument, return); - instance()->modelManagerSupport(backend)->switchHeaderSource(currentDocument->filePath(), - inNextSplit); + modelManagerSupport(backend)->switchHeaderSource(currentDocument->filePath(), inNextSplit); } void CppModelManager::showPreprocessedFile(bool inNextSplit) @@ -383,7 +383,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit) TemporaryDirectory::masterTemporaryDirectory()->filePath(outFileName)); const auto useBuiltinPreprocessor = [filePath, outFilePath, inNextSplit, contents = doc->contents()] { - const Document::Ptr preprocessedDoc = instance()->snapshot() + const Document::Ptr preprocessedDoc = snapshot() .preprocessedDocument(contents, filePath); QByteArray content = R"(/* Created using Qt Creator's built-in preprocessor. */ /* See Tools -> Debug Qt Creator -> Inspect C++ Code Model for the parameters used. @@ -430,7 +430,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit) } const ProjectPart::ConstPtr projectPart = Utils::findOrDefault( - instance()->projectPart(filePath), [](const ProjectPart::ConstPtr &pp) { + CppModelManager::projectPart(filePath), [](const ProjectPart::ConstPtr &pp) { return pp->belongsToProject(ProjectTree::currentProject()); }); if (!projectPart) { @@ -513,7 +513,7 @@ static void checkNextFunctionForUnused( remainingLinks = remainingLinksList; activeLinks = activeLinksList; search->setUserData(data); - CppModelManager::instance()->modelManagerSupport(CppModelManager::Backend::Best) + CppModelManager::modelManagerSupport(CppModelManager::Backend::Best) ->checkUnused(link, search, [search, link, findRefsFuture, actionsSwitcher](const Link &) { if (!search || findRefsFuture->isCanceled()) return; @@ -620,7 +620,7 @@ void CppModelManager::checkForUnusedSymbol(SearchResult *search, const CPlusPlus::LookupContext &context, const LinkHandler &callback) { - instance()->d->m_findReferences->checkUnused(search, link, symbol, context, callback); + d->m_findReferences->checkUnused(search, link, symbol, context, callback); } int argumentPositionOf(const AST *last, const CallAST *callAst) @@ -642,7 +642,7 @@ int argumentPositionOf(const AST *last, const CallAST *callAst) SignalSlotType CppModelManager::getSignalSlotType(const FilePath &filePath, const QByteArray &content, - int position) const + int position) { if (content.isEmpty()) return SignalSlotType::None; @@ -653,7 +653,7 @@ SignalSlotType CppModelManager::getSignalSlotType(const FilePath &filePath, if (position > 2 && content.mid(position - 2, 2) == "::") fixedContent.insert(position, 'x'); - const Snapshot snapshot = this->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); const Document::Ptr document = snapshot.preprocessedDocument(fixedContent, filePath); document->check(); QTextDocument textDocument(QString::fromUtf8(fixedContent)); @@ -763,7 +763,7 @@ SignalSlotType CppModelManager::getSignalSlotType(const FilePath &filePath, FollowSymbolUnderCursor &CppModelManager::builtinFollowSymbol() { - return instance()->d->m_builtinModelManagerSupport.followSymbolInterface(); + return d->m_builtinModelManagerSupport.followSymbolInterface(); } template<class FilterClass> @@ -804,32 +804,32 @@ void CppModelManager::setCurrentDocumentFilter(std::unique_ptr<ILocatorFilter> & setFilter(d->m_currentDocumentFilter, std::move(filter)); } -ILocatorFilter *CppModelManager::locatorFilter() const +ILocatorFilter *CppModelManager::locatorFilter() { return d->m_locatorFilter.get(); } -ILocatorFilter *CppModelManager::classesFilter() const +ILocatorFilter *CppModelManager::classesFilter() { return d->m_classesFilter.get(); } -ILocatorFilter *CppModelManager::includesFilter() const +ILocatorFilter *CppModelManager::includesFilter() { return d->m_includesFilter.get(); } -ILocatorFilter *CppModelManager::functionsFilter() const +ILocatorFilter *CppModelManager::functionsFilter() { return d->m_functionsFilter.get(); } -IFindFilter *CppModelManager::symbolsFindFilter() const +IFindFilter *CppModelManager::symbolsFindFilter() { return d->m_symbolsFindFilter.get(); } -ILocatorFilter *CppModelManager::currentDocumentFilter() const +ILocatorFilter *CppModelManager::currentDocumentFilter() { return d->m_currentDocumentFilter.get(); } @@ -841,7 +841,7 @@ const FilePath &CppModelManager::configurationFileName() void CppModelManager::updateModifiedSourceFiles() { - const Snapshot snapshot = this->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); QList<Document::Ptr> documentsToCheck; for (const Document::Ptr &document : snapshot) documentsToCheck << document; @@ -869,7 +869,7 @@ CppModelManager *CppModelManager::instance() void CppModelManager::registerJsExtension() { - JsExpander::registerGlobalObject("Cpp", [this] { + JsExpander::registerGlobalObject("Cpp", [] { return new CppToolsJsExtension(&d->m_locatorData); }); } @@ -878,16 +878,16 @@ void CppModelManager::initCppTools() { // Objects connect(VcsManager::instance(), &VcsManager::repositoryChanged, - this, &CppModelManager::updateModifiedSourceFiles); + m_instance, &CppModelManager::updateModifiedSourceFiles); connect(DocumentManager::instance(), &DocumentManager::filesChangedInternally, - this, [this](const FilePaths &filePaths) { + m_instance, [](const FilePaths &filePaths) { updateSourceFiles(toSet(filePaths)); }); - connect(this, &CppModelManager::documentUpdated, + connect(m_instance, &CppModelManager::documentUpdated, &d->m_locatorData, &CppLocatorData::onDocumentUpdated); - connect(this, &CppModelManager::aboutToRemoveFiles, + connect(m_instance, &CppModelManager::aboutToRemoveFiles, &d->m_locatorData, &CppLocatorData::onAboutToRemoveFiles); // Set up builtin filters @@ -895,7 +895,7 @@ void CppModelManager::initCppTools() setClassesFilter(std::make_unique<CppClassesFilter>()); setIncludesFilter(std::make_unique<CppIncludesFilter>()); setFunctionsFilter(std::make_unique<CppFunctionsFilter>()); - setSymbolsFindFilter(std::make_unique<SymbolsFindFilter>(this)); + setSymbolsFindFilter(std::make_unique<SymbolsFindFilter>()); setCurrentDocumentFilter(std::make_unique<CppCurrentDocumentFilter>()); // Setup matchers LocatorMatcher::addMatcherCreator(MatcherType::AllSymbols, [] { @@ -912,24 +912,13 @@ void CppModelManager::initCppTools() }); } -static bool setExtraDiagnosticsCallback(const QString &fileName, const QString &kind, - const QList<Document::DiagnosticMessage> &diagnostics) -{ - return m_instance->setExtraDiagnostics(fileName, kind, diagnostics); -} - -static Snapshot snapshotCallback() -{ - return m_instance->snapshot(); -} - CppModelManager::CppModelManager() - : d(new CppModelManagerPrivate) { + d = new CppModelManagerPrivate; m_instance = this; - CppModelManagerBase::registerSetExtraDiagnosticsCallback(&setExtraDiagnosticsCallback); - CppModelManagerBase::registerSnapshotCallback(&snapshotCallback); + CppModelManagerBase::registerSetExtraDiagnosticsCallback(&CppModelManager::setExtraDiagnostics); + CppModelManagerBase::registerSnapshotCallback(&CppModelManager::snapshot); // Used for weak dependency in VcsBaseSubmitEditor setObjectName("CppModelManager"); @@ -1002,13 +991,13 @@ CppModelManager::~CppModelManager() delete d; } -Snapshot CppModelManager::snapshot() const +Snapshot CppModelManager::snapshot() { QMutexLocker locker(&d->m_snapshotMutex); return d->m_snapshot; } -Document::Ptr CppModelManager::document(const FilePath &filePath) const +Document::Ptr CppModelManager::document(const FilePath &filePath) { QMutexLocker locker(&d->m_snapshotMutex); return d->m_snapshot.document(filePath); @@ -1042,7 +1031,7 @@ void CppModelManager::ensureUpdated() d->m_dirty = false; } -FilePaths CppModelManager::internalProjectFiles() const +FilePaths CppModelManager::internalProjectFiles() { FilePaths files; for (const ProjectData &projectData : std::as_const(d->m_projectData)) { @@ -1055,7 +1044,7 @@ FilePaths CppModelManager::internalProjectFiles() const return files; } -HeaderPaths CppModelManager::internalHeaderPaths() const +HeaderPaths CppModelManager::internalHeaderPaths() { HeaderPaths headerPaths; for (const ProjectData &projectData: std::as_const(d->m_projectData)) { @@ -1079,7 +1068,7 @@ static void addUnique(const Macros &newMacros, Macros ¯os, } } -Macros CppModelManager::internalDefinedMacros() const +Macros CppModelManager::internalDefinedMacros() { Macros macros; QSet<ProjectExplorer::Macro> alreadyIn; @@ -1107,7 +1096,7 @@ void CppModelManager::dumpModelManagerConfiguration(const QString &logFileId) ProjectExplorer::Macro::toByteArray(definedMacros())); } -QSet<AbstractEditorSupport *> CppModelManager::abstractEditorSupports() const +QSet<AbstractEditorSupport *> CppModelManager::abstractEditorSupports() { return d->m_extraEditorSupports; } @@ -1122,7 +1111,7 @@ void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupp d->m_extraEditorSupports.remove(editorSupport); } -CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const FilePath &filePath) const +CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const FilePath &filePath) { if (filePath.isEmpty()) return nullptr; @@ -1133,7 +1122,7 @@ CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const FilePath &file BaseEditorDocumentProcessor *CppModelManager::cppEditorDocumentProcessor(const FilePath &filePath) { - const auto document = instance()->cppEditorDocument(filePath); + const auto document = cppEditorDocument(filePath); return document ? document->processor() : nullptr; } @@ -1237,17 +1226,17 @@ WorkingCopy CppModelManager::buildWorkingCopyList() return workingCopy; } -WorkingCopy CppModelManager::workingCopy() const +WorkingCopy CppModelManager::workingCopy() { - return const_cast<CppModelManager *>(this)->buildWorkingCopyList(); + return buildWorkingCopyList(); } -QByteArray CppModelManager::codeModelConfiguration() const +QByteArray CppModelManager::codeModelConfiguration() { return QByteArray::fromRawData(pp_configuration, qstrlen(pp_configuration)); } -CppLocatorData *CppModelManager::locatorData() const +CppLocatorData *CppModelManager::locatorData() { return &d->m_locatorData; } @@ -1308,14 +1297,14 @@ QFuture<void> CppModelManager::updateSourceFiles(const QSet<FilePath> &sourceFil return d->m_internalIndexingSupport->refreshSourceFiles(filteredFiles, mode); } -ProjectInfoList CppModelManager::projectInfos() const +ProjectInfoList CppModelManager::projectInfos() { QReadLocker locker(&d->m_projectLock); return Utils::transform<QList<ProjectInfo::ConstPtr>>(d->m_projectData, [](const ProjectData &d) { return d.projectInfo; }); } -ProjectInfo::ConstPtr CppModelManager::projectInfo(Project *project) const +ProjectInfo::ConstPtr CppModelManager::projectInfo(Project *project) { QReadLocker locker(&d->m_projectLock); return d->m_projectData.value(project).projectInfo; @@ -1335,7 +1324,7 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec } } -const QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() const +const QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() { QMutexLocker locker(&d->m_cppEditorDocumentsMutex); return d->m_cppEditorDocuments.values(); @@ -1453,7 +1442,7 @@ void CppModelManagerPrivate::setupWatcher(const QFuture<void> &future, Project * projectData->indexer->setFuture(future); } -void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const +void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) { // Refresh visible documents QSet<IDocument *> visibleCppEditorDocuments; @@ -1534,7 +1523,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne const QSet<FilePath> removedFiles = comparer.removedFiles(); if (!removedFiles.isEmpty()) { filesRemoved = true; - emit aboutToRemoveFiles(transform<QStringList>(removedFiles, &FilePath::toString)); + emit m_instance->aboutToRemoveFiles(transform<QStringList>(removedFiles, &FilePath::toString)); removeFilesFromSnapshot(removedFiles); } } @@ -1570,10 +1559,10 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne // Announce removed project parts if (!removedProjectParts.isEmpty()) - emit projectPartsRemoved(removedProjectParts); + emit m_instance->projectPartsRemoved(removedProjectParts); // Announce added project parts - emit projectPartsUpdated(project); + emit m_instance->projectPartsUpdated(project); // Ideally, we would update all the editor documents that depend on the 'filesToReindex'. // However, on e.g. a session restore first the editor documents are created and then the @@ -1588,25 +1577,25 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne // It's safe to do this here, as only the UI thread writes to the map and no other thread // uses the indexer value. - d->setupWatcher(indexingFuture, project, projectData, this); + d->setupWatcher(indexingFuture, project, projectData, m_instance); return indexingFuture; } -ProjectPart::ConstPtr CppModelManager::projectPartForId(const QString &projectPartId) const +ProjectPart::ConstPtr CppModelManager::projectPartForId(const QString &projectPartId) { QReadLocker locker(&d->m_projectLock); return d->m_projectPartIdToProjectProjectPart.value(projectPartId); } -QList<ProjectPart::ConstPtr> CppModelManager::projectPart(const FilePath &fileName) const +QList<ProjectPart::ConstPtr> CppModelManager::projectPart(const FilePath &fileName) { QReadLocker locker(&d->m_projectLock); return d->m_fileToProjectParts.value(fileName.canonicalPath()); } QList<ProjectPart::ConstPtr> CppModelManager::projectPartFromDependencies( - const FilePath &fileName) const + const FilePath &fileName) { QSet<ProjectPart::ConstPtr> parts; const FilePaths deps = snapshot().filesDependingOn(fileName); @@ -1631,10 +1620,10 @@ bool CppModelManager::isCppEditor(IEditor *editor) bool CppModelManager::usesClangd(const TextEditor::TextDocument *document) { - return instance()->d->m_activeModelManagerSupport->usesClangd(document); + return d->m_activeModelManagerSupport->usesClangd(document); } -bool CppModelManager::isClangCodeModelActive() const +bool CppModelManager::isClangCodeModelActive() { return d->m_activeModelManagerSupport != &d->m_builtinModelManagerSupport; } @@ -1642,19 +1631,19 @@ bool CppModelManager::isClangCodeModelActive() const void CppModelManager::emitDocumentUpdated(Document::Ptr doc) { if (replaceDocument(doc)) - emit documentUpdated(doc); + emit m_instance->documentUpdated(doc); } void CppModelManager::emitAbstractEditorSupportContentsUpdated(const QString &filePath, const QString &sourcePath, const QByteArray &contents) { - emit abstractEditorSupportContentsUpdated(filePath, sourcePath, contents); + emit m_instance->abstractEditorSupportContentsUpdated(filePath, sourcePath, contents); } void CppModelManager::emitAbstractEditorSupportRemoved(const QString &filePath) { - emit abstractEditorSupportRemoved(filePath); + emit m_instance->abstractEditorSupportRemoved(filePath); } void CppModelManager::onProjectAdded(Project *) @@ -1694,7 +1683,7 @@ void CppModelManager::onAboutToRemoveProject(Project *project) } if (!idsOfRemovedProjectParts.isEmpty()) - emit projectPartsRemoved(idsOfRemovedProjectParts); + emit m_instance->projectPartsRemoved(idsOfRemovedProjectParts); delayedGC(); } @@ -1713,7 +1702,7 @@ void CppModelManager::onActiveProjectChanged(Project *project) updateCppEditorDocuments(); } -void CppModelManager::onSourceFilesRefreshed() const +void CppModelManager::onSourceFilesRefreshed() { if (CppIndexingSupport::isFindErrorsIndexingActive()) { QTimer::singleShot(1, QCoreApplication::instance(), &QCoreApplication::quit); @@ -1745,10 +1734,10 @@ void CppModelManager::onAboutToLoadSession() GC(); } -QSet<QString> CppModelManager::dependingInternalTargets(const FilePath &file) const +QSet<QString> CppModelManager::dependingInternalTargets(const FilePath &file) { QSet<QString> result; - const Snapshot snapshot = this->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); QTC_ASSERT(snapshot.contains(file), return result); bool wasHeader; const FilePath correspondingFile @@ -1762,8 +1751,10 @@ QSet<QString> CppModelManager::dependingInternalTargets(const FilePath &file) co return result; } -QSet<QString> CppModelManager::internalTargets(const FilePath &filePath) const +QSet<QString> CppModelManager::internalTargets(const FilePath &filePath) { + QTC_ASSERT(m_instance, return {}); + const QList<ProjectPart::ConstPtr> projectParts = projectPart(filePath); // if we have no project parts it's most likely a header with declarations only and CMake based if (projectParts.isEmpty()) @@ -1931,7 +1922,7 @@ void CppModelManager::setupFallbackProjectPart() QMutexLocker locker(&d->m_fallbackProjectPartMutex); d->m_fallbackProjectPart = part; } - emit fallbackProjectPartUpdated(); + emit m_instance->fallbackProjectPartUpdated(); } void CppModelManager::GC() @@ -1981,14 +1972,14 @@ void CppModelManager::GC() } // Announce removing files and replace the snapshot - emit aboutToRemoveFiles(notReachableFiles); + emit m_instance->aboutToRemoveFiles(notReachableFiles); replaceSnapshot(newSnapshot); - emit gcFinished(); + emit m_instance->gcFinished(); } void CppModelManager::finishedRefreshingSourceFiles(const QSet<QString> &files) { - emit sourceFilesRefreshed(files); + emit m_instance->sourceFilesRefreshed(files); } void CppModelManager::activateClangCodeModel( @@ -1998,12 +1989,12 @@ void CppModelManager::activateClangCodeModel( d->m_activeModelManagerSupport = d->m_extendedModelManagerSupport.get(); } -CppCompletionAssistProvider *CppModelManager::completionAssistProvider() const +CppCompletionAssistProvider *CppModelManager::completionAssistProvider() { return d->m_builtinModelManagerSupport.completionAssistProvider(); } -TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const +TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() { return d->m_builtinModelManagerSupport.createHoverHandler(); } @@ -2012,7 +2003,7 @@ void CppModelManager::followSymbol(const CursorInEditor &data, const LinkHandler &processLinkCallback, bool resolveTarget, bool inNextSplit, Backend backend) { - instance()->modelManagerSupport(backend)->followSymbol(data, processLinkCallback, + modelManagerSupport(backend)->followSymbol(data, processLinkCallback, resolveTarget, inNextSplit); } @@ -2020,7 +2011,7 @@ void CppModelManager::followSymbolToType(const CursorInEditor &data, const LinkHandler &processLinkCallback, bool inNextSplit, Backend backend) { - instance()->modelManagerSupport(backend)->followSymbolToType(data, processLinkCallback, + modelManagerSupport(backend)->followSymbolToType(data, processLinkCallback, inNextSplit); } @@ -2028,11 +2019,11 @@ void CppModelManager::switchDeclDef(const CursorInEditor &data, const LinkHandler &processLinkCallback, Backend backend) { - instance()->modelManagerSupport(backend)->switchDeclDef(data, processLinkCallback); + modelManagerSupport(backend)->switchDeclDef(data, processLinkCallback); } BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor( - TextEditor::TextDocument *baseTextDocument) const + TextEditor::TextDocument *baseTextDocument) { return d->m_activeModelManagerSupport->createEditorDocumentProcessor(baseTextDocument); } @@ -2093,7 +2084,7 @@ bool CppModelManager::setExtraDiagnostics(const QString &fileName, const QList<Document::DiagnosticMessage> &diagnostics) { d->m_diagnosticMessages = diagnostics; - emit diagnosticsChanged(fileName, kind); + emit m_instance->diagnosticsChanged(fileName, kind); return true; } diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 7dd49c6ebd1..6f6dc7298e3 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -80,95 +80,95 @@ public: static CppModelManager *instance(); - void registerJsExtension(); + static void registerJsExtension(); - // Documented in source file. - enum ProgressNotificationMode { + // Documented in source file. + enum ProgressNotificationMode { ForcedProgressNotification, ReservedProgressNotification }; - QFuture<void> updateSourceFiles(const QSet<Utils::FilePath> &sourceFiles, - ProgressNotificationMode mode = ReservedProgressNotification); - void updateCppEditorDocuments(bool projectsUpdated = false) const; - WorkingCopy workingCopy() const; - QByteArray codeModelConfiguration() const; - CppLocatorData *locatorData() const; + static QFuture<void> updateSourceFiles(const QSet<Utils::FilePath> &sourceFiles, + ProgressNotificationMode mode = ReservedProgressNotification); + static void updateCppEditorDocuments(bool projectsUpdated = false); + static WorkingCopy workingCopy(); + static QByteArray codeModelConfiguration(); + static CppLocatorData *locatorData(); - bool setExtraDiagnostics(const QString &fileName, - const QString &kind, - const QList<Document::DiagnosticMessage> &diagnostics); + static bool setExtraDiagnostics(const QString &fileName, + const QString &kind, + const QList<Document::DiagnosticMessage> &diagnostics); - const QList<Document::DiagnosticMessage> diagnosticMessages(); + static const QList<Document::DiagnosticMessage> diagnosticMessages(); - ProjectInfoList projectInfos() const; - ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const; - QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, - const QSet<Utils::FilePath> &additionalFiles = {}); + static ProjectInfoList projectInfos(); + static ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project); + static QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, + const QSet<Utils::FilePath> &additionalFiles = {}); /// \return The project part with the given project file - ProjectPart::ConstPtr projectPartForId(const QString &projectPartId) const; + static ProjectPart::ConstPtr projectPartForId(const QString &projectPartId); /// \return All project parts that mention the given file name as one of the sources/headers. - QList<ProjectPart::ConstPtr> projectPart(const Utils::FilePath &fileName) const; - QList<ProjectPart::ConstPtr> projectPart(const QString &fileName) const + static QList<ProjectPart::ConstPtr> projectPart(const Utils::FilePath &fileName); + static QList<ProjectPart::ConstPtr> projectPart(const QString &fileName) { return projectPart(Utils::FilePath::fromString(fileName)); } /// This is a fall-back function: find all files that includes the file directly or indirectly, /// and return its \c ProjectPart list for use with this file. - QList<ProjectPart::ConstPtr> projectPartFromDependencies(const Utils::FilePath &fileName) const; + static QList<ProjectPart::ConstPtr> projectPartFromDependencies(const Utils::FilePath &fileName); /// \return A synthetic \c ProjectPart which consists of all defines/includes/frameworks from /// all loaded projects. - ProjectPart::ConstPtr fallbackProjectPart(); + static ProjectPart::ConstPtr fallbackProjectPart(); - CPlusPlus::Snapshot snapshot() const; - Document::Ptr document(const Utils::FilePath &filePath) const; - bool replaceDocument(Document::Ptr newDoc); + static CPlusPlus::Snapshot snapshot(); + static Document::Ptr document(const Utils::FilePath &filePath); + static bool replaceDocument(Document::Ptr newDoc); - void emitDocumentUpdated(Document::Ptr doc); - void emitAbstractEditorSupportContentsUpdated(const QString &filePath, + static void emitDocumentUpdated(Document::Ptr doc); + static void emitAbstractEditorSupportContentsUpdated(const QString &filePath, const QString &sourcePath, const QByteArray &contents); - void emitAbstractEditorSupportRemoved(const QString &filePath); + static void emitAbstractEditorSupportRemoved(const QString &filePath); static bool isCppEditor(Core::IEditor *editor); static bool usesClangd(const TextEditor::TextDocument *document); - bool isClangCodeModelActive() const; + static bool isClangCodeModelActive(); - QSet<AbstractEditorSupport*> abstractEditorSupports() const; - void addExtraEditorSupport(AbstractEditorSupport *editorSupport); - void removeExtraEditorSupport(AbstractEditorSupport *editorSupport); + static QSet<AbstractEditorSupport*> abstractEditorSupports(); + static void addExtraEditorSupport(AbstractEditorSupport *editorSupport); + static void removeExtraEditorSupport(AbstractEditorSupport *editorSupport); - const QList<CppEditorDocumentHandle *> cppEditorDocuments() const; - CppEditorDocumentHandle *cppEditorDocument(const Utils::FilePath &filePath) const; + static const QList<CppEditorDocumentHandle *> cppEditorDocuments(); + static CppEditorDocumentHandle *cppEditorDocument(const Utils::FilePath &filePath); static BaseEditorDocumentProcessor *cppEditorDocumentProcessor(const Utils::FilePath &filePath); - void registerCppEditorDocument(CppEditorDocumentHandle *cppEditorDocument); - void unregisterCppEditorDocument(const QString &filePath); - - QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); - - SignalSlotType getSignalSlotType(const Utils::FilePath &filePath, - const QByteArray &content, - int position) const; - - void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, - const QString &replacement = QString(), - const std::function<void()> &callback = {}); - void renameUsages(const CPlusPlus::Document::Ptr &doc, - const QTextCursor &cursor, - const CPlusPlus::Snapshot &snapshot, - const QString &replacement, - const std::function<void()> &callback); - void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); - - void findMacroUsages(const CPlusPlus::Macro ¯o); - void renameMacroUsages(const CPlusPlus::Macro ¯o, const QString &replacement); - - void finishedRefreshingSourceFiles(const QSet<QString> &files); - - void activateClangCodeModel(std::unique_ptr<ModelManagerSupport> &&modelManagerSupport); - CppCompletionAssistProvider *completionAssistProvider() const; - BaseEditorDocumentProcessor *createEditorDocumentProcessor( - TextEditor::TextDocument *baseTextDocument) const; - TextEditor::BaseHoverHandler *createHoverHandler() const; + static void registerCppEditorDocument(CppEditorDocumentHandle *cppEditorDocument); + static void unregisterCppEditorDocument(const QString &filePath); + + static QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); + + static SignalSlotType getSignalSlotType(const Utils::FilePath &filePath, + const QByteArray &content, + int position); + + static void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, + const QString &replacement = QString(), + const std::function<void()> &callback = {}); + static void renameUsages(const CPlusPlus::Document::Ptr &doc, + const QTextCursor &cursor, + const CPlusPlus::Snapshot &snapshot, + const QString &replacement, + const std::function<void()> &callback); + static void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); + + static void findMacroUsages(const CPlusPlus::Macro ¯o); + static void renameMacroUsages(const CPlusPlus::Macro ¯o, const QString &replacement); + + static void finishedRefreshingSourceFiles(const QSet<QString> &files); + + static void activateClangCodeModel(std::unique_ptr<ModelManagerSupport> &&modelManagerSupport); + static CppCompletionAssistProvider *completionAssistProvider(); + static BaseEditorDocumentProcessor *createEditorDocumentProcessor( + TextEditor::TextDocument *baseTextDocument); + static TextEditor::BaseHoverHandler *createHoverHandler(); static FollowSymbolUnderCursor &builtinFollowSymbol(); enum class Backend { Builtin, Best }; @@ -196,22 +196,22 @@ public: const CPlusPlus::LookupContext &context, const Utils::LinkHandler &callback); - CppIndexingSupport *indexingSupport(); + static CppIndexingSupport *indexingSupport(); - Utils::FilePaths projectFiles(); + static Utils::FilePaths projectFiles(); - ProjectExplorer::HeaderPaths headerPaths(); + static ProjectExplorer::HeaderPaths headerPaths(); // Use this *only* for auto tests - void setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths); + static void setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths); - ProjectExplorer::Macros definedMacros(); + static ProjectExplorer::Macros definedMacros(); - void enableGarbageCollector(bool enable); + static void enableGarbageCollector(bool enable); - SymbolFinder *symbolFinder(); + static SymbolFinder *symbolFinder(); - QThreadPool *sharedThreadPool(); + static QThreadPool *sharedThreadPool(); static QSet<Utils::FilePath> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck); @@ -219,34 +219,34 @@ public: static const Utils::FilePath &configurationFileName(); static const Utils::FilePath &editorConfigurationFileName(); - void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); - void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); - void setIncludesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); - void setFunctionsFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); - void setSymbolsFindFilter(std::unique_ptr<Core::IFindFilter> &&filter); - void setCurrentDocumentFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); + static void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); + static void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); + static void setIncludesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); + static void setFunctionsFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); + static void setSymbolsFindFilter(std::unique_ptr<Core::IFindFilter> &&filter); + static void setCurrentDocumentFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); - Core::ILocatorFilter *locatorFilter() const; - Core::ILocatorFilter *classesFilter() const; - Core::ILocatorFilter *includesFilter() const; - Core::ILocatorFilter *functionsFilter() const; - Core::IFindFilter *symbolsFindFilter() const; - Core::ILocatorFilter *currentDocumentFilter() const; + static Core::ILocatorFilter *locatorFilter(); + static Core::ILocatorFilter *classesFilter(); + static Core::ILocatorFilter *includesFilter(); + static Core::ILocatorFilter *functionsFilter(); + static Core::IFindFilter *symbolsFindFilter(); + static Core::ILocatorFilter *currentDocumentFilter(); /* * try to find build system target that depends on the given file - if the file is no header * try to find the corresponding header and use this instead to find the respective target */ - QSet<QString> dependingInternalTargets(const Utils::FilePath &file) const; + static QSet<QString> dependingInternalTargets(const Utils::FilePath &file); - QSet<QString> internalTargets(const Utils::FilePath &filePath) const; + static QSet<QString> internalTargets(const Utils::FilePath &filePath); - void renameIncludes(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); + static void renameIncludes(const Utils::FilePath &oldFilePath, const Utils::FilePath &newFilePath); // for VcsBaseSubmitEditor Q_INVOKABLE QSet<QString> symbolsInFiles(const QSet<Utils::FilePath> &files) const; - ModelManagerSupport *modelManagerSupport(Backend backend) const; + static ModelManagerSupport *modelManagerSupport(Backend backend); signals: /// Project data might be locked while this is emitted. @@ -271,40 +271,37 @@ signals: void diagnosticsChanged(const QString &fileName, const QString &kind); public slots: - void updateModifiedSourceFiles(); - void GC(); + static void updateModifiedSourceFiles(); + static void GC(); private: // This should be executed in the GUI thread. friend class Tests::ModelManagerTestHelper; - void onAboutToLoadSession(); - void onProjectAdded(ProjectExplorer::Project *project); - void onAboutToRemoveProject(ProjectExplorer::Project *project); - void onActiveProjectChanged(ProjectExplorer::Project *project); - void onSourceFilesRefreshed() const; - void onCurrentEditorChanged(Core::IEditor *editor); - void onCoreAboutToClose(); - void setupFallbackProjectPart(); - - void delayedGC(); - void recalculateProjectPartMappings(); - - void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot); - void removeFilesFromSnapshot(const QSet<Utils::FilePath> &removedFiles); - void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo); - - WorkingCopy buildWorkingCopyList(); - - void ensureUpdated(); - Utils::FilePaths internalProjectFiles() const; - ProjectExplorer::HeaderPaths internalHeaderPaths() const; - ProjectExplorer::Macros internalDefinedMacros() const; - - void dumpModelManagerConfiguration(const QString &logFileId); - void initCppTools(); - -private: - Internal::CppModelManagerPrivate *d; + static void onAboutToLoadSession(); + static void onProjectAdded(ProjectExplorer::Project *project); + static void onAboutToRemoveProject(ProjectExplorer::Project *project); + static void onActiveProjectChanged(ProjectExplorer::Project *project); + static void onSourceFilesRefreshed(); + static void onCurrentEditorChanged(Core::IEditor *editor); + static void onCoreAboutToClose(); + static void setupFallbackProjectPart(); + + static void delayedGC(); + static void recalculateProjectPartMappings(); + + static void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot); + static void removeFilesFromSnapshot(const QSet<Utils::FilePath> &removedFiles); + static void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo); + + static WorkingCopy buildWorkingCopyList(); + + static void ensureUpdated(); + static Utils::FilePaths internalProjectFiles(); + static ProjectExplorer::HeaderPaths internalHeaderPaths(); + static ProjectExplorer::Macros internalDefinedMacros(); + + static void dumpModelManagerConfiguration(const QString &logFileId); + static void initCppTools(); }; } // CppEditor diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index cb292293e44..c2a9189fd63 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -164,7 +164,7 @@ private: static ProjectPart::ConstPtr projectPartOfEditorDocument(const FilePath &filePath) { - auto *editorDocument = CppModelManager::instance()->cppEditorDocument(filePath); + auto *editorDocument = CppModelManager::cppEditorDocument(filePath); QTC_ASSERT(editorDocument, return ProjectPart::ConstPtr()); return editorDocument->processor()->parser()->projectPartInfo().projectPart; } @@ -173,7 +173,6 @@ static ProjectPart::ConstPtr projectPartOfEditorDocument(const FilePath &filePat void ModelManagerTest::testPathsAreClean() { ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata")); @@ -188,9 +187,9 @@ void ModelManagerTest::testPathsAreClean() const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); - mm->updateProjectInfo(pi); + CppModelManager::updateProjectInfo(pi); - ProjectExplorer::HeaderPaths headerPaths = mm->headerPaths(); + ProjectExplorer::HeaderPaths headerPaths = CppModelManager::headerPaths(); QCOMPARE(headerPaths.size(), 2); QVERIFY(headerPaths.contains(HeaderPath::makeUser(testDataDir.includeDir()))); QVERIFY(headerPaths.contains(HeaderPath::makeFramework(testDataDir.frameworksDir()))); @@ -203,7 +202,6 @@ void ModelManagerTest::testFrameworkHeaders() QSKIP("Can't resolve framework soft links on Windows."); ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata")); @@ -221,11 +219,11 @@ void ModelManagerTest::testFrameworkHeaders() const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); - mm->updateProjectInfo(pi).waitForFinished(); + CppModelManager::updateProjectInfo(pi).waitForFinished(); QCoreApplication::processEvents(); - QVERIFY(mm->snapshot().contains(source)); - Document::Ptr doc = mm->document(source); + QVERIFY(CppModelManager::snapshot().contains(source)); + Document::Ptr doc = CppModelManager::document(source); QVERIFY(!doc.isNull()); CPlusPlus::Namespace *ns = doc->globalNamespace(); QVERIFY(ns); @@ -247,7 +245,6 @@ void ModelManagerTest::testFrameworkHeaders() void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() { ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata")); @@ -268,7 +265,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() QSet<FilePath> refreshedFiles = helper.updateProjectInfo(pi); QCOMPARE(refreshedFiles.size(), 1); QVERIFY(refreshedFiles.contains(testCpp)); - CPlusPlus::Snapshot snapshot = mm->snapshot(); + CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); QVERIFY(snapshot.contains(testHeader)); QVERIFY(snapshot.contains(testCpp)); @@ -287,7 +284,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() QCOMPARE(refreshedFiles.size(), 1); QVERIFY(refreshedFiles.contains(testCpp)); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); QVERIFY(snapshot.contains(testHeader)); QVERIFY(snapshot.contains(testCpp)); @@ -304,7 +301,6 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() void ModelManagerTest::testRefreshSeveralTimes() { ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata_refresh")); @@ -323,7 +319,7 @@ void ModelManagerTest::testRefreshSeveralTimes() }; const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); - mm->updateProjectInfo(pi); + CppModelManager::updateProjectInfo(pi); CPlusPlus::Snapshot snapshot; QSet<FilePath> refreshedFiles; @@ -344,7 +340,7 @@ void ModelManagerTest::testRefreshSeveralTimes() QVERIFY(refreshedFiles.contains(testHeader2)); QVERIFY(refreshedFiles.contains(testCpp)); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); QVERIFY(snapshot.contains(testHeader1)); QVERIFY(snapshot.contains(testHeader2)); QVERIFY(snapshot.contains(testCpp)); @@ -366,7 +362,6 @@ void ModelManagerTest::testRefreshSeveralTimes() void ModelManagerTest::testRefreshTestForChanges() { ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata_refresh")); const FilePath testCpp = testDataDir.filePath("source.cpp"); @@ -381,7 +376,7 @@ void ModelManagerTest::testRefreshTestForChanges() // Reindexing triggers a reparsing thread helper.resetRefreshedSourceFiles(); - QFuture<void> firstFuture = mm->updateProjectInfo(pi); + QFuture<void> firstFuture = CppModelManager::updateProjectInfo(pi); QVERIFY(firstFuture.isStarted() || firstFuture.isRunning()); firstFuture.waitForFinished(); const QSet<FilePath> refreshedFiles = helper.waitForRefreshedSourceFiles(); @@ -389,7 +384,7 @@ void ModelManagerTest::testRefreshTestForChanges() QVERIFY(refreshedFiles.contains(testCpp)); // No reindexing since nothing has changed - QFuture<void> subsequentFuture = mm->updateProjectInfo(pi); + QFuture<void> subsequentFuture = CppModelManager::updateProjectInfo(pi); QVERIFY(subsequentFuture.isCanceled() && subsequentFuture.isFinished()); } @@ -398,7 +393,6 @@ void ModelManagerTest::testRefreshTestForChanges() void ModelManagerTest::testRefreshAddedAndPurgeRemoved() { ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata_refresh")); @@ -424,7 +418,7 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved() QVERIFY(refreshedFiles.contains(testHeader1)); QVERIFY(refreshedFiles.contains(testCpp)); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); QVERIFY(snapshot.contains(testHeader1)); QVERIFY(snapshot.contains(testCpp)); @@ -440,7 +434,7 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved() QCOMPARE(refreshedFiles.size(), 1); QVERIFY(refreshedFiles.contains(testHeader2)); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); QVERIFY(snapshot.contains(testHeader2)); QVERIFY(snapshot.contains(testCpp)); // The removed project file is not anymore in the snapshot @@ -461,7 +455,6 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir); ModelManagerTestHelper helper; - CppModelManager *mm = CppModelManager::instance(); const auto project = helper.createProject(_("test_modelmanager_refresh_timeStampModified"), FilePath::fromString("blubb.pro")); @@ -480,7 +473,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() refreshedFiles = helper.updateProjectInfo(pi); QCOMPARE(refreshedFiles.size(), initialProjectFilePaths.size()); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); for (const FilePath &file : initialProjectFilePaths) { QVERIFY(refreshedFiles.contains(file)); QVERIFY(snapshot.contains(file)); @@ -509,7 +502,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() refreshedFiles = helper.updateProjectInfo(pi); QCOMPARE(refreshedFiles.size(), finalProjectFilePaths.size()); - snapshot = mm->snapshot(); + snapshot = CppModelManager::snapshot(); for (const FilePath &file : finalProjectFilePaths) { QVERIFY(refreshedFiles.contains(file)); QVERIFY(snapshot.contains(file)); @@ -550,7 +543,6 @@ void ModelManagerTest::testSnapshotAfterTwoProjects() ModelManagerTestHelper helper; ProjectCreator project1(&helper); ProjectCreator project2(&helper); - CppModelManager *mm = CppModelManager::instance(); // Project 1 project1.create(_("test_modelmanager_snapshot_after_two_projects.1"), @@ -559,10 +551,10 @@ void ModelManagerTest::testSnapshotAfterTwoProjects() refreshedFiles = helper.updateProjectInfo(project1.projectInfo); QCOMPARE(refreshedFiles, Utils::toSet(project1.projectFiles)); - const int snapshotSizeAfterProject1 = mm->snapshot().size(); + const int snapshotSizeAfterProject1 = CppModelManager::snapshot().size(); for (const FilePath &file : std::as_const(project1.projectFiles)) - QVERIFY(mm->snapshot().contains(file)); + QVERIFY(CppModelManager::snapshot().contains(file)); // Project 2 project2.create(_("test_modelmanager_snapshot_after_two_projects.2"), @@ -572,14 +564,14 @@ void ModelManagerTest::testSnapshotAfterTwoProjects() refreshedFiles = helper.updateProjectInfo(project2.projectInfo); QCOMPARE(refreshedFiles, Utils::toSet(project2.projectFiles)); - const int snapshotSizeAfterProject2 = mm->snapshot().size(); + const int snapshotSizeAfterProject2 = CppModelManager::snapshot().size(); QVERIFY(snapshotSizeAfterProject2 > snapshotSizeAfterProject1); QVERIFY(snapshotSizeAfterProject2 >= snapshotSizeAfterProject1 + project2.projectFiles.size()); for (const FilePath &file : std::as_const(project1.projectFiles)) - QVERIFY(mm->snapshot().contains(file)); + QVERIFY(CppModelManager::snapshot().contains(file)); for (const FilePath &file : std::as_const(project2.projectFiles)) - QVERIFY(mm->snapshot().contains(file)); + QVERIFY(CppModelManager::snapshot().contains(file)); } /// Check: (1) For a project with a *.ui file an AbstractEditorSupport object @@ -601,10 +593,9 @@ void ModelManagerTest::testExtraeditorsupportUiFiles() // Check working copy. // An AbstractEditorSupport object should have been added for the ui_* file. - CppModelManager *mm = CppModelManager::instance(); - WorkingCopy workingCopy = mm->workingCopy(); + WorkingCopy workingCopy = CppModelManager::workingCopy(); - QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h" + QCOMPARE(workingCopy.size(), 2); // CppModelManager::configurationFileName() and "ui_*.h" QStringList fileNamesInWorkinCopy; const WorkingCopy::Table &elements = workingCopy.elements(); @@ -613,16 +604,16 @@ void ModelManagerTest::testExtraeditorsupportUiFiles() fileNamesInWorkinCopy.sort(); const QString expectedUiHeaderFileName = _("ui_mainwindow.h"); - QCOMPARE(fileNamesInWorkinCopy.at(0), mm->configurationFileName().toString()); + QCOMPARE(fileNamesInWorkinCopy.at(0), CppModelManager::configurationFileName().toString()); QCOMPARE(fileNamesInWorkinCopy.at(1), expectedUiHeaderFileName); // Check CppSourceProcessor / includes. // The CppSourceProcessor is expected to find the ui_* file in the working copy. const FilePath fileIncludingTheUiFile = temporaryDir.absolutePath("mainwindow.cpp"); - while (!mm->snapshot().document(fileIncludingTheUiFile)) + while (!CppModelManager::snapshot().document(fileIncludingTheUiFile)) QCoreApplication::processEvents(); - const CPlusPlus::Snapshot snapshot = mm->snapshot(); + const CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); const Document::Ptr document = snapshot.document(fileIncludingTheUiFile); QVERIFY(document); const FilePaths includedFiles = document->includedFiles(); @@ -640,7 +631,6 @@ void ModelManagerTest::testGcIfLastCppeditorClosed() MyTestDataDir testDataDirectory(_("testdata_guiproject1")); const FilePath file = testDataDirectory.filePath("main.cpp"); - CppModelManager *mm = CppModelManager::instance(); helper.resetRefreshedSourceFiles(); // Open a file in the editor @@ -648,8 +638,8 @@ void ModelManagerTest::testGcIfLastCppeditorClosed() Core::IEditor *editor = Core::EditorManager::openEditor(file); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(mm->isCppEditor(editor)); - QVERIFY(mm->workingCopy().get(file)); + QVERIFY(CppModelManager::isCppEditor(editor)); + QVERIFY(CppModelManager::workingCopy().get(file)); // Wait until the file is refreshed helper.waitForRefreshedSourceFiles(); @@ -659,8 +649,8 @@ void ModelManagerTest::testGcIfLastCppeditorClosed() helper.waitForFinishedGc(); // Check: File is removed from the snapshpt - QVERIFY(!mm->workingCopy().get(file)); - QVERIFY(!mm->snapshot().contains(file)); + QVERIFY(!CppModelManager::workingCopy().get(file)); + QVERIFY(!CppModelManager::snapshot().contains(file)); } /// Check: Files that are open in the editor are not garbage collected. @@ -671,7 +661,6 @@ void ModelManagerTest::testDontGcOpenedFiles() MyTestDataDir testDataDirectory(_("testdata_guiproject1")); const FilePath file = testDataDirectory.filePath("main.cpp"); - CppModelManager *mm = CppModelManager::instance(); helper.resetRefreshedSourceFiles(); // Open a file in the editor @@ -679,24 +668,24 @@ void ModelManagerTest::testDontGcOpenedFiles() Core::IEditor *editor = Core::EditorManager::openEditor(file); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(mm->isCppEditor(editor)); + QVERIFY(CppModelManager::isCppEditor(editor)); // Wait until the file is refreshed and check whether it is in the working copy helper.waitForRefreshedSourceFiles(); - QVERIFY(mm->workingCopy().get(file)); + QVERIFY(CppModelManager::workingCopy().get(file)); // Run the garbage collector - mm->GC(); + CppModelManager::GC(); // Check: File is still there - QVERIFY(mm->workingCopy().get(file)); - QVERIFY(mm->snapshot().contains(file)); + QVERIFY(CppModelManager::workingCopy().get(file)); + QVERIFY(CppModelManager::snapshot().contains(file)); // Close editor Core::EditorManager::closeDocuments({editor->document()}); helper.waitForFinishedGc(); - QVERIFY(mm->snapshot().isEmpty()); + QVERIFY(CppModelManager::snapshot().isEmpty()); } namespace { @@ -735,8 +724,6 @@ void ModelManagerTest::testDefinesPerProject() const FilePath main2File = testDataDirectory.filePath("main2.cpp"); const FilePath header = testDataDirectory.filePath("header.h"); - CppModelManager *mm = CppModelManager::instance(); - const auto project = helper.createProject(_("test_modelmanager_defines_per_project"), Utils::FilePath::fromString("blubb.pro")); @@ -758,7 +745,7 @@ void ModelManagerTest::testDefinesPerProject() const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2}); helper.updateProjectInfo(pi); - QCOMPARE(mm->snapshot().size(), 4); + QCOMPARE(CppModelManager::snapshot().size(), 4); // Open a file in the editor QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); @@ -778,9 +765,9 @@ void ModelManagerTest::testDefinesPerProject() EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(mm->isCppEditor(editor)); + QVERIFY(CppModelManager::isCppEditor(editor)); - Document::Ptr doc = mm->document(i.filePath); + Document::Ptr doc = CppModelManager::document(i.filePath); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -796,8 +783,6 @@ void ModelManagerTest::testPrecompiledHeaders() const FilePath pch1File = testDataDirectory.filePath("pch1.h"); const FilePath pch2File = testDataDirectory.filePath("pch2.h"); - CppModelManager *mm = CppModelManager::instance(); - const auto project = helper.createProject(_("test_modelmanager_defines_per_project_pch"), Utils::FilePath::fromString("blubb.pro")); @@ -820,7 +805,7 @@ void ModelManagerTest::testPrecompiledHeaders() const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2}); helper.updateProjectInfo(pi); - QCOMPARE(mm->snapshot().size(), 4); + QCOMPARE(CppModelManager::snapshot().size(), 4); // Open a file in the editor QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); @@ -842,18 +827,17 @@ void ModelManagerTest::testPrecompiledHeaders() EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(mm->isCppEditor(editor)); + QVERIFY(CppModelManager::isCppEditor(editor)); auto parser = BuiltinEditorDocumentParser::get(filePath); QVERIFY(parser); BaseEditorDocumentParser::Configuration config = parser->configuration(); config.usePrecompiledHeaders = true; parser->setConfiguration(config); - parser->update({CppModelManager::instance()->workingCopy(), nullptr, - Utils::Language::Cxx, false}); + parser->update({CppModelManager::workingCopy(), nullptr,Utils::Language::Cxx, false}); // Check if defines from pch are considered - Document::Ptr document = mm->document(filePath); + Document::Ptr document = CppModelManager::document(filePath); QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName); // Check if declarations from pch are considered @@ -876,8 +860,6 @@ void ModelManagerTest::testDefinesPerEditor() const FilePath main2File = testDataDirectory.filePath("main2.cpp"); const FilePath header = testDataDirectory.filePath("header.h"); - CppModelManager *mm = CppModelManager::instance(); - const auto project = helper.createProject(_("test_modelmanager_defines_per_editor"), Utils::FilePath::fromString("blubb.pro")); @@ -896,7 +878,7 @@ void ModelManagerTest::testDefinesPerEditor() const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2}); helper.updateProjectInfo(pi); - QCOMPARE(mm->snapshot().size(), 4); + QCOMPARE(CppModelManager::snapshot().size(), 4); // Open a file in the editor QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); @@ -916,17 +898,16 @@ void ModelManagerTest::testDefinesPerEditor() EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(mm->isCppEditor(editor)); + QVERIFY(CppModelManager::isCppEditor(editor)); const FilePath filePath = editor->document()->filePath(); const auto parser = BaseEditorDocumentParser::get(filePath); BaseEditorDocumentParser::Configuration config = parser->configuration(); config.editorDefines = editorDefines.toUtf8(); parser->setConfiguration(config); - parser->update({CppModelManager::instance()->workingCopy(), nullptr, - Utils::Language::Cxx, false}); + parser->update({CppModelManager::workingCopy(), nullptr, Utils::Language::Cxx, false}); - Document::Ptr doc = mm->document(main1File); + Document::Ptr doc = CppModelManager::document(main1File); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -986,7 +967,7 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate() void ModelManagerTest::testRenameIncludes() { struct ModelManagerGCHelper { - ~ModelManagerGCHelper() { CppModelManager::instance()->GC(); } + ~ModelManagerGCHelper() { CppModelManager::GC(); } } GCHelper; Q_UNUSED(GCHelper) // do not warn about being unused @@ -997,7 +978,6 @@ void ModelManagerTest::testRenameIncludes() const QStringList fileNames = {"foo.h", "foo.cpp", "main.cpp"}; const FilePath oldHeader = FilePath::fromString(workingDir.filePath("foo.h")); const FilePath newHeader = FilePath::fromString(workingDir.filePath("bar.h")); - CppModelManager *modelManager = CppModelManager::instance(); const MyTestDataDir testDir(_("testdata_project1")); // Copy test files to a temporary directory @@ -1012,9 +992,9 @@ void ModelManagerTest::testRenameIncludes() } // Update the c++ model manager and check for the old includes - modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + CppModelManager::updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); - CPlusPlus::Snapshot snapshot = modelManager->snapshot(); + CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); for (const FilePath &sourceFile : std::as_const(sourceFiles)) { QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{oldHeader}); } @@ -1025,9 +1005,9 @@ void ModelManagerTest::testRenameIncludes() Core::HandleIncludeGuards::Yes)); // Update the c++ model manager again and check for the new includes - modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + CppModelManager::updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); - snapshot = modelManager->snapshot(); + snapshot = CppModelManager::snapshot(); for (const FilePath &sourceFile : std::as_const(sourceFiles)) { QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{newHeader}); } @@ -1036,7 +1016,7 @@ void ModelManagerTest::testRenameIncludes() void ModelManagerTest::testRenameIncludesInEditor() { struct ModelManagerGCHelper { - ~ModelManagerGCHelper() { CppModelManager::instance()->GC(); } + ~ModelManagerGCHelper() { CppModelManager::GC(); } } GCHelper; Q_UNUSED(GCHelper) // do not warn about being unused @@ -1054,7 +1034,6 @@ void ModelManagerTest::testRenameIncludesInEditor() const QString headerWithMalformedGuard(workingDir.filePath(_("baz3.h"))); const QString renamedHeaderWithMalformedGuard(workingDir.filePath(_("foobar5000.h"))); const FilePath mainFile = FilePath::fromString(workingDir.filePath("main.cpp")); - CppModelManager *modelManager = CppModelManager::instance(); const MyTestDataDir testDir(_("testdata_project1")); ModelManagerTestHelper helper; @@ -1072,9 +1051,9 @@ void ModelManagerTest::testRenameIncludesInEditor() } // Update the c++ model manager and check for the old includes - modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + CppModelManager::updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); - CPlusPlus::Snapshot snapshot = modelManager->snapshot(); + CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); for (const FilePath &sourceFile : std::as_const(sourceFiles)) { QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{headerWithPragmaOnce}); @@ -1087,8 +1066,8 @@ void ModelManagerTest::testRenameIncludesInEditor() EditorCloser editorCloser(editor); const QScopeGuard cleanup([] { Core::DocumentManager::saveAllModifiedDocumentsSilently(); }); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); - QVERIFY(modelManager->isCppEditor(editor)); - QVERIFY(modelManager->workingCopy().get(mainFile)); + QVERIFY(CppModelManager::isCppEditor(editor)); + QVERIFY(CppModelManager::workingCopy().get(mainFile)); // Test the renaming of a header file where a pragma once guard is present QVERIFY(Core::FileUtils::renameFile(headerWithPragmaOnce, @@ -1150,9 +1129,9 @@ void ModelManagerTest::testRenameIncludesInEditor() // Update the c++ model manager again and check for the new includes TestCase::waitForProcessedEditorDocument(mainFile); - modelManager->updateSourceFiles(sourceFiles).waitForFinished(); + CppModelManager::updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); - snapshot = modelManager->snapshot(); + snapshot = CppModelManager::snapshot(); for (const FilePath &sourceFile : std::as_const(sourceFiles)) { QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{renamedHeaderWithPragmaOnce}); @@ -1170,35 +1149,34 @@ void ModelManagerTest::testDocumentsAndRevisions() const QSet<FilePath> filesToIndex = {filePath1,filePath2}; QVERIFY(TestCase::parseFiles(filesToIndex)); - CppModelManager *modelManager = CppModelManager::instance(); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 1U); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath1), 1U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath2), 1U); // Open editor for file 1 TextEditor::BaseTextEditor *editor1; QVERIFY(helper.openCppEditor(filePath1, &editor1)); helper.closeEditorAtEndOfTestCase(editor1); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath1), 2U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath2), 1U); // Index again QVERIFY(TestCase::parseFiles(filesToIndex)); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 2U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath1), 3U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath2), 2U); // Open editor for file 2 TextEditor::BaseTextEditor *editor2; QVERIFY(helper.openCppEditor(filePath2, &editor2)); helper.closeEditorAtEndOfTestCase(editor2); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath1), 3U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath2), 3U); // Index again QVERIFY(TestCase::parseFiles(filesToIndex)); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 4U); - VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 4U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath1), 4U); + VERIFY_DOCUMENT_REVISION(CppModelManager::document(filePath2), 4U); } } // CppEditor::Internal diff --git a/src/plugins/cppeditor/cppprojectupdater.cpp b/src/plugins/cppeditor/cppprojectupdater.cpp index e4b57c90c5a..4df4b5de4ae 100644 --- a/src/plugins/cppeditor/cppprojectupdater.cpp +++ b/src/plugins/cppeditor/cppprojectupdater.cpp @@ -81,8 +81,7 @@ void CppProjectUpdater::update(const ProjectUpdateInfo &projectUpdateInfo, } } GeneratedCodeModelSupport::update(extraCompilers); - auto updateFuture = CppModelManager::instance()->updateProjectInfo(storage->projectInfo, - compilerFiles); + auto updateFuture = CppModelManager::updateProjectInfo(storage->projectInfo, compilerFiles); m_futureSynchronizer.addFuture(updateFuture); m_taskTree.release()->deleteLater(); }; diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 048ec9915e2..09bc7d05d45 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -95,8 +95,8 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc // Set appropriate include paths if (!headerPaths.isEmpty()) { m_restoreHeaderPaths = true; - m_headerPathsToRestore = m_modelManager->headerPaths(); - m_modelManager->setHeaderPaths(headerPaths); + m_headerPathsToRestore = CppModelManager::headerPaths(); + CppModelManager::setHeaderPaths(headerPaths); } // Update Code Model @@ -154,7 +154,7 @@ BaseQuickFixTestCase::~BaseQuickFixTestCase() // Restore include paths if (m_restoreHeaderPaths) - m_modelManager->setHeaderPaths(m_headerPathsToRestore); + CppModelManager::setHeaderPaths(m_headerPathsToRestore); // Remove created files from file system for (const TestDocumentPtr &testDocument : std::as_const(m_testDocuments)) diff --git a/src/plugins/cppeditor/cppquickfixassistant.cpp b/src/plugins/cppeditor/cppquickfixassistant.cpp index 19514387d71..9202e639a28 100644 --- a/src/plugins/cppeditor/cppquickfixassistant.cpp +++ b/src/plugins/cppeditor/cppquickfixassistant.cpp @@ -51,7 +51,7 @@ CppQuickFixInterface::CppQuickFixInterface(CppEditorWidget *editor, AssistReason : AssistInterface(editor->textCursor(), editor->textDocument()->filePath(), reason) , m_editor(editor) , m_semanticInfo(editor->semanticInfo()) - , m_snapshot(CppModelManager::instance()->snapshot()) + , m_snapshot(CppModelManager::snapshot()) , m_currentFile(CppRefactoringChanges::file(editor, m_semanticInfo.doc)) , m_context(m_semanticInfo.doc, m_snapshot) { diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 93596f5ec43..9786083f6f8 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1899,10 +1899,9 @@ ProjectExplorer::HeaderPaths relevantHeaderPaths(const QString &filePath) { ProjectExplorer::HeaderPaths headerPaths; - CppModelManager *modelManager = CppModelManager::instance(); - const QList<ProjectPart::ConstPtr> projectParts = modelManager->projectPart(filePath); + const QList<ProjectPart::ConstPtr> projectParts = CppModelManager::projectPart(filePath); if (projectParts.isEmpty()) { // Not part of any project, better use all include paths than none - headerPaths += modelManager->headerPaths(); + headerPaths += CppModelManager::headerPaths(); } else { for (const ProjectPart::ConstPtr &part : projectParts) headerPaths += part->headerPaths; @@ -1997,7 +1996,7 @@ QList<IndexItem::Ptr> matchName(const Name *name, QString *className) QString simpleName; QList<IndexItem::Ptr> matches; - CppLocatorData *locatorData = CppModelManager::instance()->locatorData(); + CppLocatorData *locatorData = CppModelManager::locatorData(); const Overview oo; if (const QualifiedNameId *qualifiedName = name->asQualifiedNameId()) { const Name *name = qualifiedName->name(); diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp index dcbb53f3b11..98eaaa8febb 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.cpp +++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp @@ -217,8 +217,7 @@ void CppRefactoringFile::fileChanged() CppRefactoringChangesData::CppRefactoringChangesData(const Snapshot &snapshot) : m_snapshot(snapshot) - , m_modelManager(CppModelManager::instance()) - , m_workingCopy(m_modelManager->workingCopy()) + , m_workingCopy(CppModelManager::workingCopy()) {} void CppRefactoringChangesData::indentSelection(const QTextCursor &selection, @@ -249,7 +248,7 @@ void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection, void CppRefactoringChangesData::fileChanged(const FilePath &filePath) { - m_modelManager->updateSourceFiles({filePath}); + CppModelManager::updateSourceFiles({filePath}); } } // CppEditor diff --git a/src/plugins/cppeditor/cpprefactoringchanges.h b/src/plugins/cppeditor/cpprefactoringchanges.h index 4a79da2f73e..5dca8a9ca51 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.h +++ b/src/plugins/cppeditor/cpprefactoringchanges.h @@ -76,7 +76,6 @@ public: void fileChanged(const Utils::FilePath &filePath) override; CPlusPlus::Snapshot m_snapshot; - CppModelManager *m_modelManager; WorkingCopy m_workingCopy; }; diff --git a/src/plugins/cppeditor/cppsemanticinfoupdater.cpp b/src/plugins/cppeditor/cppsemanticinfoupdater.cpp index 4fc9dd7c66b..4edc7dac13a 100644 --- a/src/plugins/cppeditor/cppsemanticinfoupdater.cpp +++ b/src/plugins/cppeditor/cppsemanticinfoupdater.cpp @@ -178,7 +178,7 @@ void SemanticInfoUpdater::updateDetached(const SemanticInfo::Source &source) return; } - d->m_future = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(), + d->m_future = Utils::asyncRun(CppModelManager::sharedThreadPool(), &SemanticInfoUpdaterPrivate::update_helper, d.data(), source); } diff --git a/src/plugins/cppeditor/cppsourceprocessor_test.cpp b/src/plugins/cppeditor/cppsourceprocessor_test.cpp index b6ec4a4095e..23c5e111f63 100644 --- a/src/plugins/cppeditor/cppsourceprocessor_test.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor_test.cpp @@ -34,7 +34,6 @@ class SourcePreprocessor { public: SourcePreprocessor() - : m_cmm(CppModelManager::instance()) { cleanUp(); } @@ -47,7 +46,7 @@ public: TestIncludePaths::directoryOfTestFile())}); sourceProcessor->run(filePath); - Document::Ptr document = m_cmm->document(filePath); + Document::Ptr document = CppModelManager::document(filePath); return document; } @@ -59,12 +58,9 @@ public: private: void cleanUp() { - m_cmm->GC(); - QVERIFY(m_cmm->snapshot().isEmpty()); + CppModelManager::GC(); + QVERIFY(CppModelManager::snapshot().isEmpty()); } - -private: - CppModelManager *m_cmm; }; /// Check: Resolved and unresolved includes are properly tracked. diff --git a/src/plugins/cppeditor/cpptoolsjsextension.cpp b/src/plugins/cppeditor/cpptoolsjsextension.cpp index 0818af0acb4..6e3c1f1a7dc 100644 --- a/src/plugins/cppeditor/cpptoolsjsextension.cpp +++ b/src/plugins/cppeditor/cpptoolsjsextension.cpp @@ -151,8 +151,8 @@ bool CppToolsJsExtension::hasQObjectParent(const QString &klassName) const const IndexItem::Ptr item = candidates.first(); // Find class in AST. - const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); - const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy(); + const CPlusPlus::Snapshot snapshot = CppModelManager::snapshot(); + const WorkingCopy workingCopy = CppModelManager::workingCopy(); std::optional<QByteArray> source = workingCopy.source(item->filePath()); if (!source) { const Utils::expected_str<QByteArray> contents = item->filePath().fileContents(); diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 810f66db49c..63949229abe 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -149,15 +149,15 @@ VerifyCleanCppModelManager::~VerifyCleanCppModelManager() { bool VerifyCleanCppModelManager::isClean(bool testOnlyForCleanedProjects) { - CppModelManager *mm = CppModelManager::instance(); - RETURN_FALSE_IF_NOT(mm->projectInfos().isEmpty()); - RETURN_FALSE_IF_NOT(mm->headerPaths().isEmpty()); - RETURN_FALSE_IF_NOT(mm->definedMacros().isEmpty()); - RETURN_FALSE_IF_NOT(mm->projectFiles().isEmpty()); + RETURN_FALSE_IF_NOT(CppModelManager::projectInfos().isEmpty()); + RETURN_FALSE_IF_NOT(CppModelManager::headerPaths().isEmpty()); + RETURN_FALSE_IF_NOT(CppModelManager::definedMacros().isEmpty()); + RETURN_FALSE_IF_NOT(CppModelManager::projectFiles().isEmpty()); if (!testOnlyForCleanedProjects) { - RETURN_FALSE_IF_NOT(mm->snapshot().isEmpty()); - RETURN_FALSE_IF_NOT(mm->workingCopy().size() == 1); - RETURN_FALSE_IF_NOT(mm->workingCopy().get(mm->configurationFileName())); + RETURN_FALSE_IF_NOT(CppModelManager::snapshot().isEmpty()); + RETURN_FALSE_IF_NOT(CppModelManager::workingCopy().size() == 1); + RETURN_FALSE_IF_NOT(CppModelManager::workingCopy() + .get(CppModelManager::configurationFileName())); } return true; } @@ -170,9 +170,9 @@ namespace CppEditor::Tests { static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEditor *> &editors) { - CppModelManager::instance()->enableGarbageCollector(false); + CppModelManager::enableGarbageCollector(false); const bool closeEditorsSucceeded = Core::EditorManager::closeEditors(editors, false); - CppModelManager::instance()->enableGarbageCollector(true); + CppModelManager::enableGarbageCollector(true); return closeEditorsSucceeded; } @@ -188,8 +188,7 @@ static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<Fil } TestCase::TestCase(bool runGarbageCollector) - : m_modelManager(CppModelManager::instance()) - , m_succeededSoFar(false) + : m_succeededSoFar(false) , m_runGarbageCollector(runGarbageCollector) { if (m_runGarbageCollector) @@ -239,12 +238,12 @@ bool TestCase::openCppEditor(const FilePath &filePath, TextEditor::BaseTextEdito CPlusPlus::Snapshot TestCase::globalSnapshot() { - return CppModelManager::instance()->snapshot(); + return CppModelManager::snapshot(); } bool TestCase::garbageCollectGlobalSnapshot() { - CppModelManager::instance()->GC(); + CppModelManager::GC(); return globalSnapshot().isEmpty(); } @@ -269,7 +268,7 @@ static bool waitForProcessedEditorDocument_internal(CppEditorDocumentHandle *edi bool TestCase::waitForProcessedEditorDocument(const FilePath &filePath, int timeOutInMs) { - auto *editorDocument = CppModelManager::instance()->cppEditorDocument(filePath); + auto *editorDocument = CppModelManager::cppEditorDocument(filePath); return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs); } @@ -282,7 +281,7 @@ CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEdito bool TestCase::parseFiles(const QSet<FilePath> &filePaths) { - CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); + CppModelManager::updateSourceFiles(filePaths).waitForFinished(); QCoreApplication::processEvents(); const CPlusPlus::Snapshot snapshot = globalSnapshot(); if (snapshot.isEmpty()) { @@ -349,7 +348,7 @@ bool TestCase::waitUntilProjectIsFullyOpened(Project *project, int timeOutInMs) [project]() { return ProjectManager::startupBuildSystem() && !ProjectManager::startupBuildSystem()->isParsing() - && CppModelManager::instance()->projectInfo(project); + && CppModelManager::projectInfo(project); }, timeOutInMs); } @@ -405,7 +404,7 @@ ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile, if (TestCase::waitUntilProjectIsFullyOpened(project)) { m_openProjects.append(project); - return CppModelManager::instance()->projectInfo(project); + return CppModelManager::projectInfo(project); } return {}; diff --git a/src/plugins/cppeditor/cpptoolstestcase.h b/src/plugins/cppeditor/cpptoolstestcase.h index 84cf0f088a8..13548630e65 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.h +++ b/src/plugins/cppeditor/cpptoolstestcase.h @@ -32,7 +32,6 @@ class IAssistProposal; namespace CppEditor { class CppEditorWidget; -class CppModelManager; namespace Internal::Tests { @@ -152,7 +151,6 @@ public: static bool writeFile(const Utils::FilePath &filePath, const QByteArray &contents); protected: - CppModelManager *m_modelManager; bool m_succeededSoFar; private: diff --git a/src/plugins/cppeditor/cppuseselections_test.cpp b/src/plugins/cppeditor/cppuseselections_test.cpp index c9c56752844..2e5a0f2a0d8 100644 --- a/src/plugins/cppeditor/cppuseselections_test.cpp +++ b/src/plugins/cppeditor/cppuseselections_test.cpp @@ -81,7 +81,7 @@ UseSelectionsTestCase::UseSelectionsTestCase(CppTestDocument &testFile, bool hasTimedOut; const SelectionList selections = waitForUseSelections(&hasTimedOut); - const bool clangCodeModel = CppModelManager::instance()->isClangCodeModelActive(); + const bool clangCodeModel = CppModelManager::isClangCodeModelActive(); if (clangCodeModel) { QEXPECT_FAIL("local use as macro argument - argument eaten", "fails with CCM, find out why", Abort); diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 2ad6b6b4ef2..75dd0719a5c 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -110,7 +110,7 @@ static bool waitUntilAProjectIsLoaded(int timeOutInMs = 30000) timer.start(); while (timer.elapsed() < timeOutInMs) { - if (!CppModelManager::instance()->projectInfos().isEmpty()) + if (!CppModelManager::projectInfos().isEmpty()) return true; QCoreApplication::processEvents(); @@ -132,7 +132,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti // Collect files to process FilePaths filesToOpen; QList<QPointer<ProjectExplorer::Project> > projects; - const QList<ProjectInfo::ConstPtr> projectInfos = m_modelManager->projectInfos(); + const QList<ProjectInfo::ConstPtr> projectInfos = CppModelManager::projectInfos(); for (const ProjectInfo::ConstPtr &info : projectInfos) { qDebug() << "Project" << info->projectFilePath().toUserOutput() << "- files to process:" @@ -162,8 +162,8 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti QVERIFY(openCppEditor(filePath, &editor, &editorWidget)); QCOMPARE(DocumentModel::openedDocuments().size(), 1); - QVERIFY(m_modelManager->isCppEditor(editor)); - QVERIFY(m_modelManager->workingCopy().get(filePath)); + QVERIFY(CppModelManager::isCppEditor(editor)); + QVERIFY(CppModelManager::workingCopy().get(filePath)); // Rehighlight waitForRehighlightedSemanticDocument(editorWidget); diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 31d69f7363d..0432985eafb 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -331,7 +331,7 @@ F2TestCase::F2TestCase(CppEditorAction action, switch (action) { case FollowSymbolUnderCursorAction: { CppEditorWidget *widget = initialTestFile->m_editorWidget; - if (CppModelManager::instance()->isClangCodeModelActive()) { + if (CppModelManager::isClangCodeModelActive()) { if (curTestName == "testFollowSymbolQTCREATORBUG7903") QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1()); widget->enableTestMode(); diff --git a/src/plugins/cppeditor/generatedcodemodelsupport.cpp b/src/plugins/cppeditor/generatedcodemodelsupport.cpp index 22a9b2735eb..63c9de66b91 100644 --- a/src/plugins/cppeditor/generatedcodemodelsupport.cpp +++ b/src/plugins/cppeditor/generatedcodemodelsupport.cpp @@ -49,10 +49,10 @@ private: QSet<QObject *> m_cache; }; -GeneratedCodeModelSupport::GeneratedCodeModelSupport(CppModelManager *modelmanager, - ExtraCompiler *generator, +GeneratedCodeModelSupport::GeneratedCodeModelSupport(ExtraCompiler *generator, const FilePath &generatedFile) : - AbstractEditorSupport(modelmanager, generator), m_generatedFilePath(generatedFile), + AbstractEditorSupport(generator), + m_generatedFilePath(generatedFile), m_generator(generator) { QLoggingCategory log("qtc.cppeditor.generatedcodemodelsupport", QtWarningMsg); @@ -66,8 +66,7 @@ GeneratedCodeModelSupport::GeneratedCodeModelSupport(CppModelManager *modelmanag GeneratedCodeModelSupport::~GeneratedCodeModelSupport() { - CppModelManager::instance()->emitAbstractEditorSupportRemoved( - m_generatedFilePath.toString()); + CppModelManager::emitAbstractEditorSupportRemoved(m_generatedFilePath.toString()); QLoggingCategory log("qtc.cppeditor.generatedcodemodelsupport", QtWarningMsg); qCDebug(log) << "dtor ~generatedcodemodelsupport for" << m_generatedFilePath; } @@ -99,15 +98,13 @@ void GeneratedCodeModelSupport::update(const QList<ExtraCompiler *> &generators) { static QObjectCache extraCompilerCache; - CppModelManager * const mm = CppModelManager::instance(); - for (ExtraCompiler *generator : generators) { if (extraCompilerCache.contains(generator)) continue; extraCompilerCache.insert(generator); - generator->forEachTarget([mm, generator](const FilePath &generatedFile) { - new GeneratedCodeModelSupport(mm, generator, generatedFile); + generator->forEachTarget([generator](const FilePath &generatedFile) { + new GeneratedCodeModelSupport(generator, generatedFile); }); } } diff --git a/src/plugins/cppeditor/generatedcodemodelsupport.h b/src/plugins/cppeditor/generatedcodemodelsupport.h index d37177d9910..618a837e8b2 100644 --- a/src/plugins/cppeditor/generatedcodemodelsupport.h +++ b/src/plugins/cppeditor/generatedcodemodelsupport.h @@ -15,8 +15,7 @@ class CPPEDITOR_EXPORT GeneratedCodeModelSupport : public AbstractEditorSupport Q_OBJECT public: - GeneratedCodeModelSupport(CppModelManager *modelmanager, - ProjectExplorer::ExtraCompiler *generator, + GeneratedCodeModelSupport(ProjectExplorer::ExtraCompiler *generator, const Utils::FilePath &generatedFile); ~GeneratedCodeModelSupport() override; diff --git a/src/plugins/cppeditor/includeutils.cpp b/src/plugins/cppeditor/includeutils.cpp index 1404f5bace3..c7daa4e9d8f 100644 --- a/src/plugins/cppeditor/includeutils.cpp +++ b/src/plugins/cppeditor/includeutils.cpp @@ -511,14 +511,13 @@ namespace Internal { static QList<Include> includesForSource(const FilePath &filePath) { - CppModelManager *cmm = CppModelManager::instance(); - cmm->GC(); + CppModelManager::GC(); QScopedPointer<CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor()); sourceProcessor->setHeaderPaths({ProjectExplorer::HeaderPath::makeUser( TestIncludePaths::globalIncludePath())}); sourceProcessor->run(filePath); - Document::Ptr document = cmm->document(filePath); + Document::Ptr document = CppModelManager::document(filePath); return document->resolvedIncludes(); } diff --git a/src/plugins/cppeditor/modelmanagertesthelper.cpp b/src/plugins/cppeditor/modelmanagertesthelper.cpp index a133ac7fef2..bfc3998e8ee 100644 --- a/src/plugins/cppeditor/modelmanagertesthelper.cpp +++ b/src/plugins/cppeditor/modelmanagertesthelper.cpp @@ -81,7 +81,7 @@ QSet<FilePath> ModelManagerTestHelper::updateProjectInfo( const ProjectInfo::ConstPtr &projectInfo) { resetRefreshedSourceFiles(); - CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished(); + CppModelManager::updateProjectInfo(projectInfo).waitForFinished(); QCoreApplication::processEvents(); return waitForRefreshedSourceFiles(); } diff --git a/src/plugins/cppeditor/symbolfinder.cpp b/src/plugins/cppeditor/symbolfinder.cpp index 5da95a13621..dfc36a0e8aa 100644 --- a/src/plugins/cppeditor/symbolfinder.cpp +++ b/src/plugins/cppeditor/symbolfinder.cpp @@ -476,7 +476,7 @@ void SymbolFinder::checkCacheConsistency(const FilePath &referenceFile, const Sn const QString projectPartIdForFile(const FilePath &filePath) { - const QList<ProjectPart::ConstPtr> parts = CppModelManager::instance()->projectPart(filePath); + const QList<ProjectPart::ConstPtr> parts = CppModelManager::projectPart(filePath); if (!parts.isEmpty()) return parts.first()->id(); return QString(); diff --git a/src/plugins/cppeditor/symbolsfindfilter.cpp b/src/plugins/cppeditor/symbolsfindfilter.cpp index eb6a4c81dab..bf1158c414f 100644 --- a/src/plugins/cppeditor/symbolsfindfilter.cpp +++ b/src/plugins/cppeditor/symbolsfindfilter.cpp @@ -35,9 +35,8 @@ const char SETTINGS_GROUP[] = "CppSymbols"; const char SETTINGS_SYMBOLTYPES[] = "SymbolsToSearchFor"; const char SETTINGS_SEARCHSCOPE[] = "SearchScope"; -SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager) - : m_manager(manager), - m_enabled(true), +SymbolsFindFilter::SymbolsFindFilter() + : m_enabled(true), m_symbolsToSearch(SearchSymbols::AllTypes), m_scope(SymbolSearcher::SearchProjectsOnly) { @@ -121,7 +120,7 @@ void SymbolsFindFilter::startSearch(SearchResult *search) SymbolSearcher *symbolSearcher = new SymbolSearcher(parameters, projectFileNames); connect(watcher, &QFutureWatcherBase::finished, symbolSearcher, &QObject::deleteLater); - watcher->setFuture(Utils::asyncRun(m_manager->sharedThreadPool(), + watcher->setFuture(Utils::asyncRun(CppModelManager::sharedThreadPool(), &SymbolSearcher::runSearch, symbolSearcher)); FutureProgress *progress = ProgressManager::addTask(watcher->future(), Tr::tr("Searching for Symbol"), Core::Constants::TASK_SEARCH); diff --git a/src/plugins/cppeditor/symbolsfindfilter.h b/src/plugins/cppeditor/symbolsfindfilter.h index db7d4d323ab..a308bd93074 100644 --- a/src/plugins/cppeditor/symbolsfindfilter.h +++ b/src/plugins/cppeditor/symbolsfindfilter.h @@ -18,8 +18,6 @@ namespace Core { class SearchResult; } namespace Utils { class SearchResultItem; } namespace CppEditor { -class CppModelManager; - namespace Internal { class SymbolsFindFilter : public Core::IFindFilter @@ -30,7 +28,7 @@ public: using SearchScope = SymbolSearcher::SearchScope; public: - explicit SymbolsFindFilter(CppModelManager *manager); + SymbolsFindFilter(); QString id() const override; QString displayName() const override; @@ -65,7 +63,6 @@ private: QString toolTip(Utils::FindFlags findFlags) const; void startSearch(Core::SearchResult *search); - CppModelManager *m_manager; bool m_enabled; QMap<QFutureWatcher<Utils::SearchResultItem> *, QPointer<Core::SearchResult> > m_watchers; QPointer<Core::SearchResult> m_currentSearch; diff --git a/src/plugins/debugger/analyzer/analyzerutils.cpp b/src/plugins/debugger/analyzer/analyzerutils.cpp index dc87b2ad614..a2ea231755b 100644 --- a/src/plugins/debugger/analyzer/analyzerutils.cpp +++ b/src/plugins/debugger/analyzer/analyzerutils.cpp @@ -44,7 +44,7 @@ CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor() const int pos = tc.position(); widget->convertPosition(pos, &line, &column); - const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot &snapshot = CppEditor::CppModelManager::snapshot(); CPlusPlus::Document::Ptr doc = snapshot.document(widget->textDocument()->filePath()); QTC_ASSERT(doc, return nullptr); diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index b049d76f973..ccda790fe69 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -189,7 +189,7 @@ CdbEngine::CdbEngine() : this, &CdbEngine::updateLocals); if (s->useCodeModel.value()) - m_codeModelSnapshot = CppEditor::CppModelManager::instance()->snapshot(); + m_codeModelSnapshot = CppEditor::CppModelManager::snapshot(); } void CdbEngine::init() @@ -2500,7 +2500,7 @@ void CdbEngine::insertBreakpoint(const Breakpoint &bp) BreakpointParameters response = parameters; const QString responseId = breakPointCdbId(bp); QScopedPointer<BreakpointCorrectionContext> lineCorrection( - new BreakpointCorrectionContext(m_codeModelSnapshot, CppEditor::CppModelManager::instance()->workingCopy())); + new BreakpointCorrectionContext(m_codeModelSnapshot, CppEditor::CppModelManager::workingCopy())); if (!m_autoBreakPointCorrection && parameters.type == BreakpointByFileAndLine && debuggerSettings()->cdbBreakPointCorrection.value()) { diff --git a/src/plugins/debugger/debuggerrunconfigurationaspect.cpp b/src/plugins/debugger/debuggerrunconfigurationaspect.cpp index 8811934aee4..cc1c0b855c1 100644 --- a/src/plugins/debugger/debuggerrunconfigurationaspect.cpp +++ b/src/plugins/debugger/debuggerrunconfigurationaspect.cpp @@ -154,7 +154,7 @@ bool DebuggerRunConfigurationAspect::useCppDebugger() const static bool projectHasQmlDefines(ProjectExplorer::Project *project) { - auto projectInfo = CppEditor::CppModelManager::instance()->projectInfo(project); + auto projectInfo = CppEditor::CppModelManager::projectInfo(project); if (!projectInfo) // we may have e.g. a Python project return false; return Utils::anyOf(projectInfo->projectParts(), diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index 82f1929bb89..26bb70b43fd 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -223,7 +223,7 @@ QStringList getUninitializedVariables(const Snapshot &snapshot, QString cppFunctionAt(const FilePath &filePath, int line, int column) { - const Snapshot snapshot = CppModelManager::instance()->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); if (const Document::Ptr document = snapshot.document(filePath)) return document->functionAt(line, column); @@ -240,7 +240,7 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, function->clear(); const FilePath filePath = editorWidget->textDocument()->filePath(); - const Snapshot snapshot = CppModelManager::instance()->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); const Document::Ptr document = snapshot.document(filePath); QTextCursor tc = editorWidget->textCursor(); QString expr; @@ -376,7 +376,7 @@ static void setValueAnnotationsHelper(BaseTextEditor *textEditor, TextEditorWidget *widget = textEditor->editorWidget(); TextDocument *textDocument = widget->textDocument(); const FilePath filePath = loc.fileName(); - const Snapshot snapshot = CppModelManager::instance()->snapshot(); + const Snapshot snapshot = CppModelManager::snapshot(); const Document::Ptr cppDocument = snapshot.document(filePath); if (!cppDocument) // For non-C++ documents. return; diff --git a/src/plugins/designer/codemodelhelpers.cpp b/src/plugins/designer/codemodelhelpers.cpp index 8428fd98171..f58c3f65fb7 100644 --- a/src/plugins/designer/codemodelhelpers.cpp +++ b/src/plugins/designer/codemodelhelpers.cpp @@ -105,7 +105,7 @@ bool navigateToSlot(const QString &uiFileName, *errorMessage = Tr::tr("The generated header of the form \"%1\" could not be found.\nRebuilding the project might help.").arg(uiFileName); return false; } - const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); const DocumentPtr generatedHeaderDoc = snapshot.document(generatedHeaderFile); if (!generatedHeaderDoc) { *errorMessage = Tr::tr("The generated header \"%1\" could not be found in the code model.\nRebuilding the project might help.").arg(generatedHeaderFile.toUserOutput()); diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index 58bb62258a3..fb4c1afd5d6 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -499,7 +499,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, const QString uicedName = "ui_" + fi.completeBaseName() + ".h"; // Retrieve code model snapshot restricted to project of ui file or the working copy. - Snapshot docTable = CppEditor::CppModelManager::instance()->snapshot(); + Snapshot docTable = CppEditor::CppModelManager::snapshot(); Snapshot newDocTable; const Project *uiProject = ProjectManager::projectForFile(currentUiFile); if (uiProject) { @@ -511,7 +511,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, } else { const FilePath configFileName = CppEditor::CppModelManager::configurationFileName(); const CppEditor::WorkingCopy::Table elements = - CppEditor::CppModelManager::instance()->workingCopy().elements(); + CppEditor::CppModelManager::workingCopy().elements(); for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { const Utils::FilePath &fileName = it.key(); if (fileName != configFileName) @@ -578,7 +578,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, FilePath declFilePath; if (!fun) { // add function declaration to cl - CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::instance()->workingCopy(); + CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::workingCopy(); declFilePath = declDoc->filePath(); getParsedDocument(declFilePath, workingCopy, docTable); addDeclaration(docTable, declFilePath, cl, functionNameWithParameterNames); @@ -587,8 +587,8 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, QList<Utils::FilePath> filePaths; for (auto it = docTable.begin(); it != docTable.end(); ++it) filePaths << it.key(); - workingCopy = CppEditor::CppModelManager::instance()->workingCopy(); - docTable = CppEditor::CppModelManager::instance()->snapshot(); + workingCopy = CppEditor::CppModelManager::workingCopy(); + docTable = CppEditor::CppModelManager::snapshot(); newDocTable = {}; for (const auto &file : std::as_const(filePaths)) { const Document::Ptr doc = docTable.document(file); @@ -742,7 +742,7 @@ void QtCreatorIntegration::handleSymbolRenameStage2( if (usesClangd) editorWidget->textDocument()->setFilePath(uiHeader); editorWidget->textDocument()->setPlainText(QString::fromUtf8(virtualContent)); - Snapshot snapshot = CppEditor::CppModelManager::instance()->snapshot(); + Snapshot snapshot = CppEditor::CppModelManager::snapshot(); snapshot.remove(uiHeader); snapshot.remove(editor->textDocument()->filePath()); const Document::Ptr cppDoc = snapshot.preprocessedDocument(virtualContent, uiHeader); @@ -783,8 +783,8 @@ void QtCreatorIntegration::handleSymbolRenameStage2( qCDebug(log) << "renaming with built-in code model"; snapshot.insert(cppDoc); snapshot.updateDependencyTable(); - CppEditor::CppModelManager::instance()->renameUsages(cppDoc, cursor, snapshot, - newName, callback); + CppEditor::CppModelManager::renameUsages(cppDoc, cursor, snapshot, + newName, callback); } return; } diff --git a/src/plugins/modeleditor/classviewcontroller.cpp b/src/plugins/modeleditor/classviewcontroller.cpp index 68f5a66ae2a..16dcdb92d45 100644 --- a/src/plugins/modeleditor/classviewcontroller.cpp +++ b/src/plugins/modeleditor/classviewcontroller.cpp @@ -21,8 +21,7 @@ QSet<QString> ClassViewController::findClassDeclarations(const FilePath &filePat { QSet<QString> classNames; - CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance(); - CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); + CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); // scan original file CPlusPlus::Document::Ptr document = snapshot.document(filePath); diff --git a/src/plugins/modeleditor/componentviewcontroller.cpp b/src/plugins/modeleditor/componentviewcontroller.cpp index 4071c5b0159..684d104fd9f 100644 --- a/src/plugins/modeleditor/componentviewcontroller.cpp +++ b/src/plugins/modeleditor/componentviewcontroller.cpp @@ -146,8 +146,7 @@ void UpdateIncludeDependenciesVisitor::updateFilePaths() void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *component) { - CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance(); - CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); + CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); const QStringList filePaths = findFilePathOfComponent(component); for (const QString &filePath : filePaths) { diff --git a/src/plugins/modeleditor/elementtasks.cpp b/src/plugins/modeleditor/elementtasks.cpp index 6413686f61d..3cc271214fe 100644 --- a/src/plugins/modeleditor/elementtasks.cpp +++ b/src/plugins/modeleditor/elementtasks.cpp @@ -87,7 +87,7 @@ bool ElementTasks::hasClassDefinition(const qmt::MElement *element) const if (auto klass = dynamic_cast<const qmt::MClass *>(element)) { const QString qualifiedClassName = klass->umlNamespace().isEmpty() ? klass->name() : klass->umlNamespace() + "::" + klass->name(); - auto *locatorData = CppModelManager::instance()->locatorData(); + auto *locatorData = CppModelManager::locatorData(); if (!locatorData) return false; const QList<IndexItem::Ptr> matches = locatorData->findSymbols(IndexItem::Class, @@ -118,7 +118,7 @@ void ElementTasks::openClassDefinition(const qmt::MElement *element) const QString qualifiedClassName = klass->umlNamespace().isEmpty() ? klass->name() : klass->umlNamespace() + "::" + klass->name(); - auto *locatorData = CppModelManager::instance()->locatorData(); + auto *locatorData = CppModelManager::locatorData(); if (!locatorData) return; const QList<IndexItem::Ptr> matches = locatorData->findSymbols(IndexItem::Class, diff --git a/src/plugins/modeleditor/pxnodeutilities.cpp b/src/plugins/modeleditor/pxnodeutilities.cpp index f9e8e3b034c..c9e58d5052e 100644 --- a/src/plugins/modeleditor/pxnodeutilities.cpp +++ b/src/plugins/modeleditor/pxnodeutilities.cpp @@ -216,8 +216,7 @@ qmt::MObject *PxNodeUtilities::findSameObject(const QStringList &relativeElement bool PxNodeUtilities::isProxyHeader(const QString &file) const { - CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance(); - CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); + CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(file)); if (document) { |