diff options
author | hjk <hjk@qt.io> | 2022-11-21 16:48:50 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-22 15:30:00 +0000 |
commit | fa1adf4d4001207902a5572b39da4f1cbc8752f1 (patch) | |
tree | ff9cbc1c951ab862f03902d38fc4495c3e1a3ae9 /src/plugins/cppeditor | |
parent | 822e2a224a283581b38948d4626f873c6b38c044 (diff) | |
download | qt-creator-fa1adf4d4001207902a5572b39da4f1cbc8752f1.tar.gz |
CPlusPlus: Proliferate FilePath use
The starts with CppDocument::filePath(), plus a bit of the fallout
This is one patch of potentially many. It is hard to draw the
line where to stop this kind of chunk, this here converts a few
additional functions for which including it in the patch looked
like less churn than without.
Converting is mostly fromString/toString, with a few exceptions
for "already seem" like caches, that use cheaper "path()" to
avoid likely performance regressions (on Windows FilePath
comparison is currently case-insenstive, and more expensive).
There should be no difference for local operation with this patch.
Change-Id: I7b35f98a0a6f0bfed4ea0f8f987faf586f7a8f2b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor')
45 files changed, 238 insertions, 219 deletions
diff --git a/src/plugins/cppeditor/baseeditordocumentprocessor.cpp b/src/plugins/cppeditor/baseeditordocumentprocessor.cpp index 97efb1c258..252f0a4992 100644 --- a/src/plugins/cppeditor/baseeditordocumentprocessor.cpp +++ b/src/plugins/cppeditor/baseeditordocumentprocessor.cpp @@ -22,7 +22,7 @@ namespace CppEditor { */ BaseEditorDocumentProcessor::BaseEditorDocumentProcessor(QTextDocument *textDocument, - const QString &filePath) + const Utils::FilePath &filePath) : m_filePath(filePath), m_textDocument(textDocument) { diff --git a/src/plugins/cppeditor/baseeditordocumentprocessor.h b/src/plugins/cppeditor/baseeditordocumentprocessor.h index d49efd095f..9461876f6b 100644 --- a/src/plugins/cppeditor/baseeditordocumentprocessor.h +++ b/src/plugins/cppeditor/baseeditordocumentprocessor.h @@ -10,6 +10,7 @@ #include "cpptoolsreuse.h" #include <coreplugin/helpitem.h> + #include <texteditor/codeassist/assistinterface.h> #include <texteditor/quickfix.h> #include <texteditor/texteditor.h> @@ -18,7 +19,6 @@ #include <cplusplus/CppDocument.h> #include <QTextEdit> - #include <QVariant> #include <functional> @@ -45,7 +45,7 @@ class CPPEDITOR_EXPORT BaseEditorDocumentProcessor : public QObject Q_OBJECT public: - BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath); + BaseEditorDocumentProcessor(QTextDocument *textDocument, const Utils::FilePath &filePath); ~BaseEditorDocumentProcessor() override; void run(bool projectsUpdated = false); @@ -65,7 +65,7 @@ public: virtual QFuture<CursorInfo> cursorInfo(const CursorInfoParams ¶ms) = 0; - QString filePath() const { return m_filePath; } + const Utils::FilePath &filePath() const { return m_filePath; } signals: // Signal interface to implement @@ -94,7 +94,7 @@ private: virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0; private: - QString m_filePath; + Utils::FilePath m_filePath; QTextDocument *m_textDocument; }; diff --git a/src/plugins/cppeditor/builtincursorinfo.cpp b/src/plugins/cppeditor/builtincursorinfo.cpp index a0190a3b13..870c9addbe 100644 --- a/src/plugins/cppeditor/builtincursorinfo.cpp +++ b/src/plugins/cppeditor/builtincursorinfo.cpp @@ -270,7 +270,7 @@ bool handleMacroCase(const Document::Ptr document, const int length = macro->nameToQString().size(); // Macro definition - if (macro->fileName() == document->fileName()) + if (macro->fileName() == document->filePath().pathView()) ranges->append(toRange(textCursor, macro->utf16CharOffset(), length)); // Other macro uses diff --git a/src/plugins/cppeditor/builtineditordocumentparser.cpp b/src/plugins/cppeditor/builtineditordocumentparser.cpp index 7d3a2430e8..221b7d70c8 100644 --- a/src/plugins/cppeditor/builtineditordocumentparser.cpp +++ b/src/plugins/cppeditor/builtineditordocumentparser.cpp @@ -137,15 +137,15 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur // Remove changed files from the snapshot QSet<Utils::FilePath> toRemove; for (const Document::Ptr &doc : std::as_const(state.snapshot)) { - const Utils::FilePath fileName = Utils::FilePath::fromString(doc->fileName()); - if (workingCopy.contains(fileName)) { - if (workingCopy.get(fileName).second != doc->editorRevision()) - addFileAndDependencies(&state.snapshot, &toRemove, fileName); + const Utils::FilePath filePath = doc->filePath(); + if (workingCopy.contains(filePath)) { + if (workingCopy.get(filePath).second != doc->editorRevision()) + addFileAndDependencies(&state.snapshot, &toRemove, filePath); continue; } - Document::Ptr otherDoc = globalSnapshot.document(fileName); + Document::Ptr otherDoc = globalSnapshot.document(filePath); if (!otherDoc.isNull() && otherDoc->revision() != doc->revision()) - addFileAndDependencies(&state.snapshot, &toRemove, fileName); + addFileAndDependencies(&state.snapshot, &toRemove, filePath); } if (!toRemove.isEmpty()) { @@ -165,9 +165,8 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur state.snapshot.remove(filePath()); Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) { - const QString fileName = doc->fileName(); - const bool isInEditor = fileName == filePath(); - Document::Ptr otherDoc = modelManager->document(fileName); + const bool isInEditor = doc->filePath().toString() == filePath(); + Document::Ptr otherDoc = modelManager->document(doc->filePath()); unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1; if (isInEditor) newRev = qMax(rev + 1, newRev); diff --git a/src/plugins/cppeditor/builtineditordocumentprocessor.cpp b/src/plugins/cppeditor/builtineditordocumentprocessor.cpp index 58947dcb63..fa74f71e6c 100644 --- a/src/plugins/cppeditor/builtineditordocumentprocessor.cpp +++ b/src/plugins/cppeditor/builtineditordocumentprocessor.cpp @@ -136,7 +136,7 @@ QList<TextEditor::BlockRange> toTextEditorBlocks( } // anonymous namespace BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(TextEditor::TextDocument *document) - : BaseEditorDocumentProcessor(document->document(), document->filePath().toString()) + : BaseEditorDocumentProcessor(document->document(), document->filePath()) , m_parser(new BuiltinEditorDocumentParser(document->filePath().toString(), indexerFileSizeLimitInMb())) , m_codeWarningsUpdated(false) @@ -241,13 +241,13 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d if (document.isNull()) return; - if (document->fileName() != filePath()) + if (document->filePath() != filePath()) return; // some other document got updated if (document->editorRevision() != revision()) return; // outdated content, wait for a new document to be parsed - qCDebug(log) << "document parsed" << document->fileName() << document->editorRevision(); + qCDebug(log) << "document parsed" << document->filePath() << document->editorRevision(); // Emit ifdefed out blocks const auto ifdefoutBlocks = toTextEditorBlocks(document->skippedBlocks()); @@ -261,14 +261,14 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d m_documentSnapshot = snapshot; const auto source = createSemanticInfoSource(false); - QTC_CHECK(source.snapshot.contains(document->fileName())); + QTC_CHECK(source.snapshot.contains(document->filePath())); m_semanticInfoUpdater.updateDetached(source); } void BuiltinEditorDocumentProcessor::onSemanticInfoUpdated(const SemanticInfo semanticInfo) { qCDebug(log) << "semantic info updated" - << semanticInfo.doc->fileName() << semanticInfo.revision << semanticInfo.complete; + << semanticInfo.doc->filePath() << semanticInfo.revision << semanticInfo.complete; emit semanticInfoUpdated(semanticInfo); @@ -283,7 +283,7 @@ void BuiltinEditorDocumentProcessor::onCodeWarningsUpdated( if (document.isNull()) return; - if (document->fileName() != filePath()) + if (document->filePath() != filePath()) return; // some other document got updated if (document->editorRevision() != revision()) @@ -302,10 +302,9 @@ void BuiltinEditorDocumentProcessor::onCodeWarningsUpdated( SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bool force) const { const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy(); - const QString path = filePath(); - return SemanticInfo::Source(path, - workingCopy.source(path), - workingCopy.revision(path), + return SemanticInfo::Source(filePath().toString(), + workingCopy.source(filePath()), + workingCopy.revision(filePath()), m_documentSnapshot, force); } diff --git a/src/plugins/cppeditor/builtinindexingsupport.cpp b/src/plugins/cppeditor/builtinindexingsupport.cpp index 81d8b11c2c..474c410e14 100644 --- a/src/plugins/cppeditor/builtinindexingsupport.cpp +++ b/src/plugins/cppeditor/builtinindexingsupport.cpp @@ -71,7 +71,7 @@ public: void process(const CPlusPlus::Document::Ptr document) { using namespace CPlusPlus; - const QString fileName = document->fileName(); + const QString fileName = document->filePath().toString(); const QList<Document::DiagnosticMessage> messages = document->diagnosticMessages(); for (const Document::DiagnosticMessage &message : messages) { @@ -272,7 +272,7 @@ public: future.waitForResume(); if (future.isCanceled()) break; - if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) { + if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) { QVector<Core::SearchResultItem> resultItems; auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult { if (matcher.match(info->symbolName()).hasMatch()) { diff --git a/src/plugins/cppeditor/cppchecksymbols.cpp b/src/plugins/cppeditor/cppchecksymbols.cpp index 1621f6ae51..c0ca402070 100644 --- a/src/plugins/cppeditor/cppchecksymbols.cpp +++ b/src/plugins/cppeditor/cppchecksymbols.cpp @@ -312,7 +312,7 @@ void CheckSymbols::run() { CollectSymbols collectTypes(_doc, _context.snapshot()); - _fileName = _doc->fileName(); + _filePath = _doc->filePath(); _potentialTypes = collectTypes.types(); _potentialFields = collectTypes.fields(); _potentialFunctions = collectTypes.functions(); @@ -334,7 +334,7 @@ void CheckSymbols::run() bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length) { - Document::DiagnosticMessage m(Document::DiagnosticMessage::Warning, _fileName, line, column, text, length); + Document::DiagnosticMessage m(Document::DiagnosticMessage::Warning, _filePath, line, column, text, length); _diagMsgs.append(m); return false; } diff --git a/src/plugins/cppeditor/cppchecksymbols.h b/src/plugins/cppeditor/cppchecksymbols.h index 044dc76f4c..c2416081ff 100644 --- a/src/plugins/cppeditor/cppchecksymbols.h +++ b/src/plugins/cppeditor/cppchecksymbols.h @@ -170,7 +170,7 @@ private: CPlusPlus::Document::Ptr _doc; CPlusPlus::LookupContext _context; CPlusPlus::TypeOfExpression typeOfExpression; - QString _fileName; + Utils::FilePath _filePath; QSet<QByteArray> _potentialTypes; QSet<QByteArray> _potentialFields; QSet<QByteArray> _potentialFunctions; diff --git a/src/plugins/cppeditor/cppcodegen_test.cpp b/src/plugins/cppeditor/cppcodegen_test.cpp index 22791b0899..6b7e1b3cc5 100644 --- a/src/plugins/cppeditor/cppcodegen_test.cpp +++ b/src/plugins/cppeditor/cppcodegen_test.cpp @@ -18,6 +18,7 @@ tests the InsertionPointLocator. */ using namespace CPlusPlus; +using namespace Utils; using CppEditor::Tests::TemporaryDir; @@ -42,10 +43,10 @@ Document::Ptr createDocumentAndFile(TemporaryDir *temporaryDir, int expectedGlobalSymbolCount) { QTC_ASSERT(temporaryDir, return Document::Ptr()); - const QString absoluteFilePath = temporaryDir->createFile(relativeFilePath, text); + const FilePath absoluteFilePath = temporaryDir->createFile(relativeFilePath, text); QTC_ASSERT(!absoluteFilePath.isEmpty(), return Document::Ptr()); - return createDocument(absoluteFilePath, text, expectedGlobalSymbolCount); + return createDocument(absoluteFilePath.toString(), text, expectedGlobalSymbolCount); } } // anonymous namespace @@ -73,7 +74,7 @@ void CodegenTest::testPublicInEmptyClass() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Public); QVERIFY(loc.isValid()); @@ -107,7 +108,7 @@ void CodegenTest::testPublicInNonemptyClass() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Public); QVERIFY(loc.isValid()); @@ -141,7 +142,7 @@ void CodegenTest::testPublicBeforeProtected() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Public); QVERIFY(loc.isValid()); @@ -176,7 +177,7 @@ void CodegenTest::testPrivateAfterProtected() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Private); QVERIFY(loc.isValid()); @@ -211,7 +212,7 @@ void CodegenTest::testProtectedInNonemptyClass() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Protected); QVERIFY(loc.isValid()); @@ -246,7 +247,7 @@ void CodegenTest::testProtectedBetweenPublicAndPrivate() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::Protected); QVERIFY(loc.isValid()); @@ -302,7 +303,7 @@ void CodegenTest::testQtdesignerIntegration() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); InsertionLocation loc = find.methodDeclarationInClass( - doc->fileName(), + doc->filePath(), foo, InsertionPointLocator::PrivateSlot); QVERIFY(loc.isValid()); @@ -351,7 +352,7 @@ void CodegenTest::testDefinitionEmptyClass() QList<InsertionLocation> locList = find.methodDefinition(decl); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QString()); QCOMPARE(loc.line(), 3); @@ -387,7 +388,7 @@ void CodegenTest::testDefinitionFirstMember() Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), - headerDocument->fileName(), 1, + headerDocument->filePath().toString(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -409,7 +410,7 @@ void CodegenTest::testDefinitionFirstMember() QList<InsertionLocation> locList = find.methodDefinition(decl); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.line(), 4); QCOMPARE(loc.column(), 1); QCOMPARE(loc.suffix(), QLatin1String("\n\n")); @@ -446,7 +447,7 @@ void CodegenTest::testDefinitionLastMember() Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), - headerDocument->fileName(), 1, + headerDocument->filePath().toString(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -468,7 +469,7 @@ void CodegenTest::testDefinitionLastMember() QList<InsertionLocation> locList = find.methodDefinition(decl); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.line(), 7); QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); @@ -512,7 +513,7 @@ void CodegenTest::testDefinitionMiddleMember() Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 4); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), - headerDocument->fileName(), 1, + headerDocument->filePath().toString(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -534,7 +535,7 @@ void CodegenTest::testDefinitionMiddleMember() QList<InsertionLocation> locList = find.methodDefinition(decl); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.line(), 7); QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); @@ -572,7 +573,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined() Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), - headerDocument->fileName(), 1, + headerDocument->filePath().toString(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -594,7 +595,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined() QList<InsertionLocation> locList = find.methodDefinition(decl); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.line(), 4); QCOMPARE(loc.column(), 1); QCOMPARE(loc.prefix(), QString()); @@ -635,7 +636,7 @@ void CodegenTest::testDefinitionMemberSpecificFile() Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); QVERIFY(sourceDocument); sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), - headerDocument->fileName(), 1, + headerDocument->filePath().toString(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -654,10 +655,11 @@ void CodegenTest::testDefinitionMemberSpecificFile() CppRefactoringChanges changes(snapshot); InsertionPointLocator find(changes); - QList<InsertionLocation> locList = find.methodDefinition(decl, true, sourceDocument->fileName()); + QList<InsertionLocation> locList = + find.methodDefinition(decl, true, sourceDocument->filePath().toString()); QVERIFY(locList.size() == 1); InsertionLocation loc = locList.first(); - QCOMPARE(loc.fileName(), sourceDocument->fileName()); + QCOMPARE(loc.fileName(), sourceDocument->filePath().toString()); QCOMPARE(loc.line(), 7); QCOMPARE(loc.column(), 2); QCOMPARE(loc.prefix(), QLatin1String("\n\n")); diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 0b5006e6bf..176bd9f4fc 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -33,6 +33,8 @@ #include <numeric> using namespace CPlusPlus; +using namespace Utils; + namespace CMI = CppEditor::CppCodeModelInspector; namespace { @@ -48,11 +50,11 @@ TextEditor::BaseTextEditor *currentEditor() return qobject_cast<TextEditor::BaseTextEditor*>(Core::EditorManager::currentEditor()); } -QString fileInCurrentEditor() +Utils::FilePath fileInCurrentEditor() { if (TextEditor::BaseTextEditor *editor = currentEditor()) - return editor->document()->filePath().toString(); - return QString(); + return editor->document()->filePath(); + return {}; } QSizePolicy sizePolicyWithStretchFactor(int stretchFactor) @@ -435,7 +437,7 @@ public: void configure(const Snapshot &snapshot); void setGlobalSnapshot(const Snapshot &snapshot); - QModelIndex indexForDocument(const QString &filePath); + QModelIndex indexForDocument(const Utils::FilePath &filePath); enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount }; @@ -465,11 +467,11 @@ void SnapshotModel::setGlobalSnapshot(const Snapshot &snapshot) m_globalSnapshot = snapshot; } -QModelIndex SnapshotModel::indexForDocument(const QString &filePath) +QModelIndex SnapshotModel::indexForDocument(const FilePath &filePath) { for (int i = 0, total = m_documents.size(); i < total; ++i) { const Document::Ptr document = m_documents.at(i); - if (document->fileName() == filePath) + if (document->filePath() == filePath) return index(i, FilePathColumn); } return {}; @@ -493,12 +495,12 @@ QVariant SnapshotModel::data(const QModelIndex &index, int role) const if (column == SymbolCountColumn) { return document->control()->symbolCount(); } else if (column == SharedColumn) { - Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); + Document::Ptr globalDocument = m_globalSnapshot.document(document->filePath()); const bool isShared = globalDocument && globalDocument->fingerprint() == document->fingerprint(); return CMI::Utils::toString(isShared); } else if (column == FilePathColumn) { - return QDir::toNativeSeparators(document->fileName()); + return document->filePath().toUserOutput(); } } return QVariant(); @@ -1200,7 +1202,7 @@ public: WorkingCopyModel(QObject *parent); void configure(const WorkingCopy &workingCopy); - QModelIndex indexForFile(const QString &filePath); + QModelIndex indexForFile(const Utils::FilePath &filePath); enum Columns { RevisionColumn, FilePathColumn, ColumnCount }; @@ -1211,11 +1213,11 @@ public: private: struct WorkingCopyEntry { - WorkingCopyEntry(const QString &filePath, const QByteArray &source, unsigned revision) + WorkingCopyEntry(const Utils::FilePath &filePath, const QByteArray &source, unsigned revision) : filePath(filePath), source(source), revision(revision) {} - QString filePath; + Utils::FilePath filePath; QByteArray source; unsigned revision; }; @@ -1232,14 +1234,13 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy) emit layoutAboutToBeChanged(); m_workingCopyList.clear(); const WorkingCopy::Table &elements = workingCopy.elements(); - for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { - m_workingCopyList << WorkingCopyEntry(it.key().toString(), it.value().first, - it.value().second); - } + for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) + m_workingCopyList << WorkingCopyEntry(it.key(), it.value().first, it.value().second); + emit layoutChanged(); } -QModelIndex WorkingCopyModel::indexForFile(const QString &filePath) +QModelIndex WorkingCopyModel::indexForFile(const Utils::FilePath &filePath) { for (int i = 0, total = m_workingCopyList.size(); i < total; ++i) { const WorkingCopyEntry entry = m_workingCopyList.at(i); @@ -1267,7 +1268,7 @@ QVariant WorkingCopyModel::data(const QModelIndex &index, int role) const if (column == RevisionColumn) return m_workingCopyList.at(row).revision; else if (column == FilePathColumn) - return m_workingCopyList.at(row).filePath; + return m_workingCopyList.at(row).filePath.toString(); } else if (role == Qt::UserRole) { return m_workingCopyList.at(row).source; } @@ -1659,14 +1660,14 @@ void CppCodeModelInspectorDialog::updateDocumentData(const Document::Ptr &docume // General const KeyValueModel::Table table = { - {QString::fromLatin1("File Path"), QDir::toNativeSeparators(document->fileName())}, + {QString::fromLatin1("File Path"), document->filePath().toUserOutput()}, {QString::fromLatin1("Last Modified"), CMI::Utils::toString(document->lastModified())}, {QString::fromLatin1("Revision"), CMI::Utils::toString(document->revision())}, {QString::fromLatin1("Editor Revision"), CMI::Utils::toString(document->editorRevision())}, {QString::fromLatin1("Check Mode"), CMI::Utils::toString(document->checkMode())}, {QString::fromLatin1("Tokenized"), CMI::Utils::toString(document->isTokenized())}, {QString::fromLatin1("Parsed"), CMI::Utils::toString(document->isParsed())}, - {QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->fileName())} + {QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->filePath())} }; m_docGenericInfoModel->configure(table); resizeColumns<KeyValueModel>(m_ui->docGeneralView); diff --git a/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp b/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp index b82c2a03e1..4341c74608 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordumper.cpp @@ -384,10 +384,10 @@ QString Utils::toString(const ProjectExplorer::Abi &abi) return QString("??"); } -QString Utils::partsForFile(const QString &fileName) +QString Utils::partsForFile(const ::Utils::FilePath &filePath) { const QList<ProjectPart::ConstPtr> parts - = CppModelManager::instance()->projectPart(fileName); + = CppModelManager::instance()->projectPart(filePath); QString result; for (const ProjectPart::ConstPtr &part : parts) result += part->displayName + QLatin1Char(','); @@ -580,7 +580,7 @@ void Dumper::dumpSnapshot(const CPlusPlus::Snapshot &snapshot, const QString &ti QList<CPlusPlus::Document::Ptr> globallyShared; QList<CPlusPlus::Document::Ptr> notGloballyShared; for (const CPlusPlus::Document::Ptr &document : documents) { - CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); + CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->filePath()); if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) globallyShared.append(document); else @@ -641,18 +641,18 @@ void Dumper::dumpDocuments(const QList<CPlusPlus::Document::Ptr> &documents, boo const QByteArray i4 = indent(4); for (const CPlusPlus::Document::Ptr &document : documents) { if (skipDetails) { - m_out << i2 << "\"" << document->fileName() << "\"\n"; + m_out << i2 << "\"" << document->filePath() << "\"\n"; continue; } - m_out << i2 << "Document \"" << document->fileName() << "\"{{{3\n"; + m_out << i2 << "Document \"" << document->filePath() << "\"{{{3\n"; m_out << i3 << "Last Modified : " << Utils::toString(document->lastModified()) << "\n"; m_out << i3 << "Revision : " << Utils::toString(document->revision()) << "\n"; m_out << i3 << "Editor Revision: " << Utils::toString(document->editorRevision()) << "\n"; m_out << i3 << "Check Mode : " << Utils::toString(document->checkMode()) << "\n"; m_out << i3 << "Tokenized : " << Utils::toString(document->isTokenized()) << "\n"; m_out << i3 << "Parsed : " << Utils::toString(document->isParsed()) << "\n"; - m_out << i3 << "Project Parts : " << Utils::partsForFile(document->fileName()) << "\n"; + m_out << i3 << "Project Parts : " << Utils::partsForFile(document->filePath()) << "\n"; const QList<CPlusPlus::Document::Include> includes = document->unresolvedIncludes() + document->resolvedIncludes(); diff --git a/src/plugins/cppeditor/cppcodemodelinspectordumper.h b/src/plugins/cppeditor/cppcodemodelinspectordumper.h index 872c868fee..03b3c7c703 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordumper.h +++ b/src/plugins/cppeditor/cppcodemodelinspectordumper.h @@ -33,7 +33,7 @@ struct Utils static QString toString(ProjectFile::Kind kind); static QString toString(CPlusPlus::Kind kind); static QString toString(const ProjectExplorer::Abi &abi); - static QString partsForFile(const QString &fileName); + static QString partsForFile(const ::Utils::FilePath &filePath); static QString unresolvedFileNameWithDelimiters(const CPlusPlus::Document::Include &include); static QString pathListToString(const QStringList &pathList); static QString pathListToString(const ProjectExplorer::HeaderPaths &pathList); diff --git a/src/plugins/cppeditor/cppcodestylesettingspage.cpp b/src/plugins/cppeditor/cppcodestylesettingspage.cpp index 37cdc81c7f..7f2f0709cc 100644 --- a/src/plugins/cppeditor/cppcodestylesettingspage.cpp +++ b/src/plugins/cppeditor/cppcodestylesettingspage.cpp @@ -45,7 +45,8 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi Environment env; Preprocessor preprocess(nullptr, &env); const QByteArray preprocessedSource - = preprocess.run(QLatin1String("<no-file>"), textDocument->toPlainText().toUtf8()); + = preprocess.run(Utils::FilePath::fromParts({}, {}, u"<no-file>"), + textDocument->toPlainText().toUtf8()); Document::Ptr cppDocument = Document::create(QLatin1String("<no-file>")); cppDocument->setUtf8Source(preprocessedSource); diff --git a/src/plugins/cppeditor/cppcompletion_test.cpp b/src/plugins/cppeditor/cppcompletion_test.cpp index 4721b2775e..7fa42a4be9 100644 --- a/src/plugins/cppeditor/cppcompletion_test.cpp +++ b/src/plugins/cppeditor/cppcompletion_test.cpp @@ -26,9 +26,11 @@ /*! Tests for code completion. */ + +using namespace Core; using namespace CPlusPlus; using namespace TextEditor; -using namespace Core; +using namespace Utils; namespace CppEditor::Internal { namespace { @@ -53,11 +55,11 @@ public: m_temporaryDir.reset(new CppEditor::Tests::TemporaryDir()); QVERIFY(m_temporaryDir->isValid()); const QByteArray fileExt = isObjC ? "mm" : "h"; - const QString fileName = m_temporaryDir->createFile("file." + fileExt, m_source); - QVERIFY(!fileName.isEmpty()); + const FilePath filePath = m_temporaryDir->createFile("file." + fileExt, m_source); + QVERIFY(!filePath.isEmpty()); // Open in editor - m_editor = EditorManager::openEditor(Utils::FilePath::fromString(fileName)); + m_editor = EditorManager::openEditor(filePath); QVERIFY(m_editor); closeEditorAtEndOfTestCase(m_editor); m_editorWidget = TextEditorWidget::fromEditor(m_editor); @@ -66,7 +68,7 @@ public: m_textDocument = m_editorWidget->document(); // Get Document - const Document::Ptr document = waitForFileInGlobalSnapshot(fileName); + const Document::Ptr document = waitForFileInGlobalSnapshot(filePath.toString()); QVERIFY(document); QVERIFY(document->diagnosticMessages().isEmpty()); diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 6aa677aaba..b8330aadb2 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -1480,7 +1480,7 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope) addKeywords(); addMacros(CppModelManager::configurationFileName(), context.snapshot()); - addMacros(context.thisDocument()->fileName(), context.snapshot()); + addMacros(context.thisDocument()->filePath().toString(), context.snapshot()); addSnippets(); return !m_completions.isEmpty(); } @@ -1860,10 +1860,10 @@ void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snap { Document::Ptr doc = snapshot.document(fileName); - if (!doc || processed->contains(doc->fileName())) + if (!doc || processed->contains(doc->filePath().path())) return; - processed->insert(doc->fileName()); + processed->insert(doc->filePath().path()); const QList<Document::Include> includes = doc->resolvedIncludes(); for (const Document::Include &i : includes) diff --git a/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp b/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp index 597c289f85..965c5d4226 100644 --- a/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp +++ b/src/plugins/cppeditor/cppcurrentdocumentfilter.cpp @@ -119,7 +119,7 @@ void CppCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection, void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc) { QMutexLocker locker(&m_mutex); - if (m_currentFileName == doc->fileName()) + if (m_currentFileName == doc->filePath()) m_itemsOfCurrentDoc.clear(); } @@ -127,7 +127,7 @@ void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *currentEdit { QMutexLocker locker(&m_mutex); if (currentEditor) - m_currentFileName = currentEditor->document()->filePath().toString(); + m_currentFileName = currentEditor->document()->filePath(); else m_currentFileName.clear(); m_itemsOfCurrentDoc.clear(); @@ -139,7 +139,7 @@ void CppCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutTo return; QMutexLocker locker(&m_mutex); - if (m_currentFileName == editorAboutToClose->document()->filePath().toString()) { + if (m_currentFileName == editorAboutToClose->document()->filePath()) { m_currentFileName.clear(); m_itemsOfCurrentDoc.clear(); } diff --git a/src/plugins/cppeditor/cppcurrentdocumentfilter.h b/src/plugins/cppeditor/cppcurrentdocumentfilter.h index ab717dace6..26caa0bcbd 100644 --- a/src/plugins/cppeditor/cppcurrentdocumentfilter.h +++ b/src/plugins/cppeditor/cppcurrentdocumentfilter.h @@ -41,7 +41,7 @@ private: SearchSymbols search; mutable QMutex m_mutex; - QString m_currentFileName; + Utils::FilePath m_currentFileName; QList<IndexItem::Ptr> m_itemsOfCurrentDoc; }; diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp index 989c4b01ce..0b749d7906 100644 --- a/src/plugins/cppeditor/cppdoxygen_test.cpp +++ b/src/plugins/cppeditor/cppdoxygen_test.cpp @@ -21,6 +21,8 @@ using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::TestCase; using CppEditor::Internal::Tests::VerifyCleanCppModelManager; +using namespace Utils; + namespace CppEditor { namespace Internal { namespace Tests { @@ -425,7 +427,7 @@ void DoxygenTest::runTest(const QByteArray &original, } // Update Code Model - QVERIFY(TestCase::parseFiles(testDocument.filePath())); + QVERIFY(TestCase::parseFiles(testDocument.filePath().toString())); // Open Editor QVERIFY(TestCase::openCppEditor(testDocument.filePath(), &testDocument.m_editor, diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index 7aed0348dd..a60cd9660a 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -496,7 +496,7 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr const Utils::Id category = Utils::Id::fromString(kind); for (const auto &diagnostic : mm()->diagnosticMessages()) { - if (FilePath::fromString(diagnostic.fileName()) == filePath()) { + if (diagnostic.filePath() == filePath()) { auto it = std::find_if(std::begin(removedMarks), std::end(removedMarks), [&category, &diagnostic](TextMark *existing) { diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index 5d100007b4..dc9cb0fd64 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -239,7 +239,7 @@ public: categorize(categorize) { } - QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName) + QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath) { QList<CPlusPlus::Usage> usages; if (future->isPaused()) @@ -248,18 +248,18 @@ public: return usages; const CPlusPlus::Identifier *symbolId = symbol->identifier(); - if (CPlusPlus::Document::Ptr previousDoc = snapshot.document(fileName)) { + if (CPlusPlus::Document::Ptr previousDoc = snapshot.document(filePath)) { CPlusPlus::Control *control = previousDoc->control(); if (!control->findIdentifier(symbolId->chars(), symbolId->size())) return usages; // skip this document, it's not using symbolId. } CPlusPlus::Document::Ptr doc; - const QByteArray unpreprocessedSource = getSource(fileName, workingCopy); + const QByteArray unpreprocessedSource = getSource(filePath, workingCopy); - if (symbolDocument && fileName == Utils::FilePath::fromString(symbolDocument->fileName())) { + if (symbolDocument && filePath == symbolDocument->filePath()) { doc = symbolDocument; } else { - doc = snapshot.preprocessedDocument(unpreprocessedSource, fileName); + doc = snapshot.preprocessedDocument(unpreprocessedSource, filePath); doc->tokenize(); } @@ -541,10 +541,9 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile); // document is not parsed and has no bindings yet, do it - QByteArray source = getSource(Utils::FilePath::fromString(newSymbolDocument->fileName()), - m_modelManager->workingCopy()); + QByteArray source = getSource(newSymbolDocument->filePath(), m_modelManager->workingCopy()); CPlusPlus::Document::Ptr doc = - snapshot.preprocessedDocument(source, FilePath::fromString(newSymbolDocument->fileName())); + snapshot.preprocessedDocument(source, newSymbolDocument->filePath()); doc->check(); // find matching symbol in new document and return the new parameters diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index 499549638e..7e86acfc12 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -182,8 +182,8 @@ Class *VirtualFunctionHelper::staticClassOfFunctionCallExpression_internal() con Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snapshot &snapshot, QSet<QString> *processed) { - if (doc && !name.startsWith('<') && !processed->contains(doc->fileName())) { - processed->insert(doc->fileName()); + if (doc && !name.startsWith('<') && !processed->contains(doc->filePath().path())) { + processed->insert(doc->filePath().path()); for (const Macro ¯o : doc->definedMacros()) { if (macro.name() == name) { diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index be78b1bffb..c5d1b364cd 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -198,8 +198,7 @@ void FunctionDeclDefLinkFinder::startFindLinkAt( // find the start/end offsets CppRefactoringChanges refactoringChanges(snapshot); - CppRefactoringFilePtr sourceFile = refactoringChanges.file( - Utils::FilePath::fromString(doc->fileName())); + CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->filePath()); sourceFile->setCppDocument(doc); int start, end; declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end); diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp index 1d3d69fad6..d3d0bf0397 100644 --- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp @@ -17,6 +17,7 @@ #include <QtTest> using namespace CPlusPlus; +using namespace Utils; using CppEditor::Tests::TemporaryDir; @@ -56,7 +57,7 @@ public: { QVERIFY(succeededSoFar()); - QSet<QString> filePaths; + QSet<FilePath> filePaths; const int sourceListSize = sourceList.size(); TemporaryDir temporaryDir; @@ -67,14 +68,13 @@ public: // Write source to file const QString fileName = QString::fromLatin1("file%1.h").arg(i+1); - const QString absoluteFilePath = temporaryDir.createFile(fileName.toLatin1(), source); - filePaths << absoluteFilePath; + filePaths << temporaryDir.createFile(fileName.toLatin1(), source); } // Open Editor - const QString fileName = temporaryDir.path() + QLatin1String("/file1.h"); + const Utils::FilePath filePath = temporaryDir.filePath() / "file1.h"; TextEditor::BaseTextEditor *editor; - QVERIFY(openCppEditor(fileName, &editor)); + QVERIFY(openCppEditor(filePath, &editor)); closeEditorAtEndOfTestCase(editor); // Update Code Model diff --git a/src/plugins/cppeditor/cpplocatordata.cpp b/src/plugins/cppeditor/cpplocatordata.cpp index 3349011ce9..11eed8c74a 100644 --- a/src/plugins/cppeditor/cpplocatordata.cpp +++ b/src/plugins/cppeditor/cpplocatordata.cpp @@ -25,7 +25,7 @@ void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document) bool isPending = false; for (int i = 0, ei = m_pendingDocuments.size(); i < ei; ++i) { const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i); - if (doc->fileName() == document->fileName()) { + if (doc->filePath() == document->filePath()) { isPending = true; if (document->revision() >= doc->revision()) m_pendingDocuments[i] = document; @@ -33,7 +33,7 @@ void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document) } } - if (!isPending && QFileInfo(document->fileName()).suffix() != "moc") + if (!isPending && document->filePath().suffix() != "moc") m_pendingDocuments.append(document); flushPendingDocument(false); @@ -50,7 +50,7 @@ void CppLocatorData::onAboutToRemoveFiles(const QStringList &files) m_infosByFile.remove(file); for (int i = 0; i < m_pendingDocuments.size(); ++i) { - if (m_pendingDocuments.at(i)->fileName() == file) { + if (m_pendingDocuments.at(i)->filePath().path() == file) { m_pendingDocuments.remove(i); break; } @@ -70,7 +70,7 @@ void CppLocatorData::flushPendingDocument(bool force) const return; for (CPlusPlus::Document::Ptr doc : std::as_const(m_pendingDocuments)) - m_infosByFile.insert(Internal::StringTable::insert(doc->fileName()), m_search(doc)); + m_infosByFile.insert(Internal::StringTable::insert(doc->filePath()), m_search(doc)); m_pendingDocuments.clear(); m_pendingDocuments.reserve(MaxPendingDocuments); diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 3a066abcb4..884e5d3175 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -263,10 +263,10 @@ QSet<QString> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> const QDateTime lastModified = doc->lastModified(); if (!lastModified.isNull()) { - QFileInfo fileInfo(doc->fileName()); + const FilePath filePath = doc->filePath(); - if (fileInfo.exists() && fileInfo.lastModified() != lastModified) - sourceFiles.insert(doc->fileName()); + if (filePath.exists() && filePath.lastModified() != lastModified) + sourceFiles.insert(filePath.toString()); } } @@ -286,7 +286,7 @@ CppSourceProcessor *CppModelManager::createSourceProcessor() { CppModelManager *that = instance(); return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) { - const Document::Ptr previousDocument = that->document(doc->fileName()); + const Document::Ptr previousDocument = that->document(doc->filePath()); const unsigned newRevision = previousDocument.isNull() ? 1U : previousDocument->revision() + 1; @@ -816,10 +816,10 @@ Snapshot CppModelManager::snapshot() const return d->m_snapshot; } -Document::Ptr CppModelManager::document(const QString &fileName) const +Document::Ptr CppModelManager::document(const FilePath &filePath) const { QMutexLocker locker(&d->m_snapshotMutex); - return d->m_snapshot.document(fileName); + return d->m_snapshot.document(filePath); } /// Replace the document in the snapshot. @@ -829,7 +829,7 @@ bool CppModelManager::replaceDocument(Document::Ptr newDoc) { QMutexLocker locker(&d->m_snapshotMutex); - Document::Ptr previous = d->m_snapshot.document(newDoc->fileName()); + Document::Ptr previous = d->m_snapshot.document(newDoc->filePath()); if (previous && (newDoc->revision() != 0 && newDoc->revision() < previous->revision())) // the new document is outdated return false; @@ -1617,7 +1617,7 @@ void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath, const QList<Snapshot::IncludeLocation> locations = snapshot().includeLocationsOfDocument( isUiFile ? oldFileName : oldFilePath.toString()); for (const Snapshot::IncludeLocation &loc : locations) { - const auto filePath = FilePath::fromString(loc.first->fileName()); + const FilePath filePath = loc.first->filePath(); // Larger projects can easily have more than one ui file with the same name. // Replace only if ui file and including source file belong to the same product. diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 221672d979..5e5b19a3a1 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -118,7 +118,7 @@ public: ProjectPart::ConstPtr fallbackProjectPart(); CPlusPlus::Snapshot snapshot() const override; - Document::Ptr document(const QString &fileName) const; + Document::Ptr document(const Utils::FilePath &filePath) const; bool replaceDocument(Document::Ptr newDoc); void emitDocumentUpdated(Document::Ptr doc); diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index 42ce180947..ed1ac75268 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -33,6 +33,7 @@ QCOMPARE(document->revision(), expectedRevision); using namespace ProjectExplorer; +using namespace Utils; using CPlusPlus::Document; @@ -66,6 +67,11 @@ public: QString fileFromSourcesDir(const QString &fileName) const { return directory(_("sources")) + QLatin1Char('/') + fileName; } + + FilePath filePath(const QString &p) const + { + return FilePath::fromString(TestDataDir::file(p)); + } }; QStringList toAbsolutePaths(const QStringList &relativePathList, @@ -113,7 +119,7 @@ public: class FileChangerAndRestorer { public: - explicit FileChangerAndRestorer(const QString &filePath) + explicit FileChangerAndRestorer(const Utils::FilePath &filePath) : m_filePath(filePath) { } @@ -127,7 +133,7 @@ public: bool readContents(QByteArray *contents) { Utils::FileReader fileReader; - const bool isFetchOk = fileReader.fetch(Utils::FilePath::fromString(m_filePath)); + const bool isFetchOk = fileReader.fetch(m_filePath); if (isFetchOk) { m_originalFileContents = fileReader.data(); if (contents) @@ -148,7 +154,7 @@ private: } QByteArray m_originalFileContents; - const QString &m_filePath; + const Utils::FilePath m_filePath; }; ProjectPart::ConstPtr projectPartOfEditorDocument(const QString &filePath) @@ -216,7 +222,7 @@ void ModelManagerTest::testFrameworkHeaders() QCoreApplication::processEvents(); QVERIFY(mm->snapshot().contains(source)); - Document::Ptr doc = mm->document(source); + Document::Ptr doc = mm->document(Utils::FilePath::fromString(source)); QVERIFY(!doc.isNull()); CPlusPlus::Namespace *ns = doc->globalNamespace(); QVERIFY(ns); @@ -482,7 +488,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() // Modify the file QTest::qSleep(1000); // Make sure the timestamp is different - FileChangerAndRestorer fileChangerAndRestorer(fileToChange); + FileChangerAndRestorer fileChangerAndRestorer(FilePath::fromString(fileToChange)); QByteArray originalContents; QVERIFY(fileChangerAndRestorer.readContents(&originalContents)); const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;"; @@ -762,16 +768,15 @@ void ModelManagerTest::testDefinesPerProject() for (auto &i : d) { const QString firstDeclarationName = i.firstDeclarationName; - const QString fileName = i.fileName; + const Utils::FilePath filePath = Utils::FilePath::fromString(i.fileName); - 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)); - Document::Ptr doc = mm->document(fileName); + Document::Ptr doc = mm->document(filePath); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -845,7 +850,7 @@ void ModelManagerTest::testPrecompiledHeaders() Utils::Language::Cxx, false}); // Check if defines from pch are considered - Document::Ptr document = mm->document(fileName); + Document::Ptr document = mm->document(Utils::FilePath::fromString(fileName)); QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName); // Check if declarations from pch are considered @@ -919,7 +924,7 @@ void ModelManagerTest::testDefinesPerEditor() parser->update({CppModelManager::instance()->workingCopy(), nullptr, Utils::Language::Cxx, false}); - Document::Ptr doc = mm->document(main1File); + Document::Ptr doc = mm->document(FilePath::fromString(main1File)); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -1154,9 +1159,9 @@ void ModelManagerTest::testDocumentsAndRevisions() // Index two files const MyTestDataDir testDir(_("testdata_project1")); - const QString filePath1 = testDir.file(QLatin1String("foo.h")); - const QString filePath2 = testDir.file(QLatin1String("foo.cpp")); - const QSet<QString> filesToIndex = {filePath1,filePath2}; + const FilePath filePath1 = testDir.filePath(QLatin1String("foo.h")); + const FilePath filePath2 = testDir.filePath(QLatin1String("foo.cpp")); + const QSet<FilePath> filesToIndex = {filePath1,filePath2}; QVERIFY(TestCase::parseFiles(filesToIndex)); CppModelManager *modelManager = CppModelManager::instance(); @@ -1167,7 +1172,7 @@ void ModelManagerTest::testDocumentsAndRevisions() TextEditor::BaseTextEditor *editor1; QVERIFY(helper.openCppEditor(filePath1, &editor1)); helper.closeEditorAtEndOfTestCase(editor1); - QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); + QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1.toString())); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); @@ -1180,7 +1185,7 @@ void ModelManagerTest::testDocumentsAndRevisions() TextEditor::BaseTextEditor *editor2; QVERIFY(helper.openCppEditor(filePath2, &editor2)); helper.closeEditorAtEndOfTestCase(editor2); - QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); + QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2.toString())); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U); diff --git a/src/plugins/cppeditor/cpppointerdeclarationformatter_test.cpp b/src/plugins/cppeditor/cpppointerdeclarationformatter_test.cpp index 06134ee3fc..0a5f88ab9a 100644 --- a/src/plugins/cppeditor/cpppointerdeclarationformatter_test.cpp +++ b/src/plugins/cppeditor/cpppointerdeclarationformatter_test.cpp @@ -24,6 +24,7 @@ #include <QtTest> using namespace CPlusPlus; +using namespace Utils; Q_DECLARE_METATYPE(CppEditor::Internal::Overview) @@ -63,15 +64,15 @@ public: // Write source to temprorary file CppEditor::Tests::TemporaryDir temporaryDir; QVERIFY(temporaryDir.isValid()); - const QString filePath = temporaryDir.createFile("file.h", sourceWithoutCursorMarker); + const FilePath filePath = temporaryDir.createFile("file.h", sourceWithoutCursorMarker); QVERIFY(!filePath.isEmpty()); // Preprocess source - Environment env; + CPlusPlus::Environment env; Preprocessor preprocess(nullptr, &env); const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker); - Document::Ptr document = Document::create(filePath); + Document::Ptr document = Document::create(filePath.toString()); document->setUtf8Source(preprocessedSource); document->parse(parseMode); document->check(); @@ -83,9 +84,7 @@ public: QScopedPointer<TextEditor::BaseTextEditor> editor( TextEditor::PlainTextEditorFactory::createPlainTextEditor()); QString error; - editor->document()->open(&error, - Utils::FilePath::fromString(document->fileName()), - Utils::FilePath::fromString(document->fileName())); + editor->document()->open(&error, document->filePath(), document->filePath()); QVERIFY(error.isEmpty()); // Set cursor position diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index bbd192f7f7..1aaa4c8a5c 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -25,6 +25,7 @@ using namespace Core; using namespace CPlusPlus; using namespace TextEditor; +using namespace Utils; using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::Internal::TestIncludePaths; @@ -92,7 +93,7 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc } // Update Code Model - QSet<QString> filePaths; + QSet<FilePath> filePaths; for (const TestDocumentPtr &document : std::as_const(m_testDocuments)) filePaths << document->filePath(); QVERIFY(parseFiles(filePaths)); @@ -150,7 +151,7 @@ BaseQuickFixTestCase::~BaseQuickFixTestCase() // Remove created files from file system for (const TestDocumentPtr &testDocument : std::as_const(m_testDocuments)) - QVERIFY(QFile::remove(testDocument->filePath())); + QVERIFY(testDocument->filePath().removeFile()); } /// Leading whitespace is not removed, so we can check if the indetation ranges diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 0c33c37733..33819ec445 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -80,7 +80,7 @@ using namespace CPlusPlus; using namespace TextEditor; -using Utils::ChangeSet; +using namespace Utils; namespace CppEditor { @@ -2056,7 +2056,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa QString className; QList<Core::LocatorFilterEntry> matches; - const QString currentDocumentFilePath = interface.semanticInfo().doc->fileName(); + const QString currentDocumentFilePath = interface.semanticInfo().doc->filePath().toString(); const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath); QList<Utils::FilePath> headers; @@ -2530,7 +2530,7 @@ public: const QString &targetFileName, const Class *targetSymbol, InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority) : CppQuickFixOperation(interface, priority) - , m_targetFileName(targetFileName) + , m_targetFileName(FilePath::fromString(targetFileName)) , m_targetSymbol(targetSymbol) , m_xsSpec(xsSpec) , m_decl(decl) @@ -2549,8 +2549,7 @@ public: m_targetFileName, m_targetSymbol, m_xsSpec); QTC_ASSERT(loc.isValid(), return); - CppRefactoringFilePtr targetFile = refactoring.file( - Utils::FilePath::fromString(m_targetFileName)); + CppRefactoringFilePtr targetFile = refactoring.file(m_targetFileName); int targetPosition1 = targetFile->position(loc.line(), loc.column()); int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1); @@ -2565,7 +2564,7 @@ public: static QString generateDeclaration(const Function *function); private: - QString m_targetFileName; + FilePath m_targetFileName; const Class *m_targetSymbol; InsertionPointLocator::AccessSpec m_xsSpec; QString m_decl; @@ -2985,12 +2984,12 @@ private: const CppRefactoringChanges refactoring(snapshot()); const InsertionPointLocator locator(refactoring); - const QString filePath = QString::fromUtf8(m_class->fileName()); + const FilePath filePath = FilePath::fromUtf8(m_class->fileName()); const InsertionLocation loc = locator.methodDeclarationInClass( filePath, m_class, InsertionPointLocator::Private); QTC_ASSERT(loc.isValid(), return); - CppRefactoringFilePtr targetFile = refactoring.file(Utils::FilePath::fromString(filePath)); + CppRefactoringFilePtr targetFile = refactoring.file(filePath); const int targetPosition1 = targetFile->position(loc.line(), loc.column()); const int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1); ChangeSet target; @@ -3633,7 +3632,7 @@ protected: if (insertionPoint != m_headerInsertionPoints.end()) return *insertionPoint; const InsertionLocation loc = m_locator.methodDeclarationInClass( - m_headerFile->filePath().toString(), m_class, spec, + m_headerFile->filePath(), m_class, spec, InsertionPointLocator::ForceAccessSpec::Yes); m_headerInsertionPoints.insert(spec, loc); return loc; @@ -4943,10 +4942,10 @@ public: // Write declaration, if necessary. if (matchingClass) { InsertionPointLocator locator(refactoring); - const QString fileName = QLatin1String(matchingClass->fileName()); + const FilePath filePath = FilePath::fromUtf8(matchingClass->fileName()); const InsertionLocation &location = - locator.methodDeclarationInClass(fileName, matchingClass, options.access); - CppRefactoringFilePtr declFile = refactoring.file(Utils::FilePath::fromString(fileName)); + locator.methodDeclarationInClass(filePath, matchingClass, options.access); + CppRefactoringFilePtr declFile = refactoring.file(filePath); change.clear(); position = declFile->position(location.line(), location.column()); change.insert(position, location.prefix() + funcDecl + location.suffix()); @@ -8081,8 +8080,7 @@ private: while (!nodesWithProcessedParents.empty()) { Node &node = nodesWithProcessedParents.back(); nodesWithProcessedParents.pop_back(); - CppRefactoringFilePtr file = refactoring.file( - Utils::FilePath::fromString(node.document->fileName())); + CppRefactoringFilePtr file = refactoring.file(node.document->filePath()); const bool parentHasUsing = Utils::anyOf(node.includes, &Node::hasGlobalUsingDirective); const int startPos = parentHasUsing ? 0 @@ -8154,14 +8152,13 @@ private: if (m_processed.contains(loc.first)) continue; - CppRefactoringFilePtr file = refactoring.file( - Utils::FilePath::fromString(loc.first->fileName())); + CppRefactoringFilePtr file = refactoring.file(loc.first->filePath()); const bool noGlobalUsing = refactorFile(file, refactoring.snapshot(), file->position(loc.second, 1)); m_processed.insert(loc.first); if (noGlobalUsing) - processIncludes(refactoring, loc.first->fileName()); + processIncludes(refactoring, loc.first->filePath().toString()); } } diff --git a/src/plugins/cppeditor/cppsemanticinfoupdater.cpp b/src/plugins/cppeditor/cppsemanticinfoupdater.cpp index 12ee180b5c..7d4aca6f9b 100644 --- a/src/plugins/cppeditor/cppsemanticinfoupdater.cpp +++ b/src/plugins/cppeditor/cppsemanticinfoupdater.cpp @@ -121,7 +121,7 @@ bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::So && currentSemanticInfo.revision == source.revision && currentSemanticInfo.doc && currentSemanticInfo.doc->translationUnit()->ast() - && currentSemanticInfo.doc->fileName() == source.fileName + && currentSemanticInfo.doc->filePath().toString() == source.fileName && !currentSemanticInfo.snapshot.isEmpty() && currentSemanticInfo.snapshot == source.snapshot) { SemanticInfo newSemanticInfo; diff --git a/src/plugins/cppeditor/cppsourceprocessor.cpp b/src/plugins/cppeditor/cppsourceprocessor.cpp index 35cea8f142..3f1d18c089 100644 --- a/src/plugins/cppeditor/cppsourceprocessor.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor.cpp @@ -66,7 +66,7 @@ inline Message messageNoSuchFile(Document::Ptr &document, const QString &fileNam { const QString text = QCoreApplication::translate( "CppSourceProcessor", "%1: No such file or directory").arg(fileName); - return Message(Message::Warning, document->fileName(), line, /*column =*/ 0, text); + return Message(Message::Warning, document->filePath(), line, /*column =*/ 0, text); } inline Message messageNoFileContents(Document::Ptr &document, const QString &fileName, @@ -74,7 +74,7 @@ inline Message messageNoFileContents(Document::Ptr &document, const QString &fil { const QString text = QCoreApplication::translate( "CppSourceProcessor", "%1: Could not get file contents").arg(fileName); - return Message(Message::Warning, document->fileName(), line, /*column =*/ 0, text); + return Message(Message::Warning, document->filePath(), line, /*column =*/ 0, text); } inline const CPlusPlus::Macro revision(const WorkingCopy &workingCopy, @@ -244,7 +244,7 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ if (m_currentDoc) { if (type == IncludeLocal) { - const QFileInfo currentFileInfo(m_currentDoc->fileName()); + const QFileInfo currentFileInfo = m_currentDoc->filePath().toFileInfo(); const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName; if (checkFile(path)) return path; @@ -252,7 +252,7 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ // searching as if this would be a global include. } else if (type == IncludeNext) { - const QFileInfo currentFileInfo(m_currentDoc->fileName()); + const QFileInfo currentFileInfo = m_currentDoc->filePath().toFileInfo(); const QString currentDirPath = cleanPath(currentFileInfo.dir().path()); auto headerPathsEnd = m_headerPaths.end(); auto headerPathsIt = m_headerPaths.begin(); @@ -372,7 +372,7 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc) if (!doc) return; - const QString fn = doc->fileName(); + const QString fn = doc->filePath().path(); if (m_processed.contains(fn)) return; @@ -457,7 +457,8 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include document->setLastModified(info.lastModified()); const Document::Ptr previousDocument = switchCurrentDocument(document); - const QByteArray preprocessedCode = m_preprocess.run(absoluteFileName, contents); + const QByteArray preprocessedCode = + m_preprocess.run(Utils::FilePath::fromString(absoluteFileName), contents); // { // QByteArray b(preprocessedCode); b.replace("\n", "<<<\n"); // qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData()); @@ -478,7 +479,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include document->setUtf8Source(preprocessedCode); document->keepSourceAndAST(); document->tokenize(); - document->check(m_workingCopy.contains(document->fileName()) ? Document::FullCheck + document->check(m_workingCopy.contains(document->filePath()) ? Document::FullCheck : Document::FastCheck); m_documentFinished(document); diff --git a/src/plugins/cppeditor/cppsourceprocessor_test.cpp b/src/plugins/cppeditor/cppsourceprocessor_test.cpp index e4c30f97c1..58e0fdf630 100644 --- a/src/plugins/cppeditor/cppsourceprocessor_test.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor_test.cpp @@ -21,7 +21,8 @@ #include <QtTest> using namespace CPlusPlus; -using ProjectExplorer::HeaderPathType; +using namespace ProjectExplorer; +using namespace Utils; using Include = Document::Include; using CppEditor::Tests::TestCase; @@ -46,7 +47,7 @@ public: TestIncludePaths::directoryOfTestFile())}); sourceProcessor->run(filePath); - Document::Ptr document = m_cmm->document(filePath); + Document::Ptr document = m_cmm->document(Utils::FilePath::fromString(filePath)); return document; } @@ -96,7 +97,8 @@ void SourceProcessorTest::testIncludesCyclic() { const QString fileName1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h")); const QString fileName2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h")); - const QSet<QString> sourceFiles = {fileName1, fileName2}; + const QSet<FilePath> sourceFiles = {FilePath::fromString(fileName1), + FilePath::fromString(fileName2)}; // Create global snapshot (needed in BuiltinEditorDocumentParser) TestCase testCase; @@ -104,7 +106,7 @@ void SourceProcessorTest::testIncludesCyclic() // Open editor TextEditor::BaseTextEditor *editor; - QVERIFY(testCase.openCppEditor(fileName1, &editor)); + QVERIFY(testCase.openCppEditor(FilePath::fromString(fileName1), &editor)); testCase.closeEditorAtEndOfTestCase(editor); // Check editor snapshot @@ -165,7 +167,7 @@ void SourceProcessorTest::testMacroUses() static bool isMacroDefinedInDocument(const QByteArray ¯oName, const Document::Ptr &document) { - for (const Macro ¯o : document->definedMacros()) { + for (const CPlusPlus::Macro ¯o : document->definedMacros()) { if (macro.name() == macroName) return true; } diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 2d83897e96..2633e41ffb 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -84,15 +84,15 @@ TestDocumentPtr CppTestDocument::create(const QByteArray &fileName, const QByteA return doc; } -QString CppTestDocument::filePath() const +FilePath CppTestDocument::filePath() const { if (!m_baseDirectory.isEmpty()) - return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName); + return FilePath::fromString(QDir::cleanPath(m_baseDirectory + '/' + m_fileName)); if (!QFileInfo(m_fileName).isAbsolute()) - return Utils::TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName; + return FilePath::fromString(TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName); - return m_fileName; + return FilePath::fromString(m_fileName); } bool CppTestDocument::writeToDisk() const @@ -212,11 +212,11 @@ bool TestCase::succeededSoFar() const return m_succeededSoFar; } -bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, +bool TestCase::openCppEditor(const FilePath &filePath, TextEditor::BaseTextEditor **editor, CppEditorWidget **editorWidget) { if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>( - Core::EditorManager::openEditor(FilePath::fromString(fileName)))) { + Core::EditorManager::openEditor(filePath))) { if (editor) { *editor = e; TextEditor::StorageSettings s = e->textDocument()->storageSettings(); @@ -281,16 +281,17 @@ CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEdito return editorWidget->semanticInfo().doc; } -bool TestCase::parseFiles(const QSet<QString> &filePaths) +bool TestCase::parseFiles(const QSet<FilePath> &filePaths) { - CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); + QSet<QString> filePaths_ = transform(filePaths, &FilePath::toString); + CppModelManager::instance()->updateSourceFiles(filePaths_).waitForFinished(); QCoreApplication::processEvents(); const CPlusPlus::Snapshot snapshot = globalSnapshot(); if (snapshot.isEmpty()) { qWarning("After parsing: snapshot is empty."); return false; } - if (!snapshotContains(snapshot, filePaths)) { + if (!snapshotContains(snapshot, filePaths_)) { qWarning("After parsing: snapshot does not contain all expected files."); return false; } @@ -299,7 +300,7 @@ bool TestCase::parseFiles(const QSet<QString> &filePaths) bool TestCase::parseFiles(const QString &filePath) { - return parseFiles(QSet<QString>{filePath}); + return parseFiles({FilePath::fromString(filePath)}); } void TestCase::closeEditorAtEndOfTestCase(Core::IEditor *editor) @@ -355,11 +356,11 @@ bool TestCase::waitUntilProjectIsFullyOpened(Project *project, int timeOutInMs) timeOutInMs); } -bool TestCase::writeFile(const QString &filePath, const QByteArray &contents) +bool TestCase::writeFile(const FilePath &filePath, const QByteArray &contents) { - Utils::FileSaver saver(Utils::FilePath::fromString(filePath)); + Utils::FileSaver saver(filePath); if (!saver.write(contents) || !saver.finalize()) { - qWarning() << "Failed to write file to disk:" << qPrintable(filePath); + qWarning() << "Failed to write file to disk:" << qPrintable(filePath.toUserOutput()); return false; } return true; @@ -419,15 +420,15 @@ TemporaryDir::TemporaryDir() { } -QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArray &contents) +FilePath TemporaryDir::createFile(const QByteArray &relativePath, const QByteArray &contents) { const QString relativePathString = QString::fromUtf8(relativePath); if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute()) - return QString(); + return {}; - const QString filePath = m_temporaryDir.filePath(relativePathString).path(); + const FilePath filePath = m_temporaryDir.filePath(relativePathString); if (!TestCase::writeFile(filePath, contents)) - return QString(); + return {}; return filePath; } diff --git a/src/plugins/cppeditor/cpptoolstestcase.h b/src/plugins/cppeditor/cpptoolstestcase.h index 600075463d..53284f38be 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.h +++ b/src/plugins/cppeditor/cpptoolstestcase.h @@ -60,7 +60,7 @@ public: QString baseDirectory() const { return m_baseDirectory; } void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; } - QString filePath() const; + Utils::FilePath filePath() const; bool writeToDisk() const; bool hasCursorMarker() const { return m_cursorPosition != -1; } @@ -123,14 +123,14 @@ public: ~TestCase(); bool succeededSoFar() const; - static bool openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, + static bool openCppEditor(const Utils::FilePath &filePath, TextEditor::BaseTextEditor **editor, CppEditorWidget **editorWidget = nullptr); void closeEditorAtEndOfTestCase(Core::IEditor *editor); static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor); static bool parseFiles(const QString &filePath); - static bool parseFiles(const QSet<QString> &filePaths); + static bool parseFiles(const QSet<Utils::FilePath> &filePaths); static CPlusPlus::Snapshot globalSnapshot(); static bool garbageCollectGlobalSnapshot(); @@ -149,7 +149,7 @@ public: const QStringList &filePaths, int timeOutInMs = defaultTimeOutInMs); - static bool writeFile(const QString &filePath, const QByteArray &contents); + static bool writeFile(const Utils::FilePath &filePath, const QByteArray &contents); protected: CppModelManager *m_modelManager; @@ -184,8 +184,9 @@ public: bool isValid() const { return m_isValid; } QString path() const { return m_temporaryDir.path().path(); } + Utils::FilePath filePath() const { return m_temporaryDir.path(); } - QString createFile(const QByteArray &relativePath, const QByteArray &contents); + Utils::FilePath createFile(const QByteArray &relativePath, const QByteArray &contents); protected: Utils::TemporaryDirectory m_temporaryDir; diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 0b781168bd..c5602c5f67 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -51,6 +51,7 @@ using namespace Core; using namespace CPlusPlus; using namespace TextEditor; +using namespace Utils; namespace CppEditor::Internal::Tests { @@ -158,7 +159,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti QCOMPARE(DocumentModel::openedDocuments().size(), 0); BaseTextEditor *editor; CppEditorWidget *editorWidget; - QVERIFY(openCppEditor(filePath, &editor, &editorWidget)); + QVERIFY(openCppEditor(FilePath::fromString(filePath), &editor, &editorWidget)); QCOMPARE(DocumentModel::openedDocuments().size(), 1); QVERIFY(m_modelManager->isCppEditor(editor)); diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 38cd0cdebc..c15995504e 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -62,6 +62,7 @@ using namespace CPlusPlus; using namespace TextEditor; using namespace Core; using namespace ProjectExplorer; +using namespace Utils; class OverrideItem { @@ -256,7 +257,8 @@ F2TestCase::F2TestCase(CppEditorAction action, QVERIFY(testFile->baseDirectory().isEmpty()); testFile->setBaseDirectory(temporaryDir.path()); QVERIFY(testFile->writeToDisk()); - projectFileContent += QString::fromLatin1("\"%1\",").arg(testFile->filePath()); + projectFileContent += QString::fromLatin1("\"%1\",") + .arg(testFile->filePath().toString()); } projectFileContent += "]}\n"; @@ -272,9 +274,7 @@ F2TestCase::F2TestCase(CppEditorAction action, CppTestDocument projectFile("project.qbs", projectFileContent.toUtf8()); projectFile.setBaseDirectory(temporaryDir.path()); QVERIFY(projectFile.writeToDisk()); - const auto openProjectResult = - ProjectExplorerPlugin::openProject( - Utils::FilePath::fromString(projectFile.filePath())); + const auto openProjectResult = ProjectExplorerPlugin::openProject(projectFile.filePath()); QVERIFY2(openProjectResult && openProjectResult.project(), qPrintable(openProjectResult.errorMessage())); projectCloser.setProject(openProjectResult.project()); @@ -286,7 +286,7 @@ F2TestCase::F2TestCase(CppEditorAction action, } // Update Code Model - QSet<QString> filePaths; + QSet<FilePath> filePaths; for (const TestDocumentPtr &testFile : testFiles) filePaths << testFile->filePath(); QVERIFY(parseFiles(filePaths)); @@ -302,7 +302,8 @@ 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()); + const Document::Ptr document = + waitForFileInGlobalSnapshot(testFile->filePath().toString()); QVERIFY(document); if (document->checkMode() == Document::FullCheck) { if (!document->diagnosticMessages().isEmpty()) @@ -405,7 +406,7 @@ F2TestCase::F2TestCase(CppEditorAction action, BaseTextEditor *currentTextEditor = dynamic_cast<BaseTextEditor*>(currentEditor); QVERIFY(currentTextEditor); - QCOMPARE(currentTextEditor->document()->filePath().toString(), targetTestFile->filePath()); + QCOMPARE(currentTextEditor->document()->filePath(), targetTestFile->filePath()); int expectedLine, expectedColumn; if (useClangd && expectedVirtualFunctionProposal.size() == 1) { expectedLine = expectedVirtualFunctionProposal.first().line; diff --git a/src/plugins/cppeditor/includeutils.cpp b/src/plugins/cppeditor/includeutils.cpp index cf855f154f..f79bb8db12 100644 --- a/src/plugins/cppeditor/includeutils.cpp +++ b/src/plugins/cppeditor/includeutils.cpp @@ -518,7 +518,7 @@ static QList<Include> includesForSource(const QString &filePath) TestIncludePaths::globalIncludePath())}); sourceProcessor->run(filePath); - Document::Ptr document = cmm->document(filePath); + Document::Ptr document = cmm->document(FilePath::fromString(filePath)); return document->resolvedIncludes(); } diff --git a/src/plugins/cppeditor/insertionpointlocator.cpp b/src/plugins/cppeditor/insertionpointlocator.cpp index 4479246f61..a0aa777cc6 100644 --- a/src/plugins/cppeditor/insertionpointlocator.cpp +++ b/src/plugins/cppeditor/insertionpointlocator.cpp @@ -251,13 +251,12 @@ InsertionPointLocator::InsertionPointLocator(const CppRefactoringChanges &refact } InsertionLocation InsertionPointLocator::methodDeclarationInClass( - const QString &fileName, + const Utils::FilePath &filePath, const Class *clazz, AccessSpec xsSpec, ForceAccessSpec forceAccessSpec) const { - const Document::Ptr doc = m_refactoringChanges.file(Utils::FilePath::fromString(fileName)) - ->cppDocument(); + const Document::Ptr doc = m_refactoringChanges.file(filePath)->cppDocument(); if (doc) { FindInClass find(doc->translationUnit(), clazz); ClassSpecifierAST *classAST = find(); diff --git a/src/plugins/cppeditor/insertionpointlocator.h b/src/plugins/cppeditor/insertionpointlocator.h index b9133e67e2..8dc5f561a7 100644 --- a/src/plugins/cppeditor/insertionpointlocator.h +++ b/src/plugins/cppeditor/insertionpointlocator.h @@ -80,8 +80,7 @@ public: public: explicit InsertionPointLocator(const CppRefactoringChanges &refactoringChanges); - InsertionLocation methodDeclarationInClass( - const QString &fileName, + InsertionLocation methodDeclarationInClass(const Utils::FilePath &fileName, const CPlusPlus::Class *clazz, AccessSpec xsSpec, ForceAccessSpec forceAccessSpec = ForceAccessSpec::No diff --git a/src/plugins/cppeditor/searchsymbols.cpp b/src/plugins/cppeditor/searchsymbols.cpp index 0fa87c4b11..6eb143a276 100644 --- a/src/plugins/cppeditor/searchsymbols.cpp +++ b/src/plugins/cppeditor/searchsymbols.cpp @@ -37,7 +37,7 @@ void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types) IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope) { - IndexItem::Ptr root = IndexItem::create(Internal::StringTable::insert(doc->fileName()), 100); + IndexItem::Ptr root = IndexItem::create(Internal::StringTable::insert(doc->filePath()), 100); { // RAII scope ScopedIndexItemPtr parentRaii(_parent, root); @@ -46,7 +46,7 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope QTC_ASSERT(_parent, return IndexItem::Ptr()); QTC_ASSERT(root, return IndexItem::Ptr()); - QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->fileName()), + QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->filePath()), return IndexItem::Ptr()); for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i) diff --git a/src/plugins/cppeditor/stringtable.cpp b/src/plugins/cppeditor/stringtable.cpp index 6f0ef89b18..64f324ad36 100644 --- a/src/plugins/cppeditor/stringtable.cpp +++ b/src/plugins/cppeditor/stringtable.cpp @@ -56,6 +56,11 @@ StringTablePrivate::StringTablePrivate() connect(&m_gcCountDown, &QTimer::timeout, this, &StringTablePrivate::startGC); } +QString StringTable::insert(const Utils::FilePath &path) +{ + return m_instance->insert(path.path()); +} + QString StringTable::insert(const QString &string) { return m_instance->insert(string); diff --git a/src/plugins/cppeditor/stringtable.h b/src/plugins/cppeditor/stringtable.h index d24d77c02e..675d3f6539 100644 --- a/src/plugins/cppeditor/stringtable.h +++ b/src/plugins/cppeditor/stringtable.h @@ -3,13 +3,14 @@ #pragma once -#include <QString> +#include <utils/filepath.h> namespace CppEditor::Internal { class StringTable { public: + static QString insert(const Utils::FilePath &string); static QString insert(const QString &string); static void scheduleGC(); diff --git a/src/plugins/cppeditor/symbolfinder.cpp b/src/plugins/cppeditor/symbolfinder.cpp index df93d36246..484dfd6e1b 100644 --- a/src/plugins/cppeditor/symbolfinder.cpp +++ b/src/plugins/cppeditor/symbolfinder.cpp @@ -444,7 +444,7 @@ QStringList SymbolFinder::fileIterationOrder(const QString &referenceFile, const checkCacheConsistency(referenceFile, snapshot); } else { for (Document::Ptr doc : snapshot) - insertCache(referenceFile, doc->fileName()); + insertCache(referenceFile, doc->filePath().path()); } QStringList files = m_filePriorityCache.value(referenceFile).toStringList(); @@ -468,8 +468,8 @@ void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Sna // corresponding document and notices it's now null. const QSet<QString> &meta = m_fileMetaCache.value(referenceFile); for (const Document::Ptr &doc : snapshot) { - if (!meta.contains(doc->fileName())) - insertCache(referenceFile, doc->fileName()); + if (!meta.contains(doc->filePath().path())) + insertCache(referenceFile, doc->filePath().path()); } } diff --git a/src/plugins/cppeditor/typehierarchybuilder_test.cpp b/src/plugins/cppeditor/typehierarchybuilder_test.cpp index c1509df12f..095aba97ea 100644 --- a/src/plugins/cppeditor/typehierarchybuilder_test.cpp +++ b/src/plugins/cppeditor/typehierarchybuilder_test.cpp @@ -16,6 +16,8 @@ #include <QtTest> using namespace CPlusPlus; +using namespace Utils; + using CppEditor::Internal::Tests::CppTestDocument; Q_DECLARE_METATYPE(QList<CppTestDocument>) @@ -82,7 +84,7 @@ public: QList<CppTestDocument> documents_ = documents; // Write files - QSet<QString> filePaths; + QSet<FilePath> filePaths; for (auto &document : documents_) { document.setBaseDirectory(temporaryDir.path()); QVERIFY(document.writeToDisk()); |