diff options
author | hjk <hjk@qt.io> | 2022-11-23 19:00:38 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-29 12:27:10 +0000 |
commit | 83720540a1370ef455cf129beb3c30fe565e0b68 (patch) | |
tree | 6efa64c52dc0c6cee8a733326a0f0bb00f7f8fb0 /src | |
parent | 9a32aae70678ad88a04174e0939be17326aaff11 (diff) | |
download | qt-creator-83720540a1370ef455cf129beb3c30fe565e0b68.tar.gz |
CppEditor: Convert parts of ModelManagerInterface to FilePath
Change-Id: If7503b6d6732e1735eb8d48ece6e80886d10c647
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
27 files changed, 89 insertions, 95 deletions
diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index f911869384..9d37a8c2bf 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -773,7 +773,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, const auto projectPart = !config.preferredProjectPartId.isEmpty() ? CppEditor::CppModelManager::instance()->projectPartForId( config.preferredProjectPartId) - : projectPartForFile(filePath.toString()); + : projectPartForFile(filePath); if (!projectPart) return; diff --git a/src/plugins/clangcodemodel/clangdcompletion.cpp b/src/plugins/clangcodemodel/clangdcompletion.cpp index 8b7799e868..44fc6df38e 100644 --- a/src/plugins/clangcodemodel/clangdcompletion.cpp +++ b/src/plugins/clangcodemodel/clangdcompletion.cpp @@ -426,8 +426,7 @@ IAssistProposal *CustomAssistProcessor::perform() } case CustomAssistMode::IncludePath: { HeaderPaths headerPaths; - const ProjectPart::ConstPtr projectPart - = projectPartForFile(interface()->filePath().toString()); + const ProjectPart::ConstPtr projectPart = projectPartForFile(interface()->filePath()); if (projectPart) headerPaths = projectPart->headerPaths; completions = completeInclude(m_endPos, m_completionOperator, interface(), headerPaths); diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index d4c2e94bed..3a06c31251 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -92,7 +92,7 @@ CppEditor::BaseEditorDocumentParser::Configuration ClangEditorDocumentProcessor: return parser()->configuration(); } -ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const QString &filePath) +ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const Utils::FilePath &filePath) { return qobject_cast<ClangEditorDocumentProcessor*>( CppEditor::CppModelManager::cppEditorDocumentProcessor(filePath)); diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.h b/src/plugins/clangcodemodel/clangeditordocumentprocessor.h index 85d147f190..6d2dede560 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.h +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.h @@ -29,7 +29,7 @@ public: CppEditor::BaseEditorDocumentParser::Configuration parserConfig(); public: - static ClangEditorDocumentProcessor *get(const QString &filePath); + static ClangEditorDocumentProcessor *get(const Utils::FilePath &filePath); signals: void parserConfigChanged(const Utils::FilePath &filePath, diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index bbd43fa37e..6527c630b3 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -162,7 +162,7 @@ static void updateParserConfig(ClangdClient *client) if (!client->documentOpen(editor->textDocument())) return; const Utils::FilePath filePath = editor->textDocument()->filePath(); - if (const auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) + if (const auto processor = ClangEditorDocumentProcessor::get(filePath)) client->updateParserConfig(filePath, processor->parserConfig()); } } @@ -395,7 +395,7 @@ void ClangModelManagerSupport::onCurrentEditorChanged(Core::IEditor *editor) return; const ::Utils::FilePath filePath = editor->document()->filePath(); - if (auto processor = ClangEditorDocumentProcessor::get(filePath.toString())) { + if (auto processor = ClangEditorDocumentProcessor::get(filePath)) { processor->semanticRehighlight(); if (const auto client = clientForFile(filePath)) { client->updateParserConfig(filePath, processor->parserConfig()); @@ -806,7 +806,7 @@ void ClangModelManagerSupport::onTextMarkContextMenuRequested(TextEditor::TextEd QTC_ASSERT(lineNumber >= 1, return); QTC_ASSERT(menu, return); - const auto filePath = widget->textDocument()->filePath().toString(); + const Utils::FilePath filePath = widget->textDocument()->filePath(); ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(filePath); if (processor) { const auto assistInterface = createAssistInterface(widget, lineNumber); diff --git a/src/plugins/clangcodemodel/clangtextmark.cpp b/src/plugins/clangcodemodel/clangtextmark.cpp index e5ef9f4d81..d29fef2392 100644 --- a/src/plugins/clangcodemodel/clangtextmark.cpp +++ b/src/plugins/clangcodemodel/clangtextmark.cpp @@ -43,7 +43,7 @@ namespace { Project *projectForCurrentEditor() { - const QString filePath = currentCppEditorDocumentFilePath(); + const FilePath filePath = currentCppEditorDocumentFilePath(); if (filePath.isEmpty()) return nullptr; diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 0780b1cae3..1677d148a7 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -40,7 +40,7 @@ using namespace Utils; namespace ClangCodeModel { namespace Internal { -ProjectPart::ConstPtr projectPartForFile(const QString &filePath) +ProjectPart::ConstPtr projectPartForFile(const FilePath &filePath) { if (const auto parser = CppEditor::BaseEditorDocumentParser::get(filePath)) return parser->projectPartInfo().projectPart; @@ -197,15 +197,14 @@ GenerateCompilationDbResult generateCompilationDB(QList<ProjectInfo::ConstPtr> p return GenerateCompilationDbResult(compileCommandsFile.fileName(), QString()); } -QString currentCppEditorDocumentFilePath() +FilePath currentCppEditorDocumentFilePath() { - QString filePath; + FilePath filePath; const auto currentEditor = Core::EditorManager::currentEditor(); if (currentEditor && CppEditor::CppModelManager::isCppEditor(currentEditor)) { - const auto currentDocument = currentEditor->document(); - if (currentDocument) - filePath = currentDocument->filePath().toString(); + if (const auto currentDocument = currentEditor->document()) + filePath = currentDocument->filePath(); } return filePath; diff --git a/src/plugins/clangcodemodel/clangutils.h b/src/plugins/clangcodemodel/clangutils.h index 5d75821e62..f1ccd53029 100644 --- a/src/plugins/clangcodemodel/clangutils.h +++ b/src/plugins/clangcodemodel/clangutils.h @@ -47,9 +47,9 @@ QJsonArray clangOptionsForFile(const CppEditor::ProjectFile &file, const QJsonArray &generalOptions, CppEditor::UsePrecompiledHeaders usePch, bool clStyle); -CppEditor::ProjectPart::ConstPtr projectPartForFile(const QString &filePath); +CppEditor::ProjectPart::ConstPtr projectPartForFile(const Utils::FilePath &filePath); -QString currentCppEditorDocumentFilePath(); +Utils::FilePath currentCppEditorDocumentFilePath(); QString diagnosticCategoryPrefixRemoved(const QString &text); diff --git a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp index 34c47ec569..67b25f333c 100644 --- a/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp +++ b/src/plugins/clangcodemodel/test/clangbatchfileprocessor.cpp @@ -243,13 +243,13 @@ public: static Command::Ptr parse(BatchFileLineTokenizer &arguments, const CommandContext &context); private: - QString m_documentFilePath; + Utils::FilePath m_documentFilePath; }; OpenDocumentCommand::OpenDocumentCommand(const CommandContext &context, const QString &documentFilePath) : Command(context) - , m_documentFilePath(documentFilePath) + , m_documentFilePath(Utils::FilePath::fromString(documentFilePath)) { } @@ -298,8 +298,7 @@ bool OpenDocumentCommand::run() { qCDebug(debug) << "line" << context().lineNumber << "OpenDocumentCommand" << m_documentFilePath; - const bool openEditorSucceeded = Core::EditorManager::openEditor( - Utils::FilePath::fromString(m_documentFilePath)); + const bool openEditorSucceeded = Core::EditorManager::openEditor(m_documentFilePath); QTC_ASSERT(openEditorSucceeded, return false); auto *processor = ClangEditorDocumentProcessor::get(m_documentFilePath); @@ -393,8 +392,8 @@ bool InsertTextCommand::run() TextEditor::BaseTextEditor *editor = currentTextEditor(); QTC_ASSERT(editor, return false); - const QString documentFilePath = editor->document()->filePath().toString(); - auto *processor = ClangEditorDocumentProcessor::get(documentFilePath); + const Utils::FilePath documentFilePath = editor->document()->filePath(); + auto processor = ClangEditorDocumentProcessor::get(documentFilePath); QTC_ASSERT(processor, return false); editor->insert(m_textToInsert); diff --git a/src/plugins/cppeditor/baseeditordocumentparser.cpp b/src/plugins/cppeditor/baseeditordocumentparser.cpp index 48a9605124..8451126572 100644 --- a/src/plugins/cppeditor/baseeditordocumentparser.cpp +++ b/src/plugins/cppeditor/baseeditordocumentparser.cpp @@ -87,7 +87,7 @@ ProjectPartInfo BaseEditorDocumentParser::projectPartInfo() const return state().projectPartInfo; } -BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &filePath) +BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const FilePath &filePath) { CppModelManager *cmmi = CppModelManager::instance(); if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath)) { diff --git a/src/plugins/cppeditor/baseeditordocumentparser.h b/src/plugins/cppeditor/baseeditordocumentparser.h index 98317b5c2d..59fc9d50dc 100644 --- a/src/plugins/cppeditor/baseeditordocumentparser.h +++ b/src/plugins/cppeditor/baseeditordocumentparser.h @@ -24,7 +24,7 @@ class CPPEDITOR_EXPORT BaseEditorDocumentParser : public QObject public: using Ptr = QSharedPointer<BaseEditorDocumentParser>; - static Ptr get(const QString &filePath); + static Ptr get(const Utils::FilePath &filePath); struct Configuration { bool usePrecompiledHeaders = false; diff --git a/src/plugins/cppeditor/builtineditordocumentparser.cpp b/src/plugins/cppeditor/builtineditordocumentparser.cpp index 1c5baa8481..7593684d7c 100644 --- a/src/plugins/cppeditor/builtineditordocumentparser.cpp +++ b/src/plugins/cppeditor/builtineditordocumentparser.cpp @@ -239,7 +239,7 @@ ProjectExplorer::HeaderPaths BuiltinEditorDocumentParser::headerPaths() const return extraState().headerPaths; } -BuiltinEditorDocumentParser::Ptr BuiltinEditorDocumentParser::get(const QString &filePath) +BuiltinEditorDocumentParser::Ptr BuiltinEditorDocumentParser::get(const FilePath &filePath) { if (BaseEditorDocumentParser::Ptr b = BaseEditorDocumentParser::get(filePath)) return b.objectCast<BuiltinEditorDocumentParser>(); diff --git a/src/plugins/cppeditor/builtineditordocumentparser.h b/src/plugins/cppeditor/builtineditordocumentparser.h index ab97ce0d6f..e37dcfeb86 100644 --- a/src/plugins/cppeditor/builtineditordocumentparser.h +++ b/src/plugins/cppeditor/builtineditordocumentparser.h @@ -33,7 +33,7 @@ signals: public: using Ptr = QSharedPointer<BuiltinEditorDocumentParser>; - static Ptr get(const QString &filePath); + static Ptr get(const Utils::FilePath &filePath); private: void updateImpl(const QFutureInterface<void> &future, diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 176bd9f4fc..1f2349f113 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -1515,7 +1515,7 @@ void CppCodeModelInspectorDialog::refresh() TextEditor::BaseTextEditor *editor = currentEditor(); CppEditorDocumentHandle *cppEditorDocument = nullptr; if (editor) { - const QString editorFilePath = editor->document()->filePath().toString(); + const FilePath editorFilePath = editor->document()->filePath(); cppEditorDocument = cmmi->cppEditorDocument(editorFilePath); if (auto documentProcessor = CppModelManager::cppEditorDocumentProcessor(editorFilePath)) { const Snapshot editorSnapshot = documentProcessor->snapshot(); diff --git a/src/plugins/cppeditor/cppcompletion_test.cpp b/src/plugins/cppeditor/cppcompletion_test.cpp index 7fa42a4be9..beba34ac4d 100644 --- a/src/plugins/cppeditor/cppcompletion_test.cpp +++ b/src/plugins/cppeditor/cppcompletion_test.cpp @@ -68,7 +68,7 @@ public: m_textDocument = m_editorWidget->document(); // Get Document - const Document::Ptr document = waitForFileInGlobalSnapshot(filePath.toString()); + const Document::Ptr document = waitForFileInGlobalSnapshot(filePath); QVERIFY(document); QVERIFY(document->diagnosticMessages().isEmpty()); diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 8be4155bcf..0e68454d09 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -411,7 +411,7 @@ std::unique_ptr<AssistInterface> InternalCompletionAssistProvider::createAssistI return std::make_unique<CppCompletionAssistInterface>( filePath, textEditorWidget, - BuiltinEditorDocumentParser::get(filePath.toString()), + BuiltinEditorDocumentParser::get(filePath), languageFeatures, reason, CppModelManager::instance()->workingCopy()); diff --git a/src/plugins/cppeditor/cppincludehierarchy.cpp b/src/plugins/cppeditor/cppincludehierarchy.cpp index 439f8e1fea..d9211aebed 100644 --- a/src/plugins/cppeditor/cppincludehierarchy.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy.cpp @@ -197,7 +197,7 @@ void CppIncludeHierarchyItem::fetchMore() model()->m_seen.insert(m_filePath); - const QString editorFilePath = model()->editorFilePath(); + const FilePath editorFilePath = FilePath::fromString(model()->editorFilePath()); setChildrenChecked(); if (m_subTree == InIncludes) { diff --git a/src/plugins/cppeditor/cpplocatorfilter_test.cpp b/src/plugins/cppeditor/cpplocatorfilter_test.cpp index a48d74da30..d838387c3b 100644 --- a/src/plugins/cppeditor/cpplocatorfilter_test.cpp +++ b/src/plugins/cppeditor/cpplocatorfilter_test.cpp @@ -69,14 +69,14 @@ class CppCurrentDocumentFilterTestCase , public CppEditor::Tests::TestCase { public: - CppCurrentDocumentFilterTestCase(const QString &fileName, + CppCurrentDocumentFilterTestCase(const FilePath &filePath, const ResultDataList &expectedResults, const QString &searchText = QString()) : BasicLocatorFilterTest(CppModelManager::instance()->currentDocumentFilter()) - , m_fileName(fileName) + , m_filePath(filePath) { QVERIFY(succeededSoFar()); - QVERIFY(!m_fileName.isEmpty()); + QVERIFY(!m_filePath.isEmpty()); ResultDataList results = ResultData::fromFilterEntryList(matchesFor(searchText)); if (debug) { @@ -93,10 +93,10 @@ private: QVERIFY(DocumentModel::openedDocuments().isEmpty()); QVERIFY(garbageCollectGlobalSnapshot()); - m_editor = EditorManager::openEditor(FilePath::fromString(m_fileName)); + m_editor = EditorManager::openEditor(m_filePath); QVERIFY(m_editor); - QVERIFY(waitForFileInGlobalSnapshot(m_fileName)); + QVERIFY(waitForFileInGlobalSnapshot(m_filePath)); } void doAfterLocatorRun() override @@ -109,7 +109,7 @@ private: private: IEditor *m_editor = nullptr; - const QString m_fileName; + const FilePath m_filePath; }; } // anonymous namespace @@ -301,7 +301,7 @@ void LocatorFilterTest::testLocatorFilter_data() void LocatorFilterTest::testCurrentDocumentFilter() { MyTestDataDir testDirectory("testdata_basic"); - const QString testFile = testDirectory.file("file1.cpp"); + const FilePath testFile = testDirectory.filePath("file1.cpp"); auto expectedResults = ResultDataList{ ResultData("int myVariable", ""), @@ -355,7 +355,7 @@ void LocatorFilterTest::testCurrentDocumentFilter() void LocatorFilterTest::testCurrentDocumentHighlighting() { MyTestDataDir testDirectory("testdata_basic"); - const QString testFile = testDirectory.file("file1.cpp"); + const FilePath testFile = testDirectory.filePath("file1.cpp"); const QString searchText = "pos"; const ResultDataList expectedResults{ diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 8b27d02491..cce4594704 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1111,16 +1111,16 @@ void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupp d->m_extraEditorSupports.remove(editorSupport); } -CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const QString &filePath) const +CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const FilePath &filePath) const { if (filePath.isEmpty()) return nullptr; QMutexLocker locker(&d->m_cppEditorDocumentsMutex); - return d->m_cppEditorDocuments.value(filePath, 0); + return d->m_cppEditorDocuments.value(filePath.toString(), 0); } -BaseEditorDocumentProcessor *CppModelManager::cppEditorDocumentProcessor(const QString &filePath) +BaseEditorDocumentProcessor *CppModelManager::cppEditorDocumentProcessor(const FilePath &filePath) { const auto document = instance()->cppEditorDocument(filePath); return document ? document->processor() : nullptr; @@ -1442,7 +1442,7 @@ void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const const QList<Core::IEditor *> editors = Core::EditorManager::visibleEditors(); for (Core::IEditor *editor: editors) { if (Core::IDocument *document = editor->document()) { - const QString filePath = document->filePath().toString(); + const FilePath filePath = document->filePath(); if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) { visibleCppEditorDocuments.insert(document); theCppEditorDocument->processor()->run(projectsUpdated); @@ -1455,7 +1455,7 @@ void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const = Utils::toSet(Core::DocumentModel::openedDocuments()); invisibleCppEditorDocuments.subtract(visibleCppEditorDocuments); for (Core::IDocument *document : std::as_const(invisibleCppEditorDocuments)) { - const QString filePath = document->filePath().toString(); + const FilePath filePath = document->filePath(); if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) { const CppEditorDocumentHandle::RefreshReason refreshReason = projectsUpdated ? CppEditorDocumentHandle::ProjectUpdate @@ -1708,7 +1708,7 @@ void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor) if (!editor || !editor->document()) return; - const QString filePath = editor->document()->filePath().toString(); + const FilePath filePath = editor->document()->filePath(); if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) { const CppEditorDocumentHandle::RefreshReason refreshReason = theCppEditorDocument->refreshReason(); diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 63f52d22e3..6de6b58f45 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -137,8 +137,8 @@ public: void removeExtraEditorSupport(AbstractEditorSupport *editorSupport); const QList<CppEditorDocumentHandle *> cppEditorDocuments() const; - CppEditorDocumentHandle *cppEditorDocument(const QString &filePath) const; - static BaseEditorDocumentProcessor *cppEditorDocumentProcessor(const QString &filePath); + CppEditorDocumentHandle *cppEditorDocument(const Utils::FilePath &filePath) const; + static BaseEditorDocumentProcessor *cppEditorDocumentProcessor(const Utils::FilePath &filePath); void registerCppEditorDocument(CppEditorDocumentHandle *cppEditorDocument); void unregisterCppEditorDocument(const QString &filePath); diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index 0c08e81008..dbc560c53c 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -5,7 +5,6 @@ #include "baseeditordocumentprocessor.h" #include "builtineditordocumentparser.h" -#include "cppsourceprocessor.h" #include "cpptoolstestcase.h" #include "editordocumenthandle.h" #include "modelmanagertesthelper.h" @@ -161,15 +160,15 @@ private: const Utils::FilePath m_filePath; }; -ProjectPart::ConstPtr projectPartOfEditorDocument(const QString &filePath) +} // anonymous namespace + +static ProjectPart::ConstPtr projectPartOfEditorDocument(const FilePath &filePath) { auto *editorDocument = CppModelManager::instance()->cppEditorDocument(filePath); QTC_ASSERT(editorDocument, return ProjectPart::ConstPtr()); return editorDocument->processor()->parser()->projectPartInfo().projectPart; } -} // anonymous namespace - /// Check: The preprocessor cleans include and framework paths. void ModelManagerTest::testPathsAreClean() { @@ -792,8 +791,8 @@ void ModelManagerTest::testPrecompiledHeaders() ModelManagerTestHelper helper; MyTestDataDir testDataDirectory(_("testdata_defines")); - const QString main1File = testDataDirectory.file(_("main1.cpp")); - const QString main2File = testDataDirectory.file(_("main2.cpp")); + const FilePath main1File = testDataDirectory.filePath("main1.cpp"); + const FilePath main2File = testDataDirectory.filePath("main2.cpp"); const QString header = testDataDirectory.file(_("header.h")); const QString pch1File = testDataDirectory.file(_("pch1.h")); const QString pch2File = testDataDirectory.file(_("pch2.h")); @@ -809,7 +808,7 @@ void ModelManagerTest::testPrecompiledHeaders() rpp1.setPreCompiledHeaders({pch1File}); rpp1.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); const auto part1 = ProjectPart::create(project->projectFilePath(), rpp1, {}, - {{main1File, ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); + {{main1File.toString(), ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); RawProjectPart rpp2; rpp2.setProjectFileLocation("project2.projectfile"); @@ -817,7 +816,7 @@ void ModelManagerTest::testPrecompiledHeaders() rpp2.setPreCompiledHeaders({pch2File}); rpp2.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); const auto part2 = ProjectPart::create(project->projectFilePath(), rpp2, {}, - {{main2File, ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); + {{main2File.toString(), ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2}); @@ -830,7 +829,7 @@ void ModelManagerTest::testPrecompiledHeaders() struct Data { QString firstDeclarationName; QString firstClassInPchFile; - QString fileName; + FilePath filePath; } d[] = { {_("one"), _("ClassInPch1"), main1File}, {_("two"), _("ClassInPch2"), main2File} @@ -838,16 +837,15 @@ void ModelManagerTest::testPrecompiledHeaders() for (auto &i : d) { const QString firstDeclarationName = i.firstDeclarationName; const QByteArray firstClassInPchFile = i.firstClassInPchFile.toUtf8(); - const QString fileName = i.fileName; + const FilePath filePath = i.filePath; - Core::IEditor *editor = Core::EditorManager::openEditor( - Utils::FilePath::fromString(fileName)); + Core::IEditor *editor = Core::EditorManager::openEditor(filePath); EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QVERIFY(mm->isCppEditor(editor)); - auto parser = BuiltinEditorDocumentParser::get(fileName); + auto parser = BuiltinEditorDocumentParser::get(filePath); QVERIFY(parser); BaseEditorDocumentParser::Configuration config = parser->configuration(); config.usePrecompiledHeaders = true; @@ -856,7 +854,7 @@ void ModelManagerTest::testPrecompiledHeaders() Utils::Language::Cxx, false}); // Check if defines from pch are considered - Document::Ptr document = mm->document(Utils::FilePath::fromString(fileName)); + Document::Ptr document = mm->document(filePath); QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName); // Check if declarations from pch are considered @@ -922,7 +920,7 @@ void ModelManagerTest::testDefinesPerEditor() QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QVERIFY(mm->isCppEditor(editor)); - const QString filePath = editor->document()->filePath().toString(); + const FilePath filePath = editor->document()->filePath(); const auto parser = BaseEditorDocumentParser::get(filePath); BaseEditorDocumentParser::Configuration config = parser->configuration(); config.editorDefines = editorDefines.toUtf8(); @@ -940,11 +938,11 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate() ModelManagerTestHelper helper; MyTestDataDir testDataDirectory(_("testdata_defines")); - const QString fileA = testDataDirectory.file(_("main1.cpp")); // content not relevant - const QString fileB = testDataDirectory.file(_("main2.cpp")); // content not relevant + const FilePath fileA = testDataDirectory.filePath("main1.cpp"); // content not relevant + const FilePath fileB = testDataDirectory.filePath("main2.cpp"); // content not relevant // Open file A in editor - Core::IEditor *editorA = Core::EditorManager::openEditor(Utils::FilePath::fromString(fileA)); + Core::IEditor *editorA = Core::EditorManager::openEditor(fileA); QVERIFY(editorA); EditorCloser closerA(editorA); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); @@ -953,7 +951,7 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate() QVERIFY(!documentAProjectPart->hasProject()); // Open file B in editor - Core::IEditor *editorB = Core::EditorManager::openEditor(Utils::FilePath::fromString(fileB)); + Core::IEditor *editorB = Core::EditorManager::openEditor(fileB); QVERIFY(editorB); EditorCloser closerB(editorB); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 2); @@ -971,7 +969,7 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate() RawProjectPart rpp; rpp.setQtVersion(Utils::QtMajorVersion::None); const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {{fileA, ProjectFile::CXXSource}, {fileB, ProjectFile::CXXSource}}); + {{fileA.toString(), ProjectFile::CXXSource}, {fileB.toString(), ProjectFile::CXXSource}}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); helper.updateProjectInfo(pi); @@ -1157,7 +1155,7 @@ void ModelManagerTest::testRenameIncludesInEditor() QCOMPARE(renamedHeaderContents, originalMalformedGuardContents); // Update the c++ model manager again and check for the new includes - TestCase::waitForProcessedEditorDocument(mainFile.toString()); + TestCase::waitForProcessedEditorDocument(mainFile); modelManager->updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); snapshot = modelManager->snapshot(); @@ -1186,7 +1184,7 @@ void ModelManagerTest::testDocumentsAndRevisions() TextEditor::BaseTextEditor *editor1; QVERIFY(helper.openCppEditor(filePath1, &editor1)); helper.closeEditorAtEndOfTestCase(editor1); - QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1.toString())); + QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); @@ -1199,7 +1197,7 @@ void ModelManagerTest::testDocumentsAndRevisions() TextEditor::BaseTextEditor *editor2; QVERIFY(helper.openCppEditor(filePath2, &editor2)); helper.closeEditorAtEndOfTestCase(editor2); - QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2.toString())); + QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U); @@ -1209,4 +1207,4 @@ void ModelManagerTest::testDocumentsAndRevisions() VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 4U); } -} // namespace CppEditor::Internal +} // CppEditor::Internal diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 97f0c9500a..91181b91f5 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -7629,8 +7629,7 @@ void ConvertQt4Connect::match(const CppQuickFixInterface &interface, QuickFixOpe void ExtraRefactoringOperations::match(const CppQuickFixInterface &interface, QuickFixOperations &result) { - const auto processor = CppModelManager::cppEditorDocumentProcessor( - interface.filePath().toString()); + const auto processor = CppModelManager::cppEditorDocumentProcessor(interface.filePath()); if (processor) { const auto clangFixItOperations = processor->extraRefactoringOperations(interface); result.append(clangFixItOperations); diff --git a/src/plugins/cppeditor/cppsourceprocessor_test.cpp b/src/plugins/cppeditor/cppsourceprocessor_test.cpp index 58e0fdf630..06b1748d8f 100644 --- a/src/plugins/cppeditor/cppsourceprocessor_test.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor_test.cpp @@ -110,8 +110,8 @@ void SourceProcessorTest::testIncludesCyclic() testCase.closeEditorAtEndOfTestCase(editor); // Check editor snapshot - const QString filePath = editor->document()->filePath().toString(); - auto *processor = CppModelManager::cppEditorDocumentProcessor(filePath); + const FilePath filePath = editor->document()->filePath(); + auto processor = CppModelManager::cppEditorDocumentProcessor(filePath); QVERIFY(processor); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath)); Snapshot snapshot = processor->snapshot(); diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 79fdca9471..86d7008443 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -268,7 +268,7 @@ static bool waitForProcessedEditorDocument_internal(CppEditorDocumentHandle *edi } } -bool TestCase::waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs) +bool TestCase::waitForProcessedEditorDocument(const FilePath &filePath, int timeOutInMs) { auto *editorDocument = CppModelManager::instance()->cppEditorDocument(filePath); return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs); @@ -314,21 +314,21 @@ bool TestCase::closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *edito return closeEditorsWithoutGarbageCollectorInvocation({editor}); } -CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const QString &filePath, +CPlusPlus::Document::Ptr TestCase::waitForFileInGlobalSnapshot(const FilePath &filePath, int timeOutInMs) { - const auto documents = waitForFilesInGlobalSnapshot(QStringList(filePath), timeOutInMs); + const auto documents = waitForFilesInGlobalSnapshot({filePath}, timeOutInMs); return documents.isEmpty() ? CPlusPlus::Document::Ptr() : documents.first(); } -QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(const QStringList &filePaths, +QList<CPlusPlus::Document::Ptr> TestCase::waitForFilesInGlobalSnapshot(const FilePaths &filePaths, int timeOutInMs) { QElapsedTimer t; t.start(); QList<CPlusPlus::Document::Ptr> result; - for (const QString &filePath : filePaths) { + for (const FilePath &filePath : filePaths) { forever { if (CPlusPlus::Document::Ptr document = globalSnapshot().document(filePath)) { result.append(document); diff --git a/src/plugins/cppeditor/cpptoolstestcase.h b/src/plugins/cppeditor/cpptoolstestcase.h index 53284f38be..20faf4ec90 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.h +++ b/src/plugins/cppeditor/cpptoolstestcase.h @@ -135,19 +135,19 @@ public: static CPlusPlus::Snapshot globalSnapshot(); static bool garbageCollectGlobalSnapshot(); - static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000); + static bool waitForProcessedEditorDocument( + const Utils::FilePath &filePath, int timeOutInMs = 5000); + static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument( CppEditorWidget *editorWidget); enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ }; static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project, int timeOutInMs = defaultTimeOutInMs); - static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot( - const QString &filePath, + static CPlusPlus::Document::Ptr waitForFileInGlobalSnapshot(const Utils::FilePath &filePath, int timeOutInMs = defaultTimeOutInMs); static QList<CPlusPlus::Document::Ptr> waitForFilesInGlobalSnapshot( - const QStringList &filePaths, - int timeOutInMs = defaultTimeOutInMs); + const Utils::FilePaths &filePaths, int timeOutInMs = defaultTimeOutInMs); static bool writeFile(const Utils::FilePath &filePath, const QByteArray &contents); diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index c15995504e..c4f325abdc 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -302,8 +302,7 @@ F2TestCase::F2TestCase(CppEditorAction action, // The file is "Full Checked" since it is in the working copy now, // that is the function bodies are processed. forever { - const Document::Ptr document = - waitForFileInGlobalSnapshot(testFile->filePath().toString()); + const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath()); QVERIFY(document); if (document->checkMode() == Document::FullCheck) { if (!document->diagnosticMessages().isEmpty()) diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp index bfc200acd1..f7af1f6bb1 100644 --- a/src/plugins/designer/gotoslot_test.cpp +++ b/src/plugins/designer/gotoslot_test.cpp @@ -27,6 +27,7 @@ using namespace CppEditor; using namespace CPlusPlus; using namespace Designer; using namespace Designer::Internal; +using namespace Utils; namespace { @@ -125,22 +126,22 @@ bool documentContainsMemberFunctionDeclaration(const Document::Ptr &document, class GoToSlotTestCase : public CppEditor::Tests::TestCase { public: - GoToSlotTestCase(const QStringList &files) + GoToSlotTestCase(const FilePaths &files) { QVERIFY(succeededSoFar()); QCOMPARE(files.size(), 3); QList<TextEditor::BaseTextEditor *> editors; - for (const QString &file : files) { - IEditor *editor = EditorManager::openEditor(Utils::FilePath::fromString(file)); + for (const FilePath &file : files) { + IEditor *editor = EditorManager::openEditor(file); TextEditor::BaseTextEditor *e = qobject_cast<TextEditor::BaseTextEditor *>(editor); QVERIFY(e); closeEditorAtEndOfTestCase(editor); editors << e; } - const QString cppFile = files.at(0); - const QString hFile = files.at(1); + const FilePath cppFile = files.at(0); + const FilePath hFile = files.at(1); QCOMPARE(DocumentModel::openedDocuments().size(), files.size()); waitForFilesInGlobalSnapshot({cppFile, hFile}); @@ -150,14 +151,14 @@ public: QVERIFY(integration); integration->emitNavigateToSlot("pushButton", "clicked()", QStringList()); - QCOMPARE(EditorManager::currentDocument()->filePath().toString(), cppFile); + QCOMPARE(EditorManager::currentDocument()->filePath(), cppFile); QVERIFY(EditorManager::currentDocument()->isModified()); // Wait for updated documents for (TextEditor::BaseTextEditor *editor : std::as_const(editors)) { QElapsedTimer t; t.start(); - const QString filePath = editor->document()->filePath().toString(); + const FilePath filePath = editor->document()->filePath(); if (auto parser = BuiltinEditorDocumentParser::get(filePath)) { while (t.elapsed() < 2000) { if (Document::Ptr document = parser->document()) { @@ -215,7 +216,7 @@ namespace Internal { void FormEditorPlugin::test_gotoslot() { QFETCH(QStringList, files); - (GoToSlotTestCase(files)); + (GoToSlotTestCase(Utils::transform(files, FilePath::fromString))); } void FormEditorPlugin::test_gotoslot_data() |