From b87f0519e300c86ded0e4fd52379b0df0d996402 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 24 Nov 2022 19:16:47 +0100 Subject: [PATCH] CppEditor: Use FilePath for ProjectPath::m_sourceFiles ... and update using code. Change-Id: I682727a4b2982dba388e7cc7b9488225748d591f Reviewed-by: Christian Kandeler --- src/plugins/autotest/gtest/gtesttreeitem.cpp | 5 +- .../baremetal/debugservers/uvsc/uvproject.cpp | 13 ++- src/plugins/clangcodemodel/clangdclient.cpp | 7 +- src/plugins/clangcodemodel/clangutils.cpp | 8 +- src/plugins/clangtools/clangtool.cpp | 6 +- .../clangtools/documentclangtoolrunner.cpp | 9 +- src/plugins/cppcheck/cppchecktool.cpp | 12 +-- src/plugins/cppcheck/cppchecktrigger.cpp | 3 +- .../cppeditor/abstracteditorsupport.cpp | 2 +- .../cppeditor/cppcodemodelinspectordialog.cpp | 7 +- src/plugins/cppeditor/cppfindreferences.cpp | 3 +- src/plugins/cppeditor/cppmodelmanager.cpp | 78 ++++++++------- src/plugins/cppeditor/cppmodelmanager.h | 14 +-- .../cppeditor/cppmodelmanager_test.cpp | 96 +++++++++---------- src/plugins/cppeditor/cppprojectfile.cpp | 2 +- src/plugins/cppeditor/cppprojectfile.h | 8 +- .../cppeditor/cppprojectfilecategorizer.cpp | 5 +- src/plugins/cppeditor/cppprojectupdater.cpp | 5 +- .../cppeditor/cpprefactoringchanges.cpp | 2 +- src/plugins/cppeditor/cpptoolstestcase.cpp | 3 +- .../cppeditor/fileandtokenactions_test.cpp | 6 +- .../cppeditor/modelmanagertesthelper.cpp | 6 +- .../cppeditor/modelmanagertesthelper.h | 2 +- src/plugins/cppeditor/projectinfo.cpp | 16 +--- src/plugins/cppeditor/projectinfo.h | 9 +- src/plugins/todo/cpptodoitemsscanner.cpp | 4 +- 26 files changed, 158 insertions(+), 173 deletions(-) diff --git a/src/plugins/autotest/gtest/gtesttreeitem.cpp b/src/plugins/autotest/gtest/gtesttreeitem.cpp index 72c97477834..b6cdb714fed 100644 --- a/src/plugins/autotest/gtest/gtesttreeitem.cpp +++ b/src/plugins/autotest/gtest/gtesttreeitem.cpp @@ -505,14 +505,13 @@ QSet internalTargets(const TestTreeItem &item) if (!projectInfo) return {}; const Utils::FilePath filePath = item.filePath(); - const QString file = filePath.toString(); const QVector projectParts = projectInfo->projectParts(); if (projectParts.isEmpty()) return cppMM->dependingInternalTargets(item.filePath()); for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectParts) { if (Utils::FilePath::fromString(projectPart->projectFile) == item.proFile() - && Utils::anyOf(projectPart->files, [&file](const CppEditor::ProjectFile &pf) { - return pf.path == file; + && Utils::anyOf(projectPart->files, [&filePath] (const CppEditor::ProjectFile &pf) { + return pf.path == filePath; })) { result.insert(projectPart->buildSystemTarget); if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) diff --git a/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp b/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp index fb7f26493ff..773ec410666 100644 --- a/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp +++ b/src/plugins/baremetal/debugservers/uvsc/uvproject.cpp @@ -73,13 +73,12 @@ static void extractAllFiles(const DebuggerRunTool *runTool, QStringList &include for (const ProjectFile &file : std::as_const(part->files)) { if (!file.active) continue; - const auto path = FilePath::fromString(file.path); - if (file.isHeader() && !headers.contains(path)) - headers.push_back(path); - else if (file.isSource() && !sources.contains(path)) - sources.push_back(path); - else if (file.path.endsWith(".s") && !assemblers.contains(path)) - assemblers.push_back(path); + if (file.isHeader() && !headers.contains(file.path)) + headers.push_back(file.path); + else if (file.isSource() && !sources.contains(file.path)) + sources.push_back(file.path); + else if (file.path.endsWith(".s") && !assemblers.contains(file.path)) + assemblers.push_back(file.path); } for (const HeaderPath &include : std::as_const(part->headerPaths)) { if (!includes.contains(include.path)) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 6ec4629188d..ebacad7b506 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -81,6 +81,7 @@ using namespace LanguageClient; using namespace LanguageServerProtocol; using namespace ProjectExplorer; using namespace TextEditor; +using namespace Utils; namespace ClangCodeModel { namespace Internal { @@ -341,7 +342,7 @@ static void addToCompilationDb(QJsonObject &cdb, // Should we make use of them or keep using our own? args.prepend("clang"); - const QString fileString = Utils::FilePath::fromString(sourceFile.path).toUserOutput(); + const QString fileString = sourceFile.path.toUserOutput(); args.append(fileString); QJsonObject value; value.insert("workingDirectory", workingDir.toString()); @@ -819,7 +820,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder( *projectPart, warningsConfigForProject(project()), includeDir, ProjectExplorer::Macro::toMacros(config.editorDefines)); - const CppEditor::ProjectFile file(filePath.toString(), + const CppEditor::ProjectFile file(filePath, CppEditor::ProjectFile::classify(filePath.toString())); const QJsonArray projectPartOptions = fullProjectPartOptions( optionsBuilder, globalClangOptions()); @@ -833,7 +834,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath, emit configChanged(); } -void ClangdClient::switchIssuePaneEntries(const Utils::FilePath &filePath) +void ClangdClient::switchIssuePaneEntries(const FilePath &filePath) { TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); const Tasks tasks = d->issuePaneEntries.value(filePath); diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 674f21cc401..4f73c7b5524 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -110,13 +110,13 @@ static QJsonObject createFileObject(const FilePath &buildDir, bool clStyle) { QJsonObject fileObject; - fileObject["file"] = projFile.path; + fileObject["file"] = projFile.path.toString(); QJsonArray args; if (purpose == CompilationDbPurpose::Project) { args = QJsonArray::fromStringList(arguments); - const ProjectFile::Kind kind = ProjectFile::classify(projFile.path); + const ProjectFile::Kind kind = ProjectFile::classify(projFile.path.path()); if (projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID || projectPart.toolchainType == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID) { if (!ProjectFile::isObjC(kind)) { @@ -138,7 +138,7 @@ static QJsonObject createFileObject(const FilePath &buildDir, args.prepend("clang"); // TODO: clang-cl for MSVC targets? Does it matter at all what we put here? } - args.append(QDir::toNativeSeparators(projFile.path)); + args.append(projFile.path.toUserOutput()); fileObject["arguments"] = args; fileObject["directory"] = buildDir.toString(); return fileObject; @@ -269,7 +269,7 @@ QJsonArray clangOptionsForFile(const ProjectFile &file, const ProjectPart &proje ? ProjectFile::CHeader : ProjectFile::CXXHeader; } if (usePch == UsePrecompiledHeaders::Yes - && projectPart.precompiledHeaders.contains(file.path)) { + && projectPart.precompiledHeaders.contains(file.path.path())) { usePch = UsePrecompiledHeaders::No; } optionsBuilder.updateFileLanguage(fileKind); diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index 6447485c93e..b22a34a6a56 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -312,16 +312,14 @@ static FileInfos sortedFileInfos(const QVector for (const CppEditor::ProjectFile &file : std::as_const(projectPart->files)) { QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unclassified, continue); QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unsupported, continue); - if (file.path == CppEditor::CppModelManager::configurationFileName().path()) + if (file.path == CppEditor::CppModelManager::configurationFileName()) continue; if (file.active && (CppEditor::ProjectFile::isSource(file.kind) || CppEditor::ProjectFile::isHeader(file.kind))) { ProjectFile::Kind sourceKind = CppEditor::ProjectFile::sourceKind(file.kind); - fileInfos.emplace_back(Utils::FilePath::fromString(file.path), - sourceKind, - projectPart); + fileInfos.emplace_back(file.path, sourceKind, projectPart); } } } diff --git a/src/plugins/clangtools/documentclangtoolrunner.cpp b/src/plugins/clangtools/documentclangtoolrunner.cpp index 888811cea9e..bc2a036fbc0 100644 --- a/src/plugins/clangtools/documentclangtoolrunner.cpp +++ b/src/plugins/clangtools/documentclangtoolrunner.cpp @@ -135,20 +135,19 @@ static FileInfo getFileInfo(const FilePath &file, Project *project) for (const ProjectFile &projectFile : std::as_const(projectPart->files)) { QTC_ASSERT(projectFile.kind != ProjectFile::Unclassified, continue); QTC_ASSERT(projectFile.kind != ProjectFile::Unsupported, continue); - if (projectFile.path == CppModelManager::configurationFileName().path()) + if (projectFile.path == CppModelManager::configurationFileName()) continue; - const auto projectFilePath = FilePath::fromString(projectFile.path); - if (file != projectFilePath) + if (file != projectFile.path) continue; if (!projectFile.active) continue; // found the best candidate, early return ProjectFile::Kind sourceKind = ProjectFile::sourceKind(projectFile.kind); if (projectPart->buildTargetType != BuildTargetType::Unknown) - return FileInfo(projectFilePath, sourceKind, projectPart); + return FileInfo(projectFile.path, sourceKind, projectPart); // found something but keep looking for better candidates if (candidate.projectPart.isNull()) - candidate = FileInfo(projectFilePath, sourceKind, projectPart); + candidate = FileInfo(projectFile.path, sourceKind, projectPart); } } diff --git a/src/plugins/cppcheck/cppchecktool.cpp b/src/plugins/cppcheck/cppchecktool.cpp index 0fb628b7ad5..a5c3bc6afb5 100644 --- a/src/plugins/cppcheck/cppchecktool.cpp +++ b/src/plugins/cppcheck/cppchecktool.cpp @@ -22,10 +22,11 @@ #include +using namespace Utils; + namespace Cppcheck::Internal { -CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, - const Utils::Id &progressId) : +CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progressId) : m_manager(manager), m_progressRegexp("^.* checked (\\d+)% done$"), m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"), @@ -194,13 +195,12 @@ void CppcheckTool::check(const Utils::FilePaths &files) return; } - std::map groups; - for (const Utils::FilePath &file : std::as_const(filtered)) { - const QString stringed = file.toString(); + std::map groups; + for (const FilePath &file : std::as_const(filtered)) { for (const CppEditor::ProjectPart::ConstPtr &part : parts) { using CppEditor::ProjectFile; QTC_ASSERT(part, continue); - const auto match = [stringed](const ProjectFile &pFile){return pFile.path == stringed;}; + const auto match = [file](const ProjectFile &pFile){return pFile.path == file;}; if (Utils::contains(part->files, match)) groups[part].push_back(file); } diff --git a/src/plugins/cppcheck/cppchecktrigger.cpp b/src/plugins/cppcheck/cppchecktrigger.cpp index 93f15522dbc..55b1cf7ac01 100644 --- a/src/plugins/cppcheck/cppchecktrigger.cpp +++ b/src/plugins/cppcheck/cppchecktrigger.cpp @@ -78,8 +78,7 @@ void CppcheckTrigger::checkEditors(const QList &editors) if (!m_currentProject->isKnownFile(path)) continue; - const QString &pathString = path.toString(); - if (!info->sourceFiles().contains(pathString)) + if (!info->sourceFiles().contains(path)) continue; connect(document, &IDocument::aboutToReload, diff --git a/src/plugins/cppeditor/abstracteditorsupport.cpp b/src/plugins/cppeditor/abstracteditorsupport.cpp index 01e21b7bab7..f421f756718 100644 --- a/src/plugins/cppeditor/abstracteditorsupport.cpp +++ b/src/plugins/cppeditor/abstracteditorsupport.cpp @@ -29,7 +29,7 @@ AbstractEditorSupport::~AbstractEditorSupport() void AbstractEditorSupport::updateDocument() { ++m_revision; - m_modelmanager->updateSourceFiles(QSet{filePath().toString()}); + m_modelmanager->updateSourceFiles({filePath()}); } void AbstractEditorSupport::notifyAboutUpdatedContents() const diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index b5808a60c5b..fb06a8ba607 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -240,11 +240,10 @@ QVariant ProjectFilesModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { const int row = index.row(); const int column = index.column(); - if (column == FileKindColumn) { + if (column == FileKindColumn) return CMI::Utils::toString(m_files.at(row).kind); - } else if (column == FilePathColumn) { - return m_files.at(row).path; - } + if (column == FilePathColumn) + return m_files.at(row).path.toVariant(); } else if (role == Qt::ForegroundRole) { if (!m_files.at(index.row()).active) { return QApplication::palette().color(QPalette::ColorGroup::Disabled, diff --git a/src/plugins/cppeditor/cppfindreferences.cpp b/src/plugins/cppeditor/cppfindreferences.cpp index f2c5a1382fc..e819e48f985 100644 --- a/src/plugins/cppeditor/cppfindreferences.cpp +++ b/src/plugins/cppeditor/cppfindreferences.cpp @@ -457,8 +457,7 @@ void CppFindReferences::onReplaceButtonClicked(Core::SearchResult *search, { const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase); if (!filePaths.isEmpty()) { - m_modelManager->updateSourceFiles( - Utils::transform(filePaths, &Utils::FilePath::toString)); + m_modelManager->updateSourceFiles(Utils::toSet(filePaths)); SearchResultWindow::instance()->hide(); } diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 733bbde8e53..46843defcb4 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -169,7 +169,7 @@ public: // The members below are cached/(re)calculated from the projects and/or their project parts bool m_dirty; - QStringList m_projectFiles; + Utils::FilePaths m_projectFiles; ProjectExplorer::HeaderPaths m_headerPaths; ProjectExplorer::Macros m_definedMacros; @@ -262,9 +262,9 @@ const char pp_configuration[] = "#define __ptr32\n" "#define __ptr64\n"; -QSet CppModelManager::timeStampModifiedFiles(const QList &documentsToCheck) +QSet CppModelManager::timeStampModifiedFiles(const QList &documentsToCheck) { - QSet sourceFiles; + QSet sourceFiles; for (const Document::Ptr &doc : documentsToCheck) { const QDateTime lastModified = doc->lastModified(); @@ -273,7 +273,7 @@ QSet CppModelManager::timeStampModifiedFiles(const QList const FilePath filePath = doc->filePath(); if (filePath.exists() && filePath.lastModified() != lastModified) - sourceFiles.insert(filePath.toString()); + sourceFiles.insert(filePath); } } @@ -403,7 +403,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit) } const ToolChain * tc = nullptr; - const ProjectFile classifier(filePath.toString(), ProjectFile::classify(filePath.toString())); + const ProjectFile classifier(filePath, ProjectFile::classify(filePath.toString())); if (classifier.isC()) { tc = ToolChainKitAspect::cToolChain(project->activeTarget()->kit()); } else if (classifier.isCxx() || classifier.isHeader()) { @@ -890,8 +890,8 @@ void CppModelManager::initCppTools() connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged, this, &CppModelManager::updateModifiedSourceFiles); connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally, - [this](const Utils::FilePaths &filePaths) { - updateSourceFiles(Utils::transform(filePaths, &Utils::FilePath::toString)); + [this](const FilePaths &filePaths) { + updateSourceFiles(toSet(filePaths)); }); connect(this, &CppModelManager::documentUpdated, @@ -1027,16 +1027,16 @@ void CppModelManager::ensureUpdated() d->m_dirty = false; } -QStringList CppModelManager::internalProjectFiles() const +FilePaths CppModelManager::internalProjectFiles() const { - QStringList files; + FilePaths files; for (const ProjectData &projectData : std::as_const(d->m_projectData)) { for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) { for (const ProjectFile &file : part->files) files += file.path; } } - files.removeDuplicates(); + FilePath::removeDuplicates(files); return files; } @@ -1272,13 +1272,14 @@ static QSet filteredFilesRemoved(const QSet &files, int fileSi return result; } -QFuture CppModelManager::updateSourceFiles(const QSet &sourceFiles, +QFuture CppModelManager::updateSourceFiles(const QSet &sourceFiles, ProgressNotificationMode mode) { if (sourceFiles.isEmpty() || !d->m_indexerEnabled) return QFuture(); - const QSet filteredFiles = filteredFilesRemoved(sourceFiles, indexerFileSizeLimitInMb(), + const QSet filteredFiles = filteredFilesRemoved(transform(sourceFiles, &FilePath::toString), + indexerFileSizeLimitInMb(), codeModelSettings()->ignoreFiles(), codeModelSettings()->ignorePattern()); @@ -1304,11 +1305,10 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec QMutexLocker snapshotLocker(&d->m_snapshotMutex); for (const ProjectPart::ConstPtr &projectPart : projectInfo.projectParts()) { for (const ProjectFile &cxxFile : std::as_const(projectPart->files)) { - const QSet filePaths = d->m_snapshot.allIncludesForDocument( - FilePath::fromString(cxxFile.path)); + const QSet filePaths = d->m_snapshot.allIncludesForDocument(cxxFile.path); for (const FilePath &filePath : filePaths) d->m_snapshot.remove(filePath); - d->m_snapshot.remove(FilePath::fromString(cxxFile.path)); + d->m_snapshot.remove(cxxFile.path); } } } @@ -1320,11 +1320,11 @@ const QList CppModelManager::cppEditorDocuments() con } /// \brief Remove all given files from the snapshot. -void CppModelManager::removeFilesFromSnapshot(const QSet &filesToRemove) +void CppModelManager::removeFilesFromSnapshot(const QSet &filesToRemove) { QMutexLocker snapshotLocker(&d->m_snapshotMutex); - for (const QString &file : filesToRemove) - d->m_snapshot.remove(FilePath::fromString(file)); + for (const FilePath &file : filesToRemove) + d->m_snapshot.remove(file); } class ProjectInfoComparer @@ -1342,16 +1342,16 @@ public: bool configurationChanged() const { return m_new.configurationChanged(m_old); } bool configurationOrFilesChanged() const { return m_new.configurationOrFilesChanged(m_old); } - QSet addedFiles() const + QSet addedFiles() const { - QSet addedFilesSet = m_newSourceFiles; + QSet addedFilesSet = m_newSourceFiles; addedFilesSet.subtract(m_oldSourceFiles); return addedFilesSet; } - QSet removedFiles() const + QSet removedFiles() const { - QSet removedFilesSet = m_oldSourceFiles; + QSet removedFilesSet = m_oldSourceFiles; removedFilesSet.subtract(m_newSourceFiles); return removedFilesSet; } @@ -1364,14 +1364,14 @@ public: } /// Returns a list of common files that have a changed timestamp. - QSet timeStampModifiedFiles(const Snapshot &snapshot) const + QSet timeStampModifiedFiles(const Snapshot &snapshot) const { - QSet commonSourceFiles = m_newSourceFiles; + QSet commonSourceFiles = m_newSourceFiles; commonSourceFiles.intersect(m_oldSourceFiles); QList documentsToCheck; - for (const QString &file : commonSourceFiles) { - if (Document::Ptr document = snapshot.document(FilePath::fromString(file))) + for (const FilePath &file : commonSourceFiles) { + if (Document::Ptr document = snapshot.document(file)) documentsToCheck << document; } @@ -1391,10 +1391,10 @@ private: private: const ProjectInfo &m_old; - const QSet m_oldSourceFiles; + const QSet m_oldSourceFiles; const ProjectInfo &m_new; - const QSet m_newSourceFiles; + const QSet m_newSourceFiles; }; /// Make sure that m_projectLock is locked for writing when calling this. @@ -1406,8 +1406,7 @@ void CppModelManager::recalculateProjectPartMappings() for (const ProjectPart::ConstPtr &projectPart : projectData.projectInfo->projectParts()) { d->m_projectPartIdToProjectProjectPart[projectPart->id()] = projectPart; for (const ProjectFile &cxxFile : projectPart->files) - d->m_fileToProjectParts[Utils::FilePath::fromString(cxxFile.path).canonicalPath()].append( - projectPart); + d->m_fileToProjectParts[cxxFile.path.canonicalPath()].append(projectPart); } } @@ -1464,12 +1463,12 @@ void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const } QFuture CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, - const QSet &additionalFiles) + const QSet &additionalFiles) { if (!newProjectInfo) return {}; - QSet filesToReindex; + QSet filesToReindex; QStringList removedProjectParts; bool filesRemoved = false; @@ -1481,7 +1480,7 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne { // Only hold the lock for a limited scope, so the dumping afterwards does not deadlock. QWriteLocker projectLocker(&d->m_projectLock); - const QSet newSourceFiles = newProjectInfo->sourceFiles(); + const QSet newSourceFiles = newProjectInfo->sourceFiles(); // Check if we can avoid a full reindexing const auto it = d->m_projectData.find(project); @@ -1503,18 +1502,18 @@ QFuture CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne // Otherwise check for added and modified files } else { - const QSet addedFiles = comparer.addedFiles(); + const QSet addedFiles = comparer.addedFiles(); filesToReindex.unite(addedFiles); - const QSet modifiedFiles = comparer.timeStampModifiedFiles(snapshot()); + const QSet modifiedFiles = comparer.timeStampModifiedFiles(snapshot()); filesToReindex.unite(modifiedFiles); } // Announce and purge the removed files from the snapshot - const QSet removedFiles = comparer.removedFiles(); + const QSet removedFiles = comparer.removedFiles(); if (!removedFiles.isEmpty()) { filesRemoved = true; - emit aboutToRemoveFiles(Utils::toList(removedFiles)); + emit aboutToRemoveFiles(transform(removedFiles, &FilePath::toString)); removeFilesFromSnapshot(removedFiles); } } @@ -1935,8 +1934,7 @@ void CppModelManager::GC() // The configuration file is part of the project files, which is just fine. // If single files are open, without any project, then there is no need to // keep the configuration file around. - FilePaths todo = filesInEditorSupports; - todo += transform(projectFiles(), &FilePath::fromString); + FilePaths todo = filesInEditorSupports + projectFiles(); // Collect all files that are reachable from the project files while (!todo.isEmpty()) { @@ -2032,7 +2030,7 @@ CppIndexingSupport *CppModelManager::indexingSupport() return d->m_internalIndexingSupport; } -QStringList CppModelManager::projectFiles() +FilePaths CppModelManager::projectFiles() { QWriteLocker locker(&d->m_projectLock); ensureUpdated(); diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 39861405207..3d3cc2eca12 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -87,7 +87,7 @@ public: ReservedProgressNotification }; - QFuture updateSourceFiles(const QSet &sourceFiles, + QFuture updateSourceFiles(const QSet &sourceFiles, ProgressNotificationMode mode = ReservedProgressNotification); void updateCppEditorDocuments(bool projectsUpdated = false) const; WorkingCopy workingCopy() const; @@ -103,7 +103,7 @@ public: ProjectInfoList projectInfos() const; ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const; QFuture updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, - const QSet &additionalFiles = {}); + const QSet &additionalFiles = {}); /// \return The project part with the given project file ProjectPart::ConstPtr projectPartForId(const QString &projectPartId) const; @@ -192,7 +192,7 @@ public: CppIndexingSupport *indexingSupport(); - QStringList projectFiles(); + Utils::FilePaths projectFiles(); ProjectExplorer::HeaderPaths headerPaths(); @@ -207,7 +207,7 @@ public: QThreadPool *sharedThreadPool(); - static QSet timeStampModifiedFiles(const QList &documentsToCheck); + static QSet timeStampModifiedFiles(const QList &documentsToCheck); static Internal::CppSourceProcessor *createSourceProcessor(); static const Utils::FilePath &configurationFileName(); @@ -284,13 +284,13 @@ private: void recalculateProjectPartMappings(); void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot); - void removeFilesFromSnapshot(const QSet &removedFiles); + void removeFilesFromSnapshot(const QSet &removedFiles); void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo); WorkingCopy buildWorkingCopyList(); void ensureUpdated(); - QStringList internalProjectFiles() const; + Utils::FilePaths internalProjectFiles() const; ProjectExplorer::HeaderPaths internalHeaderPaths() const; ProjectExplorer::Macros internalDefinedMacros() const; @@ -301,4 +301,4 @@ private: Internal::CppModelManagerPrivate *d; }; -} // namespace CppEditor +} // CppEditor diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index 5e66ecd0f20..ff924d66961 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -103,7 +103,7 @@ public: rpp.setQtVersion(Utils::QtMajorVersion::Qt5); const ProjectFiles rppFiles = Utils::transform(projectFiles, [](const FilePath &file) { - return ProjectFile(file.toString(), ProjectFile::classify(file.toString())); + return ProjectFile(file, ProjectFile::classify(file.toString())); }); const auto project = modelManagerTestHelper->createProject( name, Utils::FilePath::fromString(dir).pathAppended(name + ".pro")); @@ -217,7 +217,7 @@ void ModelManagerTest::testFrameworkHeaders() const FilePath source = testDataDir.fileFromSourcesDir("test_modelmanager_framework_headers.cpp"); const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {ProjectFile(source.toString(), ProjectFile::CXXSource)}); + {ProjectFile(source, ProjectFile::CXXSource)}); const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); @@ -262,7 +262,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() rpp.setMacros({{"OH_BEHAVE", "-1"}}); rpp.setHeaderPaths({HeaderPath::makeUser(testDataDir.includeDir(false))}); auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {ProjectFile(testCpp.toString(), ProjectFile::CXXSource)}); + {ProjectFile(testCpp, ProjectFile::CXXSource)}); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); QSet refreshedFiles = helper.updateProjectInfo(pi); @@ -280,7 +280,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles() // Introduce a define that will enable another define once the document is reparsed. rpp.setMacros({{"TEST_DEFINE", "1"}}); part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {ProjectFile(testCpp.toString(), ProjectFile::CXXSource)}); + {ProjectFile(testCpp, ProjectFile::CXXSource)}); pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); refreshedFiles = helper.updateProjectInfo(pi); @@ -317,9 +317,9 @@ void ModelManagerTest::testRefreshSeveralTimes() RawProjectPart rpp; rpp.setQtVersion(Utils::QtMajorVersion::Qt5); const ProjectFiles files = { - ProjectFile(testHeader1.toString(), ProjectFile::CXXHeader), - ProjectFile(testHeader2.toString(), ProjectFile::CXXHeader), - ProjectFile(testCpp.toString(), ProjectFile::CXXSource) + ProjectFile(testHeader1, ProjectFile::CXXHeader), + ProjectFile(testHeader2, ProjectFile::CXXHeader), + ProjectFile(testCpp, ProjectFile::CXXSource) }; const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); @@ -369,7 +369,7 @@ void ModelManagerTest::testRefreshTestForChanges() CppModelManager *mm = CppModelManager::instance(); const MyTestDataDir testDataDir(_("testdata_refresh")); - const QString testCpp(testDataDir.file(_("source.cpp"))); + const FilePath testCpp = testDataDir.filePath("source.cpp"); const auto project = helper.createProject(_("test_modelmanager_refresh_2"), Utils::FilePath::fromString("blubb.pro")); @@ -384,7 +384,7 @@ void ModelManagerTest::testRefreshTestForChanges() QFuture firstFuture = mm->updateProjectInfo(pi); QVERIFY(firstFuture.isStarted() || firstFuture.isRunning()); firstFuture.waitForFinished(); - const QSet refreshedFiles = helper.waitForRefreshedSourceFiles(); + const QSet refreshedFiles = helper.waitForRefreshedSourceFiles(); QCOMPARE(refreshedFiles.size(), 1); QVERIFY(refreshedFiles.contains(testCpp)); @@ -411,8 +411,8 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved() RawProjectPart rpp; rpp.setQtVersion(Utils::QtMajorVersion::Qt5); const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {{testCpp.toString(), ProjectFile::CXXSource}, - {testHeader1.toString(), ProjectFile::CXXHeader}}); + {{testCpp, ProjectFile::CXXSource}, + {testHeader1, ProjectFile::CXXHeader}}); auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); CPlusPlus::Snapshot snapshot; @@ -430,8 +430,8 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved() // Now add testHeader2 and remove testHeader1 const auto newPart = ProjectPart::create(project->projectFilePath(), rpp, {}, - {{testCpp.toString(), ProjectFile::CXXSource}, - {testHeader2.toString(), ProjectFile::CXXHeader}}); + {{testCpp, ProjectFile::CXXSource}, + {testHeader2, ProjectFile::CXXHeader}}); pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {newPart}); refreshedFiles = helper.updateProjectInfo(pi); @@ -468,7 +468,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() RawProjectPart rpp; rpp.setQtVersion(Utils::QtMajorVersion::Qt5); auto files = Utils::transform(initialProjectFilePaths, [](const FilePath &f) { - return ProjectFile(f.toString(), ProjectFile::CXXSource); + return ProjectFile(f, ProjectFile::CXXSource); }); auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); @@ -501,7 +501,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange() // Add or remove source file. The configuration stays the same. files = Utils::transform(finalProjectFilePaths, [](const FilePath &f) { - return ProjectFile(f.toString(), ProjectFile::CXXSource); + return ProjectFile(f, ProjectFile::CXXSource); }); part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); @@ -732,9 +732,9 @@ void ModelManagerTest::testDefinesPerProject() ModelManagerTestHelper helper; MyTestDataDir testDataDirectory(_("testdata_defines")); - const QString main1File = testDataDirectory.file(_("main1.cpp")); - const QString main2File = testDataDirectory.file(_("main2.cpp")); - const QString header = testDataDirectory.file(_("header.h")); + const FilePath main1File = testDataDirectory.filePath("main1.cpp"); + const FilePath main2File = testDataDirectory.filePath("main2.cpp"); + const FilePath header = testDataDirectory.filePath("header.h"); CppModelManager *mm = CppModelManager::instance(); @@ -766,7 +766,7 @@ void ModelManagerTest::testDefinesPerProject() struct Data { QString firstDeclarationName; - QString fileName; + FilePath filePath; } d[] = { {_("one"), main1File}, {_("two"), main2File} @@ -774,15 +774,14 @@ void ModelManagerTest::testDefinesPerProject() for (auto &i : d) { const QString firstDeclarationName = i.firstDeclarationName; - const Utils::FilePath filePath = Utils::FilePath::fromString(i.fileName); - Core::IEditor *editor = Core::EditorManager::openEditor(filePath); + Core::IEditor *editor = Core::EditorManager::openEditor(i.filePath); EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QVERIFY(mm->isCppEditor(editor)); - Document::Ptr doc = mm->document(filePath); + Document::Ptr doc = mm->document(i.filePath); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -794,9 +793,9 @@ void ModelManagerTest::testPrecompiledHeaders() MyTestDataDir testDataDirectory(_("testdata_defines")); const FilePath main1File = testDataDirectory.filePath("main1.cpp"); const FilePath main2File = testDataDirectory.filePath("main2.cpp"); - const QString header = testDataDirectory.file(_("header.h")); - const QString pch1File = testDataDirectory.file(_("pch1.h")); - const QString pch2File = testDataDirectory.file(_("pch2.h")); + const FilePath header = testDataDirectory.filePath("header.h"); + const FilePath pch1File = testDataDirectory.filePath("pch1.h"); + const FilePath pch2File = testDataDirectory.filePath("pch2.h"); CppModelManager *mm = CppModelManager::instance(); @@ -806,18 +805,18 @@ void ModelManagerTest::testPrecompiledHeaders() RawProjectPart rpp1; rpp1.setProjectFileLocation("project1.projectfile"); rpp1.setQtVersion(Utils::QtMajorVersion::None); - rpp1.setPreCompiledHeaders({pch1File}); + rpp1.setPreCompiledHeaders({pch1File.toString()}); rpp1.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); const auto part1 = ProjectPart::create(project->projectFilePath(), rpp1, {}, - {{main1File.toString(), ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); + {{main1File, ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); RawProjectPart rpp2; rpp2.setProjectFileLocation("project2.projectfile"); rpp2.setQtVersion(Utils::QtMajorVersion::None); - rpp2.setPreCompiledHeaders({pch2File}); + rpp2.setPreCompiledHeaders({pch2File.toString()}); rpp2.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); const auto part2 = ProjectPart::create(project->projectFilePath(), rpp2, {}, - {{main2File.toString(), ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); + {{main2File, ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2}); @@ -874,9 +873,9 @@ void ModelManagerTest::testDefinesPerEditor() ModelManagerTestHelper helper; MyTestDataDir testDataDirectory(_("testdata_defines")); - const QString main1File = testDataDirectory.file(_("main1.cpp")); - const QString main2File = testDataDirectory.file(_("main2.cpp")); - const QString header = testDataDirectory.file(_("header.h")); + const FilePath main1File = testDataDirectory.filePath("main1.cpp"); + const FilePath main2File = testDataDirectory.filePath("main2.cpp"); + const FilePath header = testDataDirectory.filePath("header.h"); CppModelManager *mm = CppModelManager::instance(); @@ -914,8 +913,7 @@ void ModelManagerTest::testDefinesPerEditor() const QString editorDefines = i.editorDefines; const QString firstDeclarationName = i.firstDeclarationName; - Core::IEditor *editor = Core::EditorManager::openEditor( - Utils::FilePath::fromString(main1File)); + Core::IEditor *editor = Core::EditorManager::openEditor(main1File); EditorCloser closer(editor); QVERIFY(editor); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); @@ -929,7 +927,7 @@ void ModelManagerTest::testDefinesPerEditor() parser->update({CppModelManager::instance()->workingCopy(), nullptr, Utils::Language::Cxx, false}); - Document::Ptr doc = mm->document(FilePath::fromString(main1File)); + Document::Ptr doc = mm->document(main1File); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); } } @@ -970,7 +968,7 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate() RawProjectPart rpp; rpp.setQtVersion(Utils::QtMajorVersion::None); const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, - {{fileA.toString(), ProjectFile::CXXSource}, {fileB.toString(), ProjectFile::CXXSource}}); + {{fileA, ProjectFile::CXXSource}, {fileB, ProjectFile::CXXSource}}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); helper.updateProjectInfo(pi); @@ -1004,23 +1002,22 @@ void ModelManagerTest::testRenameIncludes() const MyTestDataDir testDir(_("testdata_project1")); // Copy test files to a temporary directory - QSet sourceFiles; + QSet sourceFiles; for (const QString &fileName : std::as_const(fileNames)) { const QString &file = workingDir.filePath(fileName); QVERIFY(QFile::copy(testDir.file(fileName), file)); // Saving source file names for the model manager update, // so we can update just the relevant files. if (ProjectFile::classify(file) == ProjectFile::CXXSource) - sourceFiles.insert(file); + sourceFiles.insert(FilePath::fromString(file)); } // Update the c++ model manager and check for the old includes modelManager->updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); CPlusPlus::Snapshot snapshot = modelManager->snapshot(); - for (const QString &sourceFile : std::as_const(sourceFiles)) { - QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), - QSet{oldHeader}); + for (const FilePath &sourceFile : std::as_const(sourceFiles)) { + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet{oldHeader}); } // Renaming the header @@ -1032,9 +1029,8 @@ void ModelManagerTest::testRenameIncludes() modelManager->updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); snapshot = modelManager->snapshot(); - for (const QString &sourceFile : std::as_const(sourceFiles)) { - QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), - QSet{newHeader}); + for (const FilePath &sourceFile : std::as_const(sourceFiles)) { + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet{newHeader}); } } @@ -1066,22 +1062,22 @@ void ModelManagerTest::testRenameIncludesInEditor() helper.resetRefreshedSourceFiles(); // Copy test files to a temporary directory - QSet sourceFiles; + QSet sourceFiles; for (const QString &fileName : fileNames) { const QString &file = workingDir.filePath(fileName); QVERIFY(QFile::copy(testDir.file(fileName), file)); // Saving source file names for the model manager update, // so we can update just the relevant files. if (ProjectFile::classify(file) == ProjectFile::CXXSource) - sourceFiles.insert(file); + sourceFiles.insert(FilePath::fromString(file)); } // Update the c++ model manager and check for the old includes modelManager->updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); CPlusPlus::Snapshot snapshot = modelManager->snapshot(); - for (const QString &sourceFile : std::as_const(sourceFiles)) { - QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), + for (const FilePath &sourceFile : std::as_const(sourceFiles)) { + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet{headerWithPragmaOnce}); } @@ -1160,8 +1156,8 @@ void ModelManagerTest::testRenameIncludesInEditor() modelManager->updateSourceFiles(sourceFiles).waitForFinished(); QCoreApplication::processEvents(); snapshot = modelManager->snapshot(); - for (const QString &sourceFile : std::as_const(sourceFiles)) { - QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), + for (const FilePath &sourceFile : std::as_const(sourceFiles)) { + QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet{renamedHeaderWithPragmaOnce}); } } diff --git a/src/plugins/cppeditor/cppprojectfile.cpp b/src/plugins/cppeditor/cppprojectfile.cpp index 392d1460adc..c960150a259 100644 --- a/src/plugins/cppeditor/cppprojectfile.cpp +++ b/src/plugins/cppeditor/cppprojectfile.cpp @@ -13,7 +13,7 @@ namespace CppEditor { -ProjectFile::ProjectFile(const QString &filePath, Kind kind, bool active) +ProjectFile::ProjectFile(const Utils::FilePath &filePath, Kind kind, bool active) : path(filePath) , kind(kind) , active(active) diff --git a/src/plugins/cppeditor/cppprojectfile.h b/src/plugins/cppeditor/cppprojectfile.h index 1c78d210fb8..529d0bb6558 100644 --- a/src/plugins/cppeditor/cppprojectfile.h +++ b/src/plugins/cppeditor/cppprojectfile.h @@ -5,7 +5,7 @@ #include "cppeditor_global.h" -#include +#include namespace Utils { class FilePath; } @@ -31,7 +31,7 @@ public: }; ProjectFile() = default; - ProjectFile(const QString &filePath, Kind kind, bool active = true); + ProjectFile(const Utils::FilePath &filePath, Kind kind, bool active = true); static Kind classifyByMimeType(const QString &mt); static Kind classify(const QString &filePath); @@ -58,7 +58,7 @@ public: friend QDebug operator<<(QDebug stream, const CppEditor::ProjectFile &projectFile); public: - QString path; + Utils::FilePath path; Kind kind = Unclassified; bool active = true; }; @@ -67,4 +67,4 @@ using ProjectFiles = QVector; const char *projectFileKindToText(ProjectFile::Kind kind); -} // namespace CppEditor +} // CppEditor diff --git a/src/plugins/cppeditor/cppprojectfilecategorizer.cpp b/src/plugins/cppeditor/cppprojectfilecategorizer.cpp index 9a795ba6e19..182c50ada55 100644 --- a/src/plugins/cppeditor/cppprojectfilecategorizer.cpp +++ b/src/plugins/cppeditor/cppprojectfilecategorizer.cpp @@ -4,6 +4,9 @@ #include "cppprojectfilecategorizer.h" #include +#include + +using namespace Utils; namespace CppEditor { @@ -38,7 +41,7 @@ ProjectFiles ProjectFileCategorizer::classifyFiles(const QStringList &filePaths, ProjectFiles ambiguousHeaders; for (const QString &filePath : filePaths) { - const ProjectFile projectFile(filePath, + const ProjectFile projectFile(FilePath::fromString(filePath), getMimeType ? ProjectFile::classifyByMimeType(getMimeType(filePath)) : ProjectFile::classify(filePath), diff --git a/src/plugins/cppeditor/cppprojectupdater.cpp b/src/plugins/cppeditor/cppprojectupdater.cpp index 115f71084ca..46b4ca1f141 100644 --- a/src/plugins/cppeditor/cppprojectupdater.cpp +++ b/src/plugins/cppeditor/cppprojectupdater.cpp @@ -19,6 +19,7 @@ #include using namespace ProjectExplorer; +using namespace Utils; namespace CppEditor { @@ -134,11 +135,11 @@ void CppProjectUpdater::checkForExtraCompilersFinished() m_projectUpdateFutureInterface.reset(); QList extraCompilers; - QSet compilerFiles; + QSet compilerFiles; for (const QPointer &compiler : std::as_const(m_extraCompilers)) { if (compiler) { extraCompilers += compiler.data(); - compilerFiles += Utils::transform(compiler->targets(), &Utils::FilePath::toString); + compilerFiles += Utils::toSet(compiler->targets()); } } GeneratedCodeModelSupport::update(extraCompilers); diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp index 9fc2102eda2..1cce747fc66 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.cpp +++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp @@ -244,7 +244,7 @@ void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection, void CppRefactoringChangesData::fileChanged(const FilePath &filePath) { - m_modelManager->updateSourceFiles({filePath.toString()}); + m_modelManager->updateSourceFiles({filePath}); } } // CppEditor diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 4070d44e71b..272f3ffe119 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -283,8 +283,7 @@ CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEdito bool TestCase::parseFiles(const QSet &filePaths) { - QSet filePaths_ = transform(filePaths, &FilePath::toString); - CppModelManager::instance()->updateSourceFiles(filePaths_).waitForFinished(); + CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); QCoreApplication::processEvents(); const CPlusPlus::Snapshot snapshot = globalSnapshot(); if (snapshot.isEmpty()) { diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index dcea22410c3..b4b60d6828c 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -137,9 +137,9 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti for (const ProjectInfo::ConstPtr &info : projectInfos) { qDebug() << "Project" << info->projectFilePath().toUserOutput() << "- files to process:" << info->sourceFiles().size(); - const QSet sourceFiles = info->sourceFiles(); - for (const QString &sourceFile : sourceFiles) - filesToOpen << FilePath::fromString(sourceFile); + const QSet sourceFiles = info->sourceFiles(); + for (const FilePath &sourceFile : sourceFiles) + filesToOpen << sourceFile; } Utils::sort(filesToOpen); diff --git a/src/plugins/cppeditor/modelmanagertesthelper.cpp b/src/plugins/cppeditor/modelmanagertesthelper.cpp index 99c2dfbfaa1..f4114c33b27 100644 --- a/src/plugins/cppeditor/modelmanagertesthelper.cpp +++ b/src/plugins/cppeditor/modelmanagertesthelper.cpp @@ -83,7 +83,7 @@ QSet ModelManagerTestHelper::updateProjectInfo( resetRefreshedSourceFiles(); CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished(); QCoreApplication::processEvents(); - return Utils::transform(waitForRefreshedSourceFiles(), &FilePath::fromString); + return waitForRefreshedSourceFiles(); } void ModelManagerTestHelper::resetRefreshedSourceFiles() @@ -92,12 +92,12 @@ void ModelManagerTestHelper::resetRefreshedSourceFiles() m_refreshHappened = false; } -QSet ModelManagerTestHelper::waitForRefreshedSourceFiles() +QSet ModelManagerTestHelper::waitForRefreshedSourceFiles() { while (!m_refreshHappened) QCoreApplication::processEvents(); - return m_lastRefreshedSourceFiles; + return Utils::transform(m_lastRefreshedSourceFiles, &FilePath::fromString); } void ModelManagerTestHelper::waitForFinishedGc() diff --git a/src/plugins/cppeditor/modelmanagertesthelper.h b/src/plugins/cppeditor/modelmanagertesthelper.h index e392623e935..44730bbb52d 100644 --- a/src/plugins/cppeditor/modelmanagertesthelper.h +++ b/src/plugins/cppeditor/modelmanagertesthelper.h @@ -43,7 +43,7 @@ public: QSet updateProjectInfo(const ProjectInfo::ConstPtr &projectInfo); void resetRefreshedSourceFiles(); - QSet waitForRefreshedSourceFiles(); + QSet waitForRefreshedSourceFiles(); void waitForFinishedGc(); signals: diff --git a/src/plugins/cppeditor/projectinfo.cpp b/src/plugins/cppeditor/projectinfo.cpp index c67c8aef847..3e1f5154e12 100644 --- a/src/plugins/cppeditor/projectinfo.cpp +++ b/src/plugins/cppeditor/projectinfo.cpp @@ -9,6 +9,8 @@ #include #include +using namespace Utils; + namespace CppEditor { ProjectInfo::ConstPtr ProjectInfo::create(const ProjectExplorer::ProjectUpdateInfo &updateInfo, @@ -17,16 +19,6 @@ ProjectInfo::ConstPtr ProjectInfo::create(const ProjectExplorer::ProjectUpdateIn return ConstPtr(new ProjectInfo(updateInfo, projectParts)); } -const QVector ProjectInfo::projectParts() const -{ - return m_projectParts; -} - -const QSet ProjectInfo::sourceFiles() const -{ - return m_sourceFiles; -} - bool ProjectInfo::operator ==(const ProjectInfo &other) const { return m_projectName == other.m_projectName @@ -58,9 +50,9 @@ bool ProjectInfo::configurationOrFilesChanged(const ProjectInfo &other) const return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles; } -static QSet getSourceFiles(const QVector &projectParts) +static QSet getSourceFiles(const QVector &projectParts) { - QSet sourceFiles; + QSet sourceFiles; for (const ProjectPart::ConstPtr &part : projectParts) { for (const ProjectFile &file : std::as_const(part->files)) sourceFiles.insert(file.path); diff --git a/src/plugins/cppeditor/projectinfo.h b/src/plugins/cppeditor/projectinfo.h index fd1c114c30d..26f92eb6a7f 100644 --- a/src/plugins/cppeditor/projectinfo.h +++ b/src/plugins/cppeditor/projectinfo.h @@ -10,7 +10,8 @@ #include #include #include -#include + +#include #include #include @@ -28,8 +29,8 @@ public: static ConstPtr create(const ProjectExplorer::ProjectUpdateInfo &updateInfo, const QVector &projectParts); - const QVector projectParts() const; - const QSet sourceFiles() const; + const QVector &projectParts() const { return m_projectParts; } + const QSet &sourceFiles() const { return m_sourceFiles; } QString projectName() const { return m_projectName; } Utils::FilePath projectFilePath() const { return m_projectFilePath; } Utils::FilePath projectRoot() const { return m_projectFilePath.parentDir(); } @@ -51,7 +52,7 @@ private: const Utils::FilePath m_projectFilePath; const Utils::FilePath m_buildRoot; const ProjectExplorer::HeaderPaths m_headerPaths; - const QSet m_sourceFiles; + const QSet m_sourceFiles; const ProjectExplorer::Macros m_defines; }; diff --git a/src/plugins/todo/cpptodoitemsscanner.cpp b/src/plugins/todo/cpptodoitemsscanner.cpp index dd6f543f405..4f0443bb162 100644 --- a/src/plugins/todo/cpptodoitemsscanner.cpp +++ b/src/plugins/todo/cpptodoitemsscanner.cpp @@ -14,6 +14,8 @@ #include +using namespace Utils; + namespace Todo { namespace Internal { @@ -35,7 +37,7 @@ void CppTodoItemsScanner::scannerParamsChanged() CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); - QSet filesToBeUpdated; + QSet filesToBeUpdated; const CppEditor::ProjectInfoList infoList = modelManager->projectInfos(); for (const CppEditor::ProjectInfo::ConstPtr &info : infoList) filesToBeUpdated.unite(info->sourceFiles());