diff options
author | hjk <hjk@qt.io> | 2022-11-24 13:05:41 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-30 17:27:56 +0000 |
commit | 39ffdb416ff3381515b7b4bf579acb23941cd6fc (patch) | |
tree | 544fd0f432246e397c3b851ed35d2b6d297dc661 | |
parent | dc3a4f0002b2c8e4c437b2d6b3bf9e2e4be91a19 (diff) |
CPlusPlus: Use FilePath for resolved include paths
... and fix fallout.
Change-Id: I66886e91ff476eff15db51cc024a8021e952d44d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
25 files changed, 136 insertions, 124 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index 5167e9ad2c..ac4986fb1a 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -299,11 +299,11 @@ void Document::setLastModified(const QDateTime &lastModified) FilePaths Document::includedFiles() const { - QStringList files; + FilePaths files; for (const Include &i : std::as_const(_resolvedIncludes)) files.append(i.resolvedFileName()); - files.removeDuplicates(); - return transform(files, &FilePath::fromString); + FilePath::removeDuplicates(files); + return files; } // This assumes to be called with a QDir::cleanPath cleaned fileName. @@ -786,13 +786,13 @@ QSet<FilePath> Snapshot::allIncludesForDocument(const FilePath &filePath) const } QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument( - const QString &fileNameOrPath) const + const FilePath &fileNameOrPath) const { - const bool matchFullPath = FilePath::fromString(fileNameOrPath).isAbsolutePath(); + const bool matchFullPath = fileNameOrPath.isAbsolutePath(); const auto isMatch = [&](const Document::Include &include) { if (matchFullPath) return include.resolvedFileName() == fileNameOrPath; - return FilePath::fromString(include.resolvedFileName()).fileName() == fileNameOrPath; + return include.resolvedFileName().fileName() == fileNameOrPath.fileName(); }; QList<IncludeLocation> result; for (const_iterator cit = begin(), citEnd = end(); cit != citEnd; ++cit) { @@ -807,7 +807,7 @@ QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument( } if (!matchFullPath && !foundMatch) { for (const auto &includeFile : cit.value()->unresolvedIncludes()) { - if (includeFile.unresolvedFileName() == fileNameOrPath) + if (includeFile.unresolvedFileName() == fileNameOrPath.path()) result.push_back({doc, includeFile.line()}); } } diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index 599b8cbc71..44d880ccf6 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -218,13 +218,13 @@ public: }; class Include { - QString _resolvedFileName; + Utils::FilePath _resolvedFileName; QString _unresolvedFileName; int _line; Client::IncludeType _type; public: - Include(const QString &unresolvedFileName, const QString &resolvedFileName, int line, + Include(const QString &unresolvedFileName, const Utils::FilePath &resolvedFileName, int line, Client::IncludeType type) : _resolvedFileName(resolvedFileName) , _unresolvedFileName(unresolvedFileName) @@ -232,7 +232,7 @@ public: , _type(type) { } - const QString &resolvedFileName() const + const Utils::FilePath &resolvedFileName() const { return _resolvedFileName; } const QString &unresolvedFileName() const @@ -404,7 +404,7 @@ public: QSet<Utils::FilePath> allIncludesForDocument(const Utils::FilePath &filePath) const; - QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const; + QList<IncludeLocation> includeLocationsOfDocument(const Utils::FilePath &fileNameOrPath) const; Utils::FilePaths filesDependingOn(const Utils::FilePath &filePath) const; diff --git a/src/libs/cplusplus/FastPreprocessor.cpp b/src/libs/cplusplus/FastPreprocessor.cpp index c948776c4b..8cc01e6250 100644 --- a/src/libs/cplusplus/FastPreprocessor.cpp +++ b/src/libs/cplusplus/FastPreprocessor.cpp @@ -29,11 +29,11 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc, _preproc.setKeepComments(true); if (Document::Ptr doc = _snapshot.document(filePath)) { - _merged.insert(filePath.toString()); + _merged.insert(filePath); for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) { if (isInjectedFile(i.key().toString())) - mergeEnvironment(i.key().toString()); + mergeEnvironment(i.key()); } const QList<Document::Include> includes = doc->resolvedIncludes(); @@ -55,20 +55,21 @@ void FastPreprocessor::sourceNeeded(int line, const QString &fileName, IncludeTy { Q_UNUSED(initialIncludes) Q_ASSERT(_currentDoc); + FilePath filePath = FilePath::fromString(fileName); if (_addIncludesToCurrentDoc) { - // CHECKME: Is that cleanName needed? - const QString cleanName = QDir::cleanPath(fileName); - _currentDoc->addIncludeFile(Document::Include(fileName, cleanName, line, mode)); + // CHECKME: Is that cleanPath needed? + const FilePath cleanPath = filePath.cleanPath(); + _currentDoc->addIncludeFile(Document::Include(fileName, cleanPath, line, mode)); } - mergeEnvironment(fileName); + mergeEnvironment(filePath); } -void FastPreprocessor::mergeEnvironment(const QString &fileName) +void FastPreprocessor::mergeEnvironment(const FilePath &filePath) { - if (! _merged.contains(fileName)) { - _merged.insert(fileName); + if (! _merged.contains(filePath)) { + _merged.insert(filePath); - if (Document::Ptr doc = _snapshot.document(fileName)) { + if (Document::Ptr doc = _snapshot.document(filePath)) { const QList<Document::Include> includes = doc->resolvedIncludes(); for (const Document::Include &i : includes) mergeEnvironment(i.resolvedFileName()); diff --git a/src/libs/cplusplus/FastPreprocessor.h b/src/libs/cplusplus/FastPreprocessor.h index 0892e120b4..c4f30063fa 100644 --- a/src/libs/cplusplus/FastPreprocessor.h +++ b/src/libs/cplusplus/FastPreprocessor.h @@ -3,12 +3,15 @@ #pragma once -#include "PreprocessorClient.h" #include "CppDocument.h" -#include "pp.h" +#include "PreprocessorClient.h" +#include "PreprocessorEnvironment.h" +#include "pp-engine.h" #include <cplusplus/Control.h> +#include <utils/filepath.h> + #include <QSet> #include <QString> @@ -19,11 +22,11 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client Environment _env; Snapshot _snapshot; Preprocessor _preproc; - QSet<QString> _merged; + QSet<Utils::FilePath> _merged; Document::Ptr _currentDoc; bool _addIncludesToCurrentDoc; - void mergeEnvironment(const QString &fileName); + void mergeEnvironment(const Utils::FilePath &filePath); public: FastPreprocessor(const Snapshot &snapshot); diff --git a/src/plugins/autotest/boost/boosttestparser.cpp b/src/plugins/autotest/boost/boosttestparser.cpp index c3cde92fa0..2a514c8b9d 100644 --- a/src/plugins/autotest/boost/boosttestparser.cpp +++ b/src/plugins/autotest/boost/boosttestparser.cpp @@ -55,7 +55,7 @@ static bool includesBoostTest(const CPlusPlus::Document::Ptr &doc, { static const QRegularExpression boostTestHpp("^.*/boost/test/.*\\.hpp$"); for (const CPlusPlus::Document::Include &inc : doc->resolvedIncludes()) { - if (boostTestHpp.match(inc.resolvedFileName()).hasMatch()) + if (boostTestHpp.match(inc.resolvedFileName().path()).hasMatch()) return true; } diff --git a/src/plugins/cppeditor/cppcodegen_test.cpp b/src/plugins/cppeditor/cppcodegen_test.cpp index 72e702d89c..49522e8cb0 100644 --- a/src/plugins/cppeditor/cppcodegen_test.cpp +++ b/src/plugins/cppeditor/cppcodegen_test.cpp @@ -388,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->filePath().toString(), 1, + headerDocument->filePath(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -447,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->filePath().toString(), 1, + headerDocument->filePath(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -513,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->filePath().toString(), 1, + headerDocument->filePath(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -573,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->filePath().toString(), 1, + headerDocument->filePath(), 1, Client::IncludeLocal)); Snapshot snapshot; @@ -636,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->filePath().toString(), 1, + headerDocument->filePath(), 1, Client::IncludeLocal)); Snapshot snapshot; diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 1f2349f113..b8af9a2b1b 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -588,7 +588,7 @@ QVariant IncludesModel::data(const QModelIndex &index, int role) const static const QBrush redBrush(QColor(205, 38, 38)); const Document::Include include = m_includes.at(index.row()); - const QString resolvedFileName = QDir::toNativeSeparators(include.resolvedFileName()); + const FilePath resolvedFileName = include.resolvedFileName(); const bool isResolved = !resolvedFileName.isEmpty(); if (role == Qt::DisplayRole) { @@ -599,7 +599,7 @@ QVariant IncludesModel::data(const QModelIndex &index, int role) const return include.line(); } else if (column == FilePathsColumn) { return QVariant(CMI::Utils::unresolvedFileNameWithDelimiters(include) - + QLatin1String(" --> ") + resolvedFileName); + + QLatin1String(" --> ") + resolvedFileName.toUserOutput()); } } else if (role == Qt::ForegroundRole) { return isResolved ? greenBrush : redBrush; diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 0e68454d09..649a0b5ad9 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -1479,8 +1479,8 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope) completeNamespace(b); addKeywords(); - addMacros(CppModelManager::configurationFileName().path(), context.snapshot()); - addMacros(context.thisDocument()->filePath().toString(), context.snapshot()); + addMacros(CppModelManager::configurationFileName(), context.snapshot()); + addMacros(context.thisDocument()->filePath(), context.snapshot()); addSnippets(); return !m_completions.isEmpty(); } @@ -1841,29 +1841,29 @@ void InternalCppCompletionAssistProcessor::addKeywords() } } -void InternalCppCompletionAssistProcessor::addMacros(const QString &fileName, +void InternalCppCompletionAssistProcessor::addMacros(const Utils::FilePath &filePath, const Snapshot &snapshot) { - QSet<QString> processed; + QSet<Utils::FilePath> processed; QSet<QString> definedMacros; - addMacros_helper(snapshot, fileName, &processed, &definedMacros); + addMacros_helper(snapshot, filePath, &processed, &definedMacros); for (const QString ¯oName : std::as_const(definedMacros)) addCompletionItem(macroName, Icons::macroIcon(), MacrosOrder); } void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snapshot, - const QString &fileName, - QSet<QString> *processed, + const Utils::FilePath &filePath, + QSet<Utils::FilePath> *processed, QSet<QString> *definedMacros) { - Document::Ptr doc = snapshot.document(fileName); + Document::Ptr doc = snapshot.document(filePath); - if (!doc || processed->contains(doc->filePath().path())) + if (!doc || processed->contains(doc->filePath())) return; - processed->insert(doc->filePath().path()); + processed->insert(doc->filePath()); const QList<Document::Include> includes = doc->resolvedIncludes(); for (const Document::Include &i : includes) diff --git a/src/plugins/cppeditor/cppcompletionassist.h b/src/plugins/cppeditor/cppcompletionassist.h index fbfdd209ca..4d986bb114 100644 --- a/src/plugins/cppeditor/cppcompletionassist.h +++ b/src/plugins/cppeditor/cppcompletionassist.h @@ -122,10 +122,10 @@ private: void addCompletionItem(CPlusPlus::Symbol *symbol, int order = 0); void addKeywords(); - void addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot); + void addMacros(const Utils::FilePath &filePath, const CPlusPlus::Snapshot &snapshot); void addMacros_helper(const CPlusPlus::Snapshot &snapshot, - const QString &fileName, - QSet<QString> *processed, + const Utils::FilePath &filePath, + QSet<Utils::FilePath> *processed, QSet<QString> *definedMacros); enum { diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index e835e0443b..225bfe44b7 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -21,6 +21,7 @@ #include <QSet> using namespace CPlusPlus; +using namespace Utils; namespace CppEditor::Internal { @@ -62,18 +63,18 @@ class CppInclude : public CppElement { public: explicit CppInclude(const Document::Include &includeFile) - : path(QDir::toNativeSeparators(includeFile.resolvedFileName())) - , fileName(Utils::FilePath::fromString(includeFile.resolvedFileName()).fileName()) + : path(includeFile.resolvedFileName()) + , fileName(path.fileName()) { helpCategory = Core::HelpItem::Brief; helpIdCandidates = QStringList(fileName); helpMark = fileName; - link = Utils::Link(Utils::FilePath::fromString(path)); - tooltip = path; + link = Utils::Link(path); + tooltip = path.toUserOutput(); } public: - QString path; + Utils::FilePath path; QString fileName; }; @@ -95,7 +96,7 @@ public: CppDeclarableElement::CppDeclarableElement(Symbol *declaration) : CppElement() , declaration(declaration) - , icon(Icons::iconForSymbol(declaration)) + , icon(CPlusPlus::Icons::iconForSymbol(declaration)) { Overview overview; overview.showArgumentNames = true; diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index 78bff45329..9a73448bd5 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -624,7 +624,7 @@ void FollowSymbolUnderCursor::findLink( const QList<Document::Include> includes = doc->resolvedIncludes(); for (const Document::Include &incl : includes) { if (incl.line() == lineno) { - link.targetFilePath = Utils::FilePath::fromString(incl.resolvedFileName()); + link.targetFilePath = incl.resolvedFileName(); link.linkTextStart = beginOfToken + 1; link.linkTextEnd = endOfToken - 1; processLinkCallback(link); diff --git a/src/plugins/cppeditor/cppincludehierarchy.cpp b/src/plugins/cppeditor/cppincludehierarchy.cpp index d9211aebed..6f6a878109 100644 --- a/src/plugins/cppeditor/cppincludehierarchy.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy.cpp @@ -58,24 +58,24 @@ static Snapshot globalSnapshot() struct FileAndLine { FileAndLine() = default; - FileAndLine(const QString &f, int l) : file(f), line(l) {} + FileAndLine(const FilePath &f, int l) : file(f), line(l) {} - QString file; + FilePath file; int line = 0; }; using FileAndLines = QList<FileAndLine>; -static FileAndLines findIncluders(const QString &filePath) +static FileAndLines findIncluders(const FilePath &filePath) { FileAndLines result; const Snapshot snapshot = globalSnapshot(); for (auto cit = snapshot.begin(), citEnd = snapshot.end(); cit != citEnd; ++cit) { - const QString filePathFromSnapshot = cit.key().toString(); + const FilePath filePathFromSnapshot = cit.key(); Document::Ptr doc = cit.value(); const QList<Document::Include> resolvedIncludes = doc->resolvedIncludes(); for (const auto &includeFile : resolvedIncludes) { - const QString includedFilePath = includeFile.resolvedFileName(); + const FilePath includedFilePath = includeFile.resolvedFileName(); if (includedFilePath == filePath) result.append(FileAndLine(filePathFromSnapshot, int(includeFile.line()))); } @@ -83,7 +83,7 @@ static FileAndLines findIncluders(const QString &filePath) return result; } -static FileAndLines findIncludes(const QString &filePath, const Snapshot &snapshot) +static FileAndLines findIncludes(const FilePath &filePath, const Snapshot &snapshot) { FileAndLines result; if (Document::Ptr doc = snapshot.document(filePath)) { @@ -101,11 +101,11 @@ public: enum SubTree { RootItem, InIncludes, InIncludedBy }; CppIncludeHierarchyItem() = default; - void createChild(const QString &filePath, SubTree subTree, + void createChild(const FilePath &filePath, SubTree subTree, int line = 0, bool definitelyNoChildren = false) { auto item = new CppIncludeHierarchyItem; - item->m_fileName = filePath.mid(filePath.lastIndexOf('/') + 1); + item->m_fileName = filePath.fileName(); item->m_filePath = filePath; item->m_line = line; item->m_subTree = subTree; @@ -120,7 +120,7 @@ public: item->setChildrenChecked(); } - QString filePath() const + FilePath filePath() const { return isPhony() ? model()->editorFilePath() : m_filePath; } @@ -138,7 +138,7 @@ private: Qt::ItemFlags flags(int) const override { - const Utils::Link link(Utils::FilePath::fromString(m_filePath), m_line); + const Utils::Link link(m_filePath, m_line); if (link.hasValidTarget()) return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable; @@ -148,7 +148,7 @@ private: void fetchMore() override; QString m_fileName; - QString m_filePath; + FilePath m_filePath; int m_line = 0; SubTree m_subTree = RootItem; bool m_isCyclic = false; @@ -171,11 +171,11 @@ QVariant CppIncludeHierarchyItem::data(int column, int role) const switch (role) { case Qt::ToolTipRole: - return m_filePath; + return m_filePath.displayName(); case Qt::DecorationRole: - return FileIconProvider::icon(FilePath::fromString(m_filePath)); + return FileIconProvider::icon(m_filePath); case LinkRole: - return QVariant::fromValue(Link(FilePath::fromString(m_filePath), m_line)); + return QVariant::fromValue(Link(m_filePath, m_line)); } return QVariant(); @@ -197,7 +197,7 @@ void CppIncludeHierarchyItem::fetchMore() model()->m_seen.insert(m_filePath); - const FilePath editorFilePath = FilePath::fromString(model()->editorFilePath()); + const FilePath editorFilePath = model()->editorFilePath(); setChildrenChecked(); if (m_subTree == InIncludes) { @@ -220,12 +220,14 @@ void CppIncludeHierarchyItem::fetchMore() } } -void CppIncludeHierarchyModel::buildHierarchy(const QString &document) +void CppIncludeHierarchyModel::buildHierarchy(const FilePath &document) { m_editorFilePath = document; rootItem()->removeChildren(); - rootItem()->createChild(tr("Includes"), CppIncludeHierarchyItem::InIncludes); - rootItem()->createChild(tr("Included by"), CppIncludeHierarchyItem::InIncludedBy); + rootItem()->createChild(FilePath::fromPathPart(tr("Includes")), + CppIncludeHierarchyItem::InIncludes); + rootItem()->createChild(FilePath::fromPathPart(tr("Included by")), + CppIncludeHierarchyItem::InIncludedBy); } void CppIncludeHierarchyModel::setSearching(bool on) @@ -411,7 +413,7 @@ void CppIncludeHierarchyWidget::perform() return; const Utils::FilePath documentPath = m_editor->textDocument()->filePath(); - m_model.buildHierarchy(documentPath.toString()); + m_model.buildHierarchy(documentPath); m_inspectedFile->setText(m_editor->textDocument()->displayName()); m_inspectedFile->setLink(Utils::Link(documentPath)); diff --git a/src/plugins/cppeditor/cppincludehierarchy.h b/src/plugins/cppeditor/cppincludehierarchy.h index ff1693755c..a9712ce73b 100644 --- a/src/plugins/cppeditor/cppincludehierarchy.h +++ b/src/plugins/cppeditor/cppincludehierarchy.h @@ -25,8 +25,8 @@ public: QStringList mimeTypes() const override; QMimeData *mimeData(const QModelIndexList &indexes) const override; - void buildHierarchy(const QString &filePath); - QString editorFilePath() const { return m_editorFilePath; } + void buildHierarchy(const Utils::FilePath &filePath); + const Utils::FilePath &editorFilePath() const { return m_editorFilePath; } void setSearching(bool on); QString toString() const; @@ -37,8 +37,8 @@ public: private: friend class CppIncludeHierarchyItem; - QString m_editorFilePath; - QSet<QString> m_seen; + Utils::FilePath m_editorFilePath; + QSet<Utils::FilePath> m_seen; bool m_searching = false; }; diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp index d3d0bf0397..a895341d51 100644 --- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp @@ -82,7 +82,7 @@ public: // Test model CppIncludeHierarchyModel model; - model.buildHierarchy(editor->document()->filePath().toString()); + model.buildHierarchy(editor->document()->filePath()); const QString actualHierarchy = toString(model); QCOMPARE(actualHierarchy, expectedHierarchy); } diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index cce4594704..1f22b3e08b 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1794,7 +1794,7 @@ void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath, return; const QList<Snapshot::IncludeLocation> locations = snapshot().includeLocationsOfDocument( - isUiFile ? oldFileName : oldFilePath.toString()); + isUiFile ? FilePath::fromString(oldFileName) : oldFilePath); for (const Snapshot::IncludeLocation &loc : locations) { const FilePath filePath = loc.first->filePath(); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 91181b91f5..46a31e1a87 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -8031,7 +8031,7 @@ private: Node &node = includeGraph[filePath]; node.document = doc; for (const Document::Include &include : doc->resolvedIncludes()) { - const auto filePath = FilePath::fromString(include.resolvedFileName()); + const FilePath filePath = include.resolvedFileName(); if (shouldHandle(filePath)) { Node &includedNode = includeGraph[filePath]; includedNode.includedBy.push_back(node); @@ -8105,7 +8105,7 @@ private: refactoring.snapshot(), currentFile->endOf(m_usingDirective), true)) { - processIncludes(refactoring, filePath().toString()); + processIncludes(refactoring, filePath()); } for (auto &file : std::as_const(m_changes)) @@ -8143,10 +8143,10 @@ private: return visitor.isGlobalUsingNamespace() && !visitor.foundGlobalUsingNamespace(); } - void processIncludes(CppRefactoringChanges &refactoring, const QString &fileName) + void processIncludes(CppRefactoringChanges &refactoring, const FilePath &filePath) { QList<Snapshot::IncludeLocation> - includeLocationsOfDocument = refactoring.snapshot().includeLocationsOfDocument(fileName); + includeLocationsOfDocument = refactoring.snapshot().includeLocationsOfDocument(filePath); for (Snapshot::IncludeLocation &loc : includeLocationsOfDocument) { if (m_processed.contains(loc.first)) continue; @@ -8157,7 +8157,7 @@ private: file->position(loc.second, 1)); m_processed.insert(loc.first); if (noGlobalUsing) - processIncludes(refactoring, loc.first->filePath().toString()); + processIncludes(refactoring, loc.first->filePath()); } } diff --git a/src/plugins/cppeditor/cppsourceprocessertesthelper.cpp b/src/plugins/cppeditor/cppsourceprocessertesthelper.cpp index df55e8b159..bf166625d3 100644 --- a/src/plugins/cppeditor/cppsourceprocessertesthelper.cpp +++ b/src/plugins/cppeditor/cppsourceprocessertesthelper.cpp @@ -3,8 +3,12 @@ #include "cppsourceprocessertesthelper.h" +#include <utils/filepath.h> + #include <QDir> +using namespace Utils; + namespace CppEditor::Tests::Internal { QString TestIncludePaths::includeBaseDirectory() @@ -28,9 +32,9 @@ QString TestIncludePaths::directoryOfTestFile() return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/local")); } -QString TestIncludePaths::testFilePath(const QString &fileName) +FilePath TestIncludePaths::testFilePath(const QString &fileName) { - return directoryOfTestFile() + QLatin1Char('/') + fileName; + return FilePath::fromString(directoryOfTestFile()) / fileName; } -} // namespace CppEditor::Tests::Internal +} // CppEditor::Tests::Internal diff --git a/src/plugins/cppeditor/cppsourceprocessertesthelper.h b/src/plugins/cppeditor/cppsourceprocessertesthelper.h index ba6428f77c..69f82156b6 100644 --- a/src/plugins/cppeditor/cppsourceprocessertesthelper.h +++ b/src/plugins/cppeditor/cppsourceprocessertesthelper.h @@ -6,6 +6,8 @@ #include <QtGlobal> #include <QString> +namespace Utils { class FilePath; } + namespace CppEditor::Tests::Internal { class TestIncludePaths @@ -17,7 +19,7 @@ public: static QString globalQtCoreIncludePath(); static QString globalIncludePath(); static QString directoryOfTestFile(); - static QString testFilePath(const QString &fileName = QLatin1String("file.cpp")); + static Utils::FilePath testFilePath(const QString &fileName = QLatin1String("file.cpp")); }; -} // namespace CppEditor::Tests::Internal +} // CppEditor::Tests::Internal diff --git a/src/plugins/cppeditor/cppsourceprocessor.cpp b/src/plugins/cppeditor/cppsourceprocessor.cpp index 1e11b8939c..2cd0eafae1 100644 --- a/src/plugins/cppeditor/cppsourceprocessor.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor.cpp @@ -383,12 +383,12 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc) const QList<Document::Include> includes = doc->resolvedIncludes(); for (const Document::Include &incl : includes) { - const QString includedFile = incl.resolvedFileName(); + const FilePath includedFile = incl.resolvedFileName(); if (Document::Ptr includedDoc = m_snapshot.document(includedFile)) mergeEnvironment(includedDoc); - else if (!m_included.contains(FilePath::fromString(includedFile))) - run(includedFile); + else if (!m_included.contains(includedFile)) + run(includedFile.toString()); } m_env.addMacros(doc->definedMacros()); @@ -416,7 +416,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include const FilePath absoluteFilePath = FilePath::fromString(absoluteFileName); if (m_currentDoc) { - m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFileName, line, type)); + m_currentDoc->addIncludeFile(Document::Include(fileName, absoluteFilePath, line, type)); if (absoluteFileName.isEmpty()) { m_currentDoc->addDiagnosticMessage(messageNoSuchFile(m_currentDoc, fileName, line)); return; @@ -453,7 +453,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include document->setLanguageFeatures(m_languageFeatures); for (const QString &include : initialIncludes) { m_included.insert(FilePath::fromString(include)); - Document::Include inc(include, include, 0, IncludeLocal); + Document::Include inc(include, FilePath::fromString(include), 0, IncludeLocal); document->addIncludeFile(inc); } if (info.exists()) diff --git a/src/plugins/cppeditor/cppsourceprocessor_test.cpp b/src/plugins/cppeditor/cppsourceprocessor_test.cpp index 06b1748d8f..af617637f7 100644 --- a/src/plugins/cppeditor/cppsourceprocessor_test.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor_test.cpp @@ -39,15 +39,15 @@ public: cleanUp(); } - Document::Ptr run(const QString &filePath) const + Document::Ptr run(const FilePath &filePath) const { QScopedPointer<CppSourceProcessor> sourceProcessor( CppModelManager::createSourceProcessor()); sourceProcessor->setHeaderPaths({ProjectExplorer::HeaderPath::makeUser( TestIncludePaths::directoryOfTestFile())}); - sourceProcessor->run(filePath); + sourceProcessor->run(filePath.toString()); - Document::Ptr document = m_cmm->document(Utils::FilePath::fromString(filePath)); + Document::Ptr document = m_cmm->document(filePath); return document; } @@ -70,7 +70,7 @@ private: /// Check: Resolved and unresolved includes are properly tracked. void SourceProcessorTest::testIncludesResolvedUnresolved() { - const QString testFilePath + const FilePath testFilePath = TestIncludePaths::testFilePath(QLatin1String("test_main_resolvedUnresolved.cpp")); SourcePreprocessor processor; @@ -81,7 +81,7 @@ void SourceProcessorTest::testIncludesResolvedUnresolved() QCOMPARE(resolvedIncludes.size(), 1); QCOMPARE(resolvedIncludes.at(0).type(), Client::IncludeLocal); QCOMPARE(resolvedIncludes.at(0).unresolvedFileName(), QLatin1String("header.h")); - const QString expectedResolvedFileName + const FilePath expectedResolvedFileName = TestIncludePaths::testFilePath(QLatin1String("header.h")); QCOMPARE(resolvedIncludes.at(0).resolvedFileName(), expectedResolvedFileName); @@ -95,10 +95,9 @@ void SourceProcessorTest::testIncludesResolvedUnresolved() /// Check: Avoid self-include entries due to cyclic includes. void SourceProcessorTest::testIncludesCyclic() { - const QString fileName1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h")); - const QString fileName2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h")); - const QSet<FilePath> sourceFiles = {FilePath::fromString(fileName1), - FilePath::fromString(fileName2)}; + const FilePath filePath1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h")); + const FilePath filePath2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h")); + const QSet<FilePath> sourceFiles = {filePath1, filePath2}; // Create global snapshot (needed in BuiltinEditorDocumentParser) TestCase testCase; @@ -106,7 +105,7 @@ void SourceProcessorTest::testIncludesCyclic() // Open editor TextEditor::BaseTextEditor *editor; - QVERIFY(testCase.openCppEditor(FilePath::fromString(fileName1), &editor)); + QVERIFY(testCase.openCppEditor(filePath1, &editor)); testCase.closeEditorAtEndOfTestCase(editor); // Check editor snapshot @@ -118,24 +117,24 @@ void SourceProcessorTest::testIncludesCyclic() QCOMPARE(snapshot.size(), 3); // Configuration file included // Check includes - Document::Ptr doc1 = snapshot.document(fileName1); + Document::Ptr doc1 = snapshot.document(filePath1); QVERIFY(doc1); - Document::Ptr doc2 = snapshot.document(fileName2); + Document::Ptr doc2 = snapshot.document(filePath2); QVERIFY(doc2); QCOMPARE(doc1->unresolvedIncludes().size(), 0); QCOMPARE(doc1->resolvedIncludes().size(), 1); - QCOMPARE(doc1->resolvedIncludes().first().resolvedFileName(), fileName2); + QCOMPARE(doc1->resolvedIncludes().first().resolvedFileName(), filePath2); QCOMPARE(doc2->unresolvedIncludes().size(), 0); QCOMPARE(doc2->resolvedIncludes().size(), 1); - QCOMPARE(doc2->resolvedIncludes().first().resolvedFileName(), fileName1); + QCOMPARE(doc2->resolvedIncludes().first().resolvedFileName(), filePath1); } /// Check: All include errors are reported as diagnostic messages. void SourceProcessorTest::testIncludesAllDiagnostics() { - const QString testFilePath + const FilePath testFilePath = TestIncludePaths::testFilePath(QLatin1String("test_main_allDiagnostics.cpp")); SourcePreprocessor processor; @@ -149,7 +148,7 @@ void SourceProcessorTest::testIncludesAllDiagnostics() void SourceProcessorTest::testMacroUses() { - const QString testFilePath + const FilePath testFilePath = TestIncludePaths::testFilePath(QLatin1String("test_main_macroUses.cpp")); SourcePreprocessor processor; diff --git a/src/plugins/cppeditor/includeutils.cpp b/src/plugins/cppeditor/includeutils.cpp index f79bb8db12..4f89b1a059 100644 --- a/src/plugins/cppeditor/includeutils.cpp +++ b/src/plugins/cppeditor/includeutils.cpp @@ -450,7 +450,7 @@ int IncludeGroup::lineForNewInclude(const QString &newIncludeFileName, return -1; if (isSorted()) { - const Include newInclude(newIncludeFileName, QString(), 0, newIncludeType); + const Include newInclude(newIncludeFileName, FilePath(), 0, newIncludeType); const QList<Include>::const_iterator it = std::lower_bound(m_includes.begin(), m_includes.end(), newInclude, includeFileNamelessThen); if (it == m_includes.end()) @@ -509,22 +509,22 @@ using Tests::Internal::TestIncludePaths; namespace Internal { -static QList<Include> includesForSource(const QString &filePath) +static QList<Include> includesForSource(const FilePath &filePath) { CppModelManager *cmm = CppModelManager::instance(); cmm->GC(); QScopedPointer<CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor()); sourceProcessor->setHeaderPaths({ProjectExplorer::HeaderPath::makeUser( TestIncludePaths::globalIncludePath())}); - sourceProcessor->run(filePath); + sourceProcessor->run(filePath.toString()); - Document::Ptr document = cmm->document(FilePath::fromString(filePath)); + Document::Ptr document = cmm->document(filePath); return document->resolvedIncludes(); } void IncludeGroupsTest::testDetectIncludeGroupsByNewLines() { - const QString testFilePath = TestIncludePaths::testFilePath( + const FilePath testFilePath = TestIncludePaths::testFilePath( QLatin1String("test_main_detectIncludeGroupsByNewLines.cpp")); QList<Include> includes = includesForSource(testFilePath); @@ -566,7 +566,7 @@ void IncludeGroupsTest::testDetectIncludeGroupsByNewLines() void IncludeGroupsTest::testDetectIncludeGroupsByIncludeDir() { - const QString testFilePath = TestIncludePaths::testFilePath( + const FilePath testFilePath = TestIncludePaths::testFilePath( QLatin1String("test_main_detectIncludeGroupsByIncludeDir.cpp")); QList<Include> includes = includesForSource(testFilePath); @@ -590,7 +590,7 @@ void IncludeGroupsTest::testDetectIncludeGroupsByIncludeDir() void IncludeGroupsTest::testDetectIncludeGroupsByIncludeType() { - const QString testFilePath = TestIncludePaths::testFilePath( + const FilePath testFilePath = TestIncludePaths::testFilePath( QLatin1String("test_main_detectIncludeGroupsByIncludeType.cpp")); QList<Include> includes = includesForSource(testFilePath); diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index b077453bf0..d20744d839 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -114,7 +114,7 @@ static QList<Document::Ptr> findDocumentsIncluding(const Snapshot &docTable, docList.append(doc); } } else { - if (include.resolvedFileName() == fileName) + if (include.resolvedFileName().path() == fileName) docList.append(doc); } } diff --git a/src/plugins/modeleditor/componentviewcontroller.cpp b/src/plugins/modeleditor/componentviewcontroller.cpp index 7c0e11d40c..a50604a2fa 100644 --- a/src/plugins/modeleditor/componentviewcontroller.cpp +++ b/src/plugins/modeleditor/componentviewcontroller.cpp @@ -152,18 +152,18 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen if (document) { const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); for (const CPlusPlus::Document::Include &include : includes) { - QString includeFilePath = include.resolvedFileName(); + Utils::FilePath includeFilePath = include.resolvedFileName(); // replace proxy header with real one CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath); if (includeDocument) { QList<CPlusPlus::Document::Include> includes = includeDocument->resolvedIncludes(); if (includes.count() == 1 && - QFileInfo(includes.at(0).resolvedFileName()).fileName() == QFileInfo(includeFilePath).fileName()) + includes.at(0).resolvedFileName().fileName() == includeFilePath.fileName()) { includeFilePath = includes.at(0).resolvedFileName(); } } - qmt::MComponent *includeComponent = findComponentFromFilePath(includeFilePath); + qmt::MComponent *includeComponent = findComponentFromFilePath(includeFilePath.toString()); if (includeComponent && includeComponent != component) { // add dependency between components if (!m_modelUtilities->haveDependency(component, includeComponent)) { diff --git a/src/plugins/modeleditor/pxnodeutilities.cpp b/src/plugins/modeleditor/pxnodeutilities.cpp index 55775228d1..100f347061 100644 --- a/src/plugins/modeleditor/pxnodeutilities.cpp +++ b/src/plugins/modeleditor/pxnodeutilities.cpp @@ -224,7 +224,7 @@ bool PxNodeUtilities::isProxyHeader(const QString &file) const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); if (includes.count() != 1) return false; - return QFileInfo(includes.at(0).resolvedFileName()).fileName() == QFileInfo(file).fileName(); + return includes.at(0).resolvedFileName().fileName() == QFileInfo(file).fileName(); } return false; } diff --git a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp index 25ca5d663f..314b0570f1 100644 --- a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp +++ b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp @@ -1148,14 +1148,14 @@ void tst_CheckSymbols::test_checksymbols_infiniteLoop() const QString filePath1 = QDir::tempPath() + QLatin1String("/file1.h"); Tests::TestCase::writeFile(FilePath::fromString(filePath1), source1); - const QString filePath2 = QDir::tempPath() + QLatin1String("/file2.h"); - Tests::TestCase::writeFile(FilePath::fromString(filePath2), source2); + const FilePath filePath2 = FilePath::fromString(QDir::tempPath()) / "/file2.h"; + Tests::TestCase::writeFile(filePath2, source2); const Document::Ptr document1 = TestCase::createDocument(filePath1, source1); document1->addIncludeFile(Document::Include("file2.h", filePath2, 1, Client::IncludeLocal)); Snapshot snapshot; snapshot.insert(document1); - snapshot.insert(TestCase::createDocument(filePath2, source2)); + snapshot.insert(TestCase::createDocument(filePath2.toString(), source2)); TestCase::runCheckSymbols(document1, snapshot); } |