diff options
Diffstat (limited to 'src')
31 files changed, 146 insertions, 122 deletions
diff --git a/src/libs/3rdparty/cplusplus/Symbol.cpp b/src/libs/3rdparty/cplusplus/Symbol.cpp index 01410ecea9..4ed2ab0c72 100644 --- a/src/libs/3rdparty/cplusplus/Symbol.cpp +++ b/src/libs/3rdparty/cplusplus/Symbol.cpp @@ -34,7 +34,9 @@ #include <utils/link.h> -using namespace CPlusPlus; +using namespace Utils; + +namespace CPlusPlus { class Symbol::HashCode: protected NameVisitor { @@ -166,6 +168,12 @@ const char *Symbol::fileName() const int Symbol::fileNameLength() const { return _fileId ? _fileId->size() : 0; } +Utils::FilePath Symbol::filePath() const +{ + return _fileId ? Utils::FilePath::fromUtf8(_fileId->chars(), _fileId->size()) + : Utils::FilePath(); +} + const Name *Symbol::unqualifiedName() const { if (! _name) @@ -280,10 +288,8 @@ void Symbol::copy(Symbol *other) _isDeprecated = other->_isDeprecated; } -Utils::Link Symbol::toLink() const +Link Symbol::toLink() const { - const QString filename = QString::fromUtf8(fileName(), fileNameLength()); - int line = this->line(); int column = this->column(); @@ -293,5 +299,7 @@ Utils::Link Symbol::toLink() const if (isGenerated()) column = 0; - return Utils::Link(Utils::FilePath::fromString(filename), line, column); + return Link(filePath(), line, column); } + +} // CPlusPlus diff --git a/src/libs/3rdparty/cplusplus/Symbol.h b/src/libs/3rdparty/cplusplus/Symbol.h index 33fe77d80d..497226dcc1 100644 --- a/src/libs/3rdparty/cplusplus/Symbol.h +++ b/src/libs/3rdparty/cplusplus/Symbol.h @@ -22,7 +22,10 @@ #include "CPlusPlusForwardDeclarations.h" -namespace Utils { class Link; } +namespace Utils { +class FilePath; +class Link; +} // Utils namespace CPlusPlus { @@ -78,6 +81,8 @@ public: /// Returns this Symbol's file name length. int fileNameLength() const; + Utils::FilePath filePath() const; + /// Returns this Symbol's name. const Name *name() const { return _name; } diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index 44d880ccf6..6d227c36f9 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -388,8 +388,6 @@ public: bool contains(const Utils::FilePath &filePath) const; Document::Ptr document(const Utils::FilePath &filePath) const; - Document::Ptr document(const QString &fileName) const - { return document(Utils::FilePath::fromString(fileName)); } const_iterator find(const Utils::FilePath &filePath) const; diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index dc7556f11f..cb4cc68e45 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -354,8 +354,8 @@ Document::Ptr LookupContext::expressionDocument() const Document::Ptr LookupContext::thisDocument() const { return _thisDocument; } -Document::Ptr LookupContext::document(const QString &fileName) const -{ return _snapshot.document(fileName); } +Document::Ptr LookupContext::document(const FilePath &filePath) const +{ return _snapshot.document(filePath); } Snapshot LookupContext::snapshot() const { return _snapshot; } diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 196075ae42..ac3c6d2be8 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -276,7 +276,7 @@ public: Document::Ptr expressionDocument() const; Document::Ptr thisDocument() const; - Document::Ptr document(const QString &fileName) const; + Document::Ptr document(const Utils::FilePath &filePath) const; Snapshot snapshot() const; ClassOrNamespace *globalNamespace() const; diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index c3628d66b5..378432110d 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -725,7 +725,7 @@ bool ResolveExpression::visit(SimpleNameAST *ast) TypeOfExpression exprTyper; exprTyper.setExpandTemplates(true); - Document::Ptr doc = _context.snapshot().document(QString::fromLocal8Bit(decl->fileName())); + Document::Ptr doc = _context.snapshot().document(decl->filePath()); exprTyper.init(doc, _context.snapshot(), _context.bindings(), QSet<const Declaration* >(_autoDeclarationsBeingResolved) << decl); diff --git a/src/plugins/autotest/qtest/qttestparser.cpp b/src/plugins/autotest/qtest/qttestparser.cpp index 746a8b40df..8b835f2aeb 100644 --- a/src/plugins/autotest/qtest/qttestparser.cpp +++ b/src/plugins/autotest/qtest/qttestparser.cpp @@ -168,9 +168,7 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc, for (const CPlusPlus::LookupItem &item : std::as_const(lookupItems)) { if (CPlusPlus::Symbol *symbol = item.declaration()) { if (CPlusPlus::Class *toeClass = symbol->asClass()) { - const QString declFileName = QLatin1String(toeClass->fileId()->chars(), - int(toeClass->fileId()->size())); - declaringDoc = snapshot.document(declFileName); + declaringDoc = snapshot.document(toeClass->filePath()); if (line) *line = toeClass->line(); if (column) diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index b8af9a2b1b..ff24d57ed5 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -1436,7 +1436,7 @@ void CppCodeModelInspectorDialog::onDocumentSelected(const QModelIndex ¤t, if (current.isValid()) { const QModelIndex index = m_proxySnapshotModel->index(current.row(), SnapshotModel::FilePathColumn); - const QString filePath = QDir::fromNativeSeparators( + const FilePath filePath = FilePath::fromUserInput( m_proxySnapshotModel->data(index, Qt::DisplayRole).toString()); const SnapshotInfo info = m_snapshotInfos->at(m_ui->snapshotSelector->currentIndex()); updateDocumentData(info.snapshot.document(filePath)); diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 649a0b5ad9..2a653d7715 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -1040,8 +1040,8 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper() int line = 0, column = 0; Utils::Text::convertPosition(interface()->textDocument(), startOfExpression, &line, &column); - const QString fileName = interface()->filePath().toString(); - return startCompletionInternal(fileName, line, column - 1, expression, endOfExpression); + return startCompletionInternal(interface()->filePath(), + line, column - 1, expression, endOfExpression); } bool InternalCppCompletionAssistProcessor::tryObjCCompletion() @@ -1268,7 +1268,7 @@ bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const || mt.matchesName(QLatin1String(CppEditor::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)); } -int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString &fileName, +int InternalCppCompletionAssistProcessor::startCompletionInternal(const Utils::FilePath &filePath, int line, int positionInBlock, const QString &expr, @@ -1276,7 +1276,7 @@ int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString { QString expression = expr.trimmed(); - Document::Ptr thisDocument = cppInterface()->snapshot().document(fileName); + Document::Ptr thisDocument = cppInterface()->snapshot().document(filePath); if (!thisDocument) return -1; diff --git a/src/plugins/cppeditor/cppcompletionassist.h b/src/plugins/cppeditor/cppcompletionassist.h index 4d986bb114..6e770c38c4 100644 --- a/src/plugins/cppeditor/cppcompletionassist.h +++ b/src/plugins/cppeditor/cppcompletionassist.h @@ -86,7 +86,7 @@ private: int startCompletionHelper(); bool tryObjCCompletion(); bool objcKeywordsWanted() const; - int startCompletionInternal(const QString &fileName, + int startCompletionInternal(const Utils::FilePath &filePath, int line, int positionInBlock, const QString &expression, int endOfExpression); diff --git a/src/plugins/cppeditor/cppeditoroutline.cpp b/src/plugins/cppeditor/cppeditoroutline.cpp index 6579a46455..b32ab5b857 100644 --- a/src/plugins/cppeditor/cppeditoroutline.cpp +++ b/src/plugins/cppeditor/cppeditoroutline.cpp @@ -123,7 +123,7 @@ QWidget *CppEditorOutline::widget() const return m_combo; } -QSharedPointer<CPlusPlus::Document> getDocument(const QString &filePath) +QSharedPointer<CPlusPlus::Document> getDocument(const Utils::FilePath &filePath) { const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); return snapshot.document(filePath); diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index c0f1680429..44940cdead 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -74,7 +74,7 @@ public: } public: - Utils::FilePath path; + FilePath path; QString fileName; }; @@ -87,7 +87,7 @@ public: const QString macroName = QString::fromUtf8(macro.name(), macro.name().size()); helpIdCandidates = QStringList(macroName); helpMark = macroName; - link = Utils::Link(macro.filePath(), macro.line()); + link = Link(macro.filePath(), macro.line()); tooltip = macro.toStringWithLineBreaks(); } }; @@ -325,9 +325,7 @@ static Symbol *followClassDeclaration(Symbol *symbol, const Snapshot &snapshot, return symbol; if (context) { - const QString fileName = QString::fromUtf8(classDeclaration->fileName(), - classDeclaration->fileNameLength()); - const Document::Ptr declarationDocument = snapshot.document(fileName); + const Document::Ptr declarationDocument = snapshot.document(classDeclaration->filePath()); if (declarationDocument != context->thisDocument()) (*context) = LookupContext(declarationDocument, snapshot); } @@ -503,15 +501,15 @@ static QFuture<QSharedPointer<CppElement>> asyncExec( class FromExpressionFunctor { public: - FromExpressionFunctor(const QString &expression, const QString &fileName) + FromExpressionFunctor(const QString &expression, const FilePath &filePath) : m_expression(expression) - , m_fileName(fileName) + , m_filePath(filePath) {} bool operator()(const CPlusPlus::Snapshot &snapshot, Document::Ptr &doc, Scope **scope, QString &expression) { - doc = snapshot.document(m_fileName); + doc = snapshot.document(m_filePath); if (doc.isNull()) return false; @@ -523,13 +521,13 @@ public: } private: const QString m_expression; - const QString m_fileName; + const FilePath m_filePath; }; QFuture<QSharedPointer<CppElement>> CppElementEvaluator::asyncExecute(const QString &expression, - const QString &fileName) + const FilePath &filePath) { - return exec(FromExpressionFunctor(expression, fileName), asyncExec); + return exec(FromExpressionFunctor(expression, filePath), asyncExec); } class FromGuiFunctor @@ -692,10 +690,10 @@ const QString &CppElementEvaluator::diagnosis() const return d->m_functor.m_diagnosis; } -Utils::Link CppElementEvaluator::linkFromExpression(const QString &expression, const QString &fileName) +Utils::Link CppElementEvaluator::linkFromExpression(const QString &expression, const FilePath &filePath) { const Snapshot &snapshot = CppModelManager::instance()->snapshot(); - Document::Ptr doc = snapshot.document(fileName); + Document::Ptr doc = snapshot.document(filePath); if (doc.isNull()) return Utils::Link(); Scope *scope = doc->globalNamespace(); diff --git a/src/plugins/cppeditor/cppelementevaluator.h b/src/plugins/cppeditor/cppelementevaluator.h index 14f2659b86..da85b89d22 100644 --- a/src/plugins/cppeditor/cppelementevaluator.h +++ b/src/plugins/cppeditor/cppelementevaluator.h @@ -41,13 +41,13 @@ public: void execute(); static QFuture<QSharedPointer<CppElement>> asyncExecute(TextEditor::TextEditorWidget *editor); static QFuture<QSharedPointer<CppElement>> asyncExecute(const QString &expression, - const QString &fileName); + const Utils::FilePath &filePath); bool identifiedCppElement() const; const QSharedPointer<CppElement> &cppElement() const; bool hasDiagnosis() const; const QString &diagnosis() const; - static Utils::Link linkFromExpression(const QString &expression, const QString &fileName); + static Utils::Link linkFromExpression(const QString &expression, const Utils::FilePath &filePath); private: class CppElementEvaluatorPrivate *d; diff --git a/src/plugins/cppeditor/cppfileiterationorder.cpp b/src/plugins/cppeditor/cppfileiterationorder.cpp index fdda0abf96..b467676af8 100644 --- a/src/plugins/cppeditor/cppfileiterationorder.cpp +++ b/src/plugins/cppeditor/cppfileiterationorder.cpp @@ -5,9 +5,11 @@ #include <utils/qtcassert.h> +using namespace Utils; + namespace CppEditor { -FileIterationOrder::Entry::Entry(const QString &filePath, +FileIterationOrder::Entry::Entry(const FilePath &filePath, const QString &projectPartId, int commonPrefixLength, int commonProjectPartPrefixLength) @@ -66,13 +68,13 @@ bool operator<(const FileIterationOrder::Entry &first, const FileIterationOrder: FileIterationOrder::FileIterationOrder() = default; -FileIterationOrder::FileIterationOrder(const QString &referenceFilePath, +FileIterationOrder::FileIterationOrder(const FilePath &referenceFilePath, const QString &referenceProjectPartId) { setReference(referenceFilePath, referenceProjectPartId); } -void FileIterationOrder::setReference(const QString &filePath, +void FileIterationOrder::setReference(const FilePath &filePath, const QString &projectPartId) { m_referenceFilePath = filePath; @@ -84,7 +86,7 @@ bool FileIterationOrder::isValid() const return !m_referenceFilePath.isEmpty(); } -static int commonPrefixLength(const QString &filePath1, const QString &filePath2) +static int commonPrefixLength(const QStringView filePath1, const QStringView filePath2) { const auto mismatches = std::mismatch(filePath1.begin(), filePath1.end(), filePath2.begin(), filePath2.end()); @@ -92,21 +94,21 @@ static int commonPrefixLength(const QString &filePath1, const QString &filePath2 } FileIterationOrder::Entry FileIterationOrder::createEntryFromFilePath( - const QString &filePath, + const FilePath &filePath, const QString &projectPartId) const { - const int filePrefixLength = commonPrefixLength(m_referenceFilePath, filePath); + const int filePrefixLength = commonPrefixLength(m_referenceFilePath.pathView(), filePath.pathView()); const int projectPartPrefixLength = commonPrefixLength(m_referenceProjectPartId, projectPartId); return Entry(filePath, projectPartId, filePrefixLength, projectPartPrefixLength); } -void FileIterationOrder::insert(const QString &filePath, const QString &projectPartId) +void FileIterationOrder::insert(const FilePath &filePath, const QString &projectPartId) { const Entry entry = createEntryFromFilePath(filePath, projectPartId); m_set.insert(entry); } -void FileIterationOrder::remove(const QString &filePath, const QString &projectPartId) +void FileIterationOrder::remove(const FilePath &filePath, const QString &projectPartId) { const auto needleElement = createEntryFromFilePath(filePath, projectPartId); const auto range = m_set.equal_range(needleElement); @@ -123,6 +125,16 @@ QStringList FileIterationOrder::toStringList() const QStringList result; for (const auto &entry : m_set) + result.append(entry.filePath.toString()); + + return result; +} + +Utils::FilePaths FileIterationOrder::toFilePaths() const +{ + FilePaths result; + + for (const auto &entry : m_set) result.append(entry.filePath); return result; diff --git a/src/plugins/cppeditor/cppfileiterationorder.h b/src/plugins/cppeditor/cppfileiterationorder.h index 6a747027a8..19181a51fa 100644 --- a/src/plugins/cppeditor/cppfileiterationorder.h +++ b/src/plugins/cppeditor/cppfileiterationorder.h @@ -5,7 +5,7 @@ #include "cppeditor_global.h" -#include <QStringList> +#include <utils/filepath.h> #include <set> @@ -14,36 +14,37 @@ namespace CppEditor { class CPPEDITOR_EXPORT FileIterationOrder { public: struct Entry { - Entry(const QString &filePath, - const QString &projectPartId = QString(), + Entry(const Utils::FilePath &filePath, + const QString &projectPartId = {}, int commonFilePathPrefixLength = 0, int commonProjectPartPrefixLength = 0); friend CPPEDITOR_EXPORT bool operator<(const Entry &first, const Entry &second); - const QString filePath; + const Utils::FilePath filePath; const QString projectPartId; int commonFilePathPrefixLength = 0; int commonProjectPartPrefixLength = 0; }; FileIterationOrder(); - FileIterationOrder(const QString &referenceFilePath, + FileIterationOrder(const Utils::FilePath &referenceFilePath, const QString &referenceProjectPartId); - void setReference(const QString &filePath, const QString &projectPartId); + void setReference(const Utils::FilePath &filePath, const QString &projectPartId); bool isValid() const; - void insert(const QString &filePath, const QString &projectPartId = QString()); - void remove(const QString &filePath, const QString &projectPartId); + void insert(const Utils::FilePath &filePath, const QString &projectPartId = QString()); + void remove(const Utils::FilePath &filePath, const QString &projectPartId); QStringList toStringList() const; + Utils::FilePaths toFilePaths() const; private: - Entry createEntryFromFilePath(const QString &filePath, + Entry createEntryFromFilePath(const Utils::FilePath &filePath, const QString &projectPartId) const; private: - QString m_referenceFilePath; + Utils::FilePath m_referenceFilePath; QString m_referenceProjectPartId; std::multiset<Entry> m_set; }; diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index a65142d3d7..ce520ffbdb 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -393,7 +393,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, std::bind(&CppFindReferences::searchAgain, this, search)); CppFindReferencesParameters parameters; parameters.symbolId = fullIdForSymbol(symbol); - parameters.symbolFileName = QByteArray(symbol->fileName()); + parameters.symbolFilePath = symbol->filePath(); parameters.categorize = codeModelSettings()->categorizeFindReferences(); if (symbol->asClass() || symbol->asForwardClassDeclaration()) { @@ -535,11 +535,10 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete CPlusPlus::LookupContext *context) { QTC_ASSERT(context, return nullptr); - QString symbolFile = QLatin1String(parameters.symbolFileName); - if (!snapshot.contains(FilePath::fromString(symbolFile))) + if (!snapshot.contains(parameters.symbolFilePath)) return nullptr; - CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile); + CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(parameters.symbolFilePath); // document is not parsed and has no bindings yet, do it QByteArray source = getSource(newSymbolDocument->filePath(), m_modelManager->workingCopy()); CPlusPlus::Document::Ptr doc = diff --git a/src/plugins/cppeditor/cppfindreferences.h b/src/plugins/cppeditor/cppfindreferences.h index 34a5a302fd..bb50ae91a4 100644 --- a/src/plugins/cppeditor/cppfindreferences.h +++ b/src/plugins/cppeditor/cppfindreferences.h @@ -46,7 +46,7 @@ class CppFindReferencesParameters { public: QList<QByteArray> symbolId; - QByteArray symbolFileName; + Utils::FilePath symbolFilePath; QString prettySymbolName; Utils::FilePaths filesToRename; bool categorize = false; diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 93d830df6e..9d524c8c86 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1372,7 +1372,7 @@ public: QList<Document::Ptr> documentsToCheck; for (const QString &file : commonSourceFiles) { - if (Document::Ptr document = snapshot.document(file)) + if (Document::Ptr document = snapshot.document(FilePath::fromString(file))) documentsToCheck << document; } diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index dbc560c53c..0299569c5e 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -456,7 +456,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() QFETCH(QStringList, finalProjectFiles); TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path()); - fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8()); + const FilePath filePath = FilePath::fromString(temporaryDir.absolutePath(fileToChange.toUtf8())); const FilePaths initialProjectFilePaths = toAbsolutePaths(initialProjectFiles, temporaryDir); const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir); @@ -486,14 +486,14 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() QVERIFY(snapshot.contains(file)); } - document = snapshot.document(fileToChange); + document = snapshot.document(filePath); const QDateTime lastModifiedBefore = document->lastModified(); QCOMPARE(document->globalSymbolCount(), 1); QCOMPARE(document->globalSymbolAt(0)->name()->identifier()->chars(), "someGlobal"); // Modify the file QTest::qSleep(1000); // Make sure the timestamp is different - FileChangerAndRestorer fileChangerAndRestorer(FilePath::fromString(fileToChange)); + FileChangerAndRestorer fileChangerAndRestorer(filePath); QByteArray originalContents; QVERIFY(fileChangerAndRestorer.readContents(&originalContents)); const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;"; @@ -514,7 +514,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() QVERIFY(refreshedFiles.contains(file)); QVERIFY(snapshot.contains(file)); } - document = snapshot.document(fileToChange); + document = snapshot.document(filePath); const QDateTime lastModifiedAfter = document->lastModified(); QVERIFY(lastModifiedAfter > lastModifiedBefore); QCOMPARE(document->globalSymbolCount(), 2); @@ -618,7 +618,8 @@ void ModelManagerTest::testExtraeditorsupportUiFiles() // Check CppSourceProcessor / includes. // The CppSourceProcessor is expected to find the ui_* file in the working copy. - const QString fileIncludingTheUiFile = temporaryDir.absolutePath("mainwindow.cpp"); + const FilePath fileIncludingTheUiFile = + FilePath::fromString(temporaryDir.absolutePath("mainwindow.cpp")); while (!mm->snapshot().document(fileIncludingTheUiFile)) QCoreApplication::processEvents(); diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp index 1a57b5d394..ee463fb5b8 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.cpp +++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp @@ -74,7 +74,7 @@ CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPo : RefactoringFile(filePath, data) { const Snapshot &snapshot = this->data()->m_snapshot; - m_cppDocument = snapshot.document(filePath.toString()); + m_cppDocument = snapshot.document(filePath); } CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const FilePath &filePath) diff --git a/src/plugins/cppeditor/cpptypehierarchy.cpp b/src/plugins/cppeditor/cpptypehierarchy.cpp index c3b808d472..4bef54edd0 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.cpp +++ b/src/plugins/cppeditor/cpptypehierarchy.cpp @@ -185,7 +185,7 @@ void CppTypeHierarchyWidget::perform() Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy"); } -void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const QString &fileName) +void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const FilePath &filePath) { if (m_future.isRunning()) m_future.cancel(); @@ -194,7 +194,7 @@ void CppTypeHierarchyWidget::performFromExpression(const QString &expression, co showProgress(); - m_future = CppElementEvaluator::asyncExecute(expression, fileName); + m_future = CppElementEvaluator::asyncExecute(expression, filePath); m_futureWatcher.setFuture(QFuture<void>(m_future)); m_synchronizer.addFuture(m_future); @@ -309,7 +309,7 @@ void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index) return; const Link updatedLink = CppElementEvaluator::linkFromExpression( - getExpression(index), link.targetFilePath.toString()); + getExpression(index), link.targetFilePath); if (updatedLink.hasValidTarget()) link = updatedLink; @@ -320,7 +320,7 @@ void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index) { const auto link = index.data(LinkRole).value<Link>(); if (link.hasValidTarget()) - performFromExpression(getExpression(index), link.targetFilePath.toString()); + performFromExpression(getExpression(index), link.targetFilePath); } // CppTypeHierarchyFactory diff --git a/src/plugins/cppeditor/cpptypehierarchy.h b/src/plugins/cppeditor/cpptypehierarchy.h index c435978a9d..a2f03499b5 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.h +++ b/src/plugins/cppeditor/cpptypehierarchy.h @@ -62,7 +62,7 @@ private slots: private: typedef QList<CppClass> CppClass::*HierarchyMember; - void performFromExpression(const QString &expression, const QString &fileName); + void performFromExpression(const QString &expression, const Utils::FilePath &filePath); QStandardItem *buildHierarchy(const CppClass &cppClass, QStandardItem *parent, bool isRoot, HierarchyMember member); void showNoTypeHierarchyLabel(); diff --git a/src/plugins/cppeditor/insertionpointlocator.cpp b/src/plugins/cppeditor/insertionpointlocator.cpp index a0aa777cc6..119e39cfb3 100644 --- a/src/plugins/cppeditor/insertionpointlocator.cpp +++ b/src/plugins/cppeditor/insertionpointlocator.cpp @@ -593,15 +593,14 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration, int line, column; if (suffix.isEmpty()) { - Document::Ptr targetDoc = changes.snapshot().document(QString::fromUtf8(definitionFunction->fileName())); + Document::Ptr targetDoc = changes.snapshot().document(definitionFunction->filePath()); if (!targetDoc) return noResult; targetDoc->translationUnit()->getPosition(definitionFunction->endOffset(), &line, &column); } else { // we don't have an offset to the start of the function definition, so we need to manually find it... - CppRefactoringFilePtr targetFile = changes.file( - Utils::FilePath::fromString(QString::fromUtf8(definitionFunction->fileName()))); + CppRefactoringFilePtr targetFile = changes.file(definitionFunction->filePath()); if (!targetFile->isValid()) return noResult; diff --git a/src/plugins/cppeditor/symbolfinder.cpp b/src/plugins/cppeditor/symbolfinder.cpp index 484dfd6e1b..a6a90cdbc1 100644 --- a/src/plugins/cppeditor/symbolfinder.cpp +++ b/src/plugins/cppeditor/symbolfinder.cpp @@ -20,6 +20,7 @@ #include <utility> using namespace CPlusPlus; +using namespace Utils; namespace CppEditor { namespace { @@ -134,7 +135,7 @@ Function *SymbolFinder::findMatchingDefinition(Symbol *declaration, if (!declaration) return nullptr; - QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength()); + const FilePath declFile = declaration->filePath(); Document::Ptr thisDocument = snapshot.document(declFile); if (!thisDocument) { @@ -150,11 +151,11 @@ Function *SymbolFinder::findMatchingDefinition(Symbol *declaration, } Hit best; - const QStringList fileNames = fileIterationOrder(declFile, snapshot); - for (const QString &fileName : fileNames) { - Document::Ptr doc = snapshot.document(fileName); + const FilePaths filePaths = fileIterationOrder(declFile, snapshot); + for (const FilePath &filePath : filePaths) { + Document::Ptr doc = snapshot.document(filePath); if (!doc) { - clearCache(declFile, fileName); + clearCache(declFile, filePath); continue; } @@ -220,7 +221,7 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps return nullptr; } - QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength()); + const FilePath declFile = declaration->filePath(); const Document::Ptr thisDocument = snapshot.document(declFile); if (!thisDocument) { qWarning() << "undefined document:" << declaration->fileName(); @@ -230,11 +231,11 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps using SymbolWithPriority = QPair<Symbol *, bool>; QList<SymbolWithPriority> candidates; QList<SymbolWithPriority> fallbacks; - const QStringList fileNames = fileIterationOrder(declFile, snapshot); - for (const QString &fileName : fileNames) { - Document::Ptr doc = snapshot.document(fileName); + const FilePaths filePaths = fileIterationOrder(declFile, snapshot); + for (const FilePath &filePath : filePaths) { + Document::Ptr doc = snapshot.document(filePath); if (!doc) { - clearCache(declFile, fileName); + clearCache(declFile, filePath); continue; } @@ -271,7 +272,7 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps for (const auto &candidate : std::as_const(candidates)) { if (candidate.first == declaration) continue; - if (QLatin1String(candidate.first->fileName()) == declFile + if (candidate.first->filePath() == declFile && candidate.first->sourceLocation() == declaration->sourceLocation()) continue; if (!candidate.first->asDeclaration()) @@ -298,10 +299,10 @@ Class *SymbolFinder::findMatchingClassDeclaration(Symbol *declaration, const Sna if (!declaration->identifier()) return nullptr; - QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength()); + const FilePath declFile = declaration->filePath(); - const QStringList fileNames = fileIterationOrder(declFile, snapshot); - for (const QString &file : fileNames) { + const FilePaths filePaths = fileIterationOrder(declFile, snapshot); + for (const FilePath &file : filePaths) { Document::Ptr doc = snapshot.document(file); if (!doc) { clearCache(declFile, file); @@ -438,16 +439,16 @@ QList<Declaration *> SymbolFinder::findMatchingDeclaration(const LookupContext & return result; } -QStringList SymbolFinder::fileIterationOrder(const QString &referenceFile, const Snapshot &snapshot) +FilePaths SymbolFinder::fileIterationOrder(const FilePath &referenceFile, const Snapshot &snapshot) { if (m_filePriorityCache.contains(referenceFile)) { checkCacheConsistency(referenceFile, snapshot); } else { for (Document::Ptr doc : snapshot) - insertCache(referenceFile, doc->filePath().path()); + insertCache(referenceFile, doc->filePath()); } - QStringList files = m_filePriorityCache.value(referenceFile).toStringList(); + FilePaths files = m_filePriorityCache.value(referenceFile).toFilePaths(); trackCacheUse(referenceFile); @@ -461,19 +462,19 @@ void SymbolFinder::clearCache() m_recent.clear(); } -void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Snapshot &snapshot) +void SymbolFinder::checkCacheConsistency(const FilePath &referenceFile, const Snapshot &snapshot) { // We only check for "new" files, which which are in the snapshot but not in the cache. // The counterpart validation for "old" files is done when one tries to access the // corresponding document and notices it's now null. - const QSet<QString> &meta = m_fileMetaCache.value(referenceFile); + const QSet<FilePath> &meta = m_fileMetaCache.value(referenceFile); for (const Document::Ptr &doc : snapshot) { - if (!meta.contains(doc->filePath().path())) - insertCache(referenceFile, doc->filePath().path()); + if (!meta.contains(doc->filePath())) + insertCache(referenceFile, doc->filePath()); } } -const QString projectPartIdForFile(const QString &filePath) +const QString projectPartIdForFile(const FilePath &filePath) { const QList<ProjectPart::ConstPtr> parts = CppModelManager::instance()->projectPart(filePath); if (!parts.isEmpty()) @@ -481,13 +482,13 @@ const QString projectPartIdForFile(const QString &filePath) return QString(); } -void SymbolFinder::clearCache(const QString &referenceFile, const QString &comparingFile) +void SymbolFinder::clearCache(const FilePath &referenceFile, const FilePath &comparingFile) { m_filePriorityCache[referenceFile].remove(comparingFile, projectPartIdForFile(comparingFile)); m_fileMetaCache[referenceFile].remove(comparingFile); } -void SymbolFinder::insertCache(const QString &referenceFile, const QString &comparingFile) +void SymbolFinder::insertCache(const FilePath &referenceFile, const FilePath &comparingFile) { FileIterationOrder &order = m_filePriorityCache[referenceFile]; if (!order.isValid()) { @@ -499,7 +500,7 @@ void SymbolFinder::insertCache(const QString &referenceFile, const QString &comp m_fileMetaCache[referenceFile].insert(comparingFile); } -void SymbolFinder::trackCacheUse(const QString &referenceFile) +void SymbolFinder::trackCacheUse(const FilePath &referenceFile) { if (!m_recent.isEmpty()) { if (m_recent.last() == referenceFile) @@ -511,7 +512,7 @@ void SymbolFinder::trackCacheUse(const QString &referenceFile) // We don't want this to grow too much. if (m_recent.size() > kMaxCacheSize) { - const QString &oldest = m_recent.takeFirst(); + const FilePath &oldest = m_recent.takeFirst(); m_filePriorityCache.remove(oldest); m_fileMetaCache.remove(oldest); } diff --git a/src/plugins/cppeditor/symbolfinder.h b/src/plugins/cppeditor/symbolfinder.h index 48a8c49a39..bb222202af 100644 --- a/src/plugins/cppeditor/symbolfinder.h +++ b/src/plugins/cppeditor/symbolfinder.h @@ -7,6 +7,8 @@ #include "cppfileiterationorder.h" +#include <utils/filepath.h> + #include <QHash> #include <QSet> #include <QStringList> @@ -51,17 +53,17 @@ public: void clearCache(); private: - QStringList fileIterationOrder(const QString &referenceFile, - const CPlusPlus::Snapshot &snapshot); - void checkCacheConsistency(const QString &referenceFile, const CPlusPlus::Snapshot &snapshot); - void clearCache(const QString &referenceFile, const QString &comparingFile); - void insertCache(const QString &referenceFile, const QString &comparingFile); + Utils::FilePaths fileIterationOrder(const Utils::FilePath &referenceFile, + const CPlusPlus::Snapshot &snapshot); + void checkCacheConsistency(const Utils::FilePath &referenceFile, const CPlusPlus::Snapshot &snapshot); + void clearCache(const Utils::FilePath &referenceFile, const Utils::FilePath &comparingFile); + void insertCache(const Utils::FilePath &referenceFile, const Utils::FilePath &comparingFile); - void trackCacheUse(const QString &referenceFile); + void trackCacheUse(const Utils::FilePath &referenceFile); - QHash<QString, FileIterationOrder> m_filePriorityCache; - QHash<QString, QSet<QString> > m_fileMetaCache; - QStringList m_recent; + QHash<Utils::FilePath, FileIterationOrder> m_filePriorityCache; + QHash<Utils::FilePath, QSet<Utils::FilePath> > m_fileMetaCache; + Utils::FilePaths m_recent; }; } // namespace CppEditor diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index fbc7e0f50a..cc412da781 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -611,7 +611,7 @@ public: //: Message tracepoint: %1 file, %2 line %3 function hit. message = Tr::tr("%1:%2 %3() hit").arg(data.fileName.fileName()). arg(data.lineNumber). - arg(cppFunctionAt(data.fileName.toString(), data.lineNumber)); + arg(cppFunctionAt(data.fileName, data.lineNumber)); } QInputDialog dialog; // Create wide input dialog. dialog.setWindowFlags(dialog.windowFlags() & ~(Qt::MSWindowsFixedSizeDialogHint)); @@ -1917,7 +1917,7 @@ void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget, // Disassemble current function in stopped state. if (engine->hasCapability(DisassemblerCapability)) { StackFrame frame; - frame.function = cppFunctionAt(args.fileName.toString(), lineNumber, 1); + frame.function = cppFunctionAt(args.fileName, lineNumber, 1); frame.line = 42; // trick gdb into mixed mode. if (!frame.function.isEmpty()) { const QString text = Tr::tr("Disassemble Function \"%1\"") diff --git a/src/plugins/debugger/sourceutils.cpp b/src/plugins/debugger/sourceutils.cpp index ee912968f4..78d3b100f0 100644 --- a/src/plugins/debugger/sourceutils.cpp +++ b/src/plugins/debugger/sourceutils.cpp @@ -220,10 +220,10 @@ QStringList getUninitializedVariables(const Snapshot &snapshot, return result; } -QString cppFunctionAt(const QString &fileName, int line, int column) +QString cppFunctionAt(const FilePath &filePath, int line, int column) { const Snapshot snapshot = CppModelManager::instance()->snapshot(); - if (const Document::Ptr document = snapshot.document(fileName)) + if (const Document::Ptr document = snapshot.document(filePath)) return document->functionAt(line, column); return QString(); @@ -238,9 +238,9 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos, if (function) function->clear(); - const QString fileName = editorWidget->textDocument()->filePath().toString(); + const FilePath filePath = editorWidget->textDocument()->filePath(); const Snapshot snapshot = CppModelManager::instance()->snapshot(); - const Document::Ptr document = snapshot.document(fileName); + const Document::Ptr document = snapshot.document(filePath); QTextCursor tc = editorWidget->textCursor(); QString expr; if (tc.hasSelection() && pos >= tc.selectionStart() && pos <= tc.selectionEnd()) { @@ -374,7 +374,7 @@ static void setValueAnnotationsHelper(BaseTextEditor *textEditor, TextDocument *textDocument = widget->textDocument(); const FilePath filePath = loc.fileName(); const Snapshot snapshot = CppModelManager::instance()->snapshot(); - const Document::Ptr cppDocument = snapshot.document(filePath.toString()); + const Document::Ptr cppDocument = snapshot.document(filePath); if (!cppDocument) // For non-C++ documents. return; diff --git a/src/plugins/debugger/sourceutils.h b/src/plugins/debugger/sourceutils.h index 755c4576c2..3f8bcabb97 100644 --- a/src/plugins/debugger/sourceutils.h +++ b/src/plugins/debugger/sourceutils.h @@ -24,7 +24,7 @@ QString cppExpressionAt(TextEditor::TextEditorWidget *editorWidget, int pos, int *line, int *column, QString *function = nullptr, int *scopeFromLine = nullptr, int *scopeToLine = nullptr); QString fixCppExpression(const QString &exp); -QString cppFunctionAt(const QString &fileName, int line, int column = 0); +QString cppFunctionAt(const Utils::FilePath &filePath, int line, int column = 0); // Get variables that are not initialized at a certain line // of a function from the code model. Shadowed variables will diff --git a/src/plugins/modeleditor/classviewcontroller.cpp b/src/plugins/modeleditor/classviewcontroller.cpp index 9247417be4..04be16c0a1 100644 --- a/src/plugins/modeleditor/classviewcontroller.cpp +++ b/src/plugins/modeleditor/classviewcontroller.cpp @@ -24,7 +24,7 @@ QSet<QString> ClassViewController::findClassDeclarations(const QString &fileName CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); // scan original file - CPlusPlus::Document::Ptr document = snapshot.document(fileName); + CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(fileName)); if (!document.isNull()) appendClassDeclarationsFromDocument(document, line, column, &classNames); @@ -32,7 +32,7 @@ QSet<QString> ClassViewController::findClassDeclarations(const QString &fileName QString otherFileName = CppEditor::correspondingHeaderOrSource(fileName); // scan other file - document = snapshot.document(otherFileName); + document = snapshot.document(Utils::FilePath::fromString(otherFileName)); if (!document.isNull()) appendClassDeclarationsFromDocument(document, -1, -1, &classNames); } diff --git a/src/plugins/modeleditor/componentviewcontroller.cpp b/src/plugins/modeleditor/componentviewcontroller.cpp index a50604a2fa..ef8e9a477d 100644 --- a/src/plugins/modeleditor/componentviewcontroller.cpp +++ b/src/plugins/modeleditor/componentviewcontroller.cpp @@ -29,6 +29,8 @@ // TODO implement removing include dependencies that are not longer used // TODO refactor add/remove relations between ancestor packages into extra controller class +using namespace Utils; + namespace ModelEditor { namespace Internal { @@ -148,7 +150,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen const QStringList filePaths = findFilePathOfComponent(component); for (const QString &filePath : filePaths) { - CPlusPlus::Document::Ptr document = snapshot.document(filePath); + CPlusPlus::Document::Ptr document = snapshot.document(FilePath::fromString(filePath)); if (document) { const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); for (const CPlusPlus::Document::Include &include : includes) { diff --git a/src/plugins/modeleditor/pxnodeutilities.cpp b/src/plugins/modeleditor/pxnodeutilities.cpp index 100f347061..4e8d826621 100644 --- a/src/plugins/modeleditor/pxnodeutilities.cpp +++ b/src/plugins/modeleditor/pxnodeutilities.cpp @@ -219,7 +219,7 @@ bool PxNodeUtilities::isProxyHeader(const QString &file) const CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance(); CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); - CPlusPlus::Document::Ptr document = snapshot.document(file); + CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(file)); if (document) { QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); if (includes.count() != 1) |