CppEditor: Use FilePath for ProjectPath::m_sourceFiles

... and update using code.

Change-Id: I682727a4b2982dba388e7cc7b9488225748d591f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-24 19:16:47 +01:00
parent 887db6b419
commit b87f0519e3
26 changed files with 158 additions and 173 deletions

View File

@@ -505,14 +505,13 @@ QSet<QString> internalTargets(const TestTreeItem &item)
if (!projectInfo) if (!projectInfo)
return {}; return {};
const Utils::FilePath filePath = item.filePath(); const Utils::FilePath filePath = item.filePath();
const QString file = filePath.toString();
const QVector<CppEditor::ProjectPart::ConstPtr> projectParts = projectInfo->projectParts(); const QVector<CppEditor::ProjectPart::ConstPtr> projectParts = projectInfo->projectParts();
if (projectParts.isEmpty()) if (projectParts.isEmpty())
return cppMM->dependingInternalTargets(item.filePath()); return cppMM->dependingInternalTargets(item.filePath());
for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectParts) { for (const CppEditor::ProjectPart::ConstPtr &projectPart : projectParts) {
if (Utils::FilePath::fromString(projectPart->projectFile) == item.proFile() if (Utils::FilePath::fromString(projectPart->projectFile) == item.proFile()
&& Utils::anyOf(projectPart->files, [&file](const CppEditor::ProjectFile &pf) { && Utils::anyOf(projectPart->files, [&filePath] (const CppEditor::ProjectFile &pf) {
return pf.path == file; return pf.path == filePath;
})) { })) {
result.insert(projectPart->buildSystemTarget); result.insert(projectPart->buildSystemTarget);
if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable) if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable)

View File

@@ -73,13 +73,12 @@ static void extractAllFiles(const DebuggerRunTool *runTool, QStringList &include
for (const ProjectFile &file : std::as_const(part->files)) { for (const ProjectFile &file : std::as_const(part->files)) {
if (!file.active) if (!file.active)
continue; continue;
const auto path = FilePath::fromString(file.path); if (file.isHeader() && !headers.contains(file.path))
if (file.isHeader() && !headers.contains(path)) headers.push_back(file.path);
headers.push_back(path); else if (file.isSource() && !sources.contains(file.path))
else if (file.isSource() && !sources.contains(path)) sources.push_back(file.path);
sources.push_back(path); else if (file.path.endsWith(".s") && !assemblers.contains(file.path))
else if (file.path.endsWith(".s") && !assemblers.contains(path)) assemblers.push_back(file.path);
assemblers.push_back(path);
} }
for (const HeaderPath &include : std::as_const(part->headerPaths)) { for (const HeaderPath &include : std::as_const(part->headerPaths)) {
if (!includes.contains(include.path)) if (!includes.contains(include.path))

View File

@@ -81,6 +81,7 @@ using namespace LanguageClient;
using namespace LanguageServerProtocol; using namespace LanguageServerProtocol;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace TextEditor; using namespace TextEditor;
using namespace Utils;
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Internal { namespace Internal {
@@ -341,7 +342,7 @@ static void addToCompilationDb(QJsonObject &cdb,
// Should we make use of them or keep using our own? // Should we make use of them or keep using our own?
args.prepend("clang"); args.prepend("clang");
const QString fileString = Utils::FilePath::fromString(sourceFile.path).toUserOutput(); const QString fileString = sourceFile.path.toUserOutput();
args.append(fileString); args.append(fileString);
QJsonObject value; QJsonObject value;
value.insert("workingDirectory", workingDir.toString()); value.insert("workingDirectory", workingDir.toString());
@@ -819,7 +820,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath,
CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder( CppEditor::CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder(
*projectPart, warningsConfigForProject(project()), includeDir, *projectPart, warningsConfigForProject(project()), includeDir,
ProjectExplorer::Macro::toMacros(config.editorDefines)); ProjectExplorer::Macro::toMacros(config.editorDefines));
const CppEditor::ProjectFile file(filePath.toString(), const CppEditor::ProjectFile file(filePath,
CppEditor::ProjectFile::classify(filePath.toString())); CppEditor::ProjectFile::classify(filePath.toString()));
const QJsonArray projectPartOptions = fullProjectPartOptions( const QJsonArray projectPartOptions = fullProjectPartOptions(
optionsBuilder, globalClangOptions()); optionsBuilder, globalClangOptions());
@@ -833,7 +834,7 @@ void ClangdClient::updateParserConfig(const Utils::FilePath &filePath,
emit configChanged(); emit configChanged();
} }
void ClangdClient::switchIssuePaneEntries(const Utils::FilePath &filePath) void ClangdClient::switchIssuePaneEntries(const FilePath &filePath)
{ {
TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS); TaskHub::clearTasks(Constants::TASK_CATEGORY_DIAGNOSTICS);
const Tasks tasks = d->issuePaneEntries.value(filePath); const Tasks tasks = d->issuePaneEntries.value(filePath);

View File

@@ -110,13 +110,13 @@ static QJsonObject createFileObject(const FilePath &buildDir,
bool clStyle) bool clStyle)
{ {
QJsonObject fileObject; QJsonObject fileObject;
fileObject["file"] = projFile.path; fileObject["file"] = projFile.path.toString();
QJsonArray args; QJsonArray args;
if (purpose == CompilationDbPurpose::Project) { if (purpose == CompilationDbPurpose::Project) {
args = QJsonArray::fromStringList(arguments); 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 if (projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID
|| projectPart.toolchainType == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID) { || projectPart.toolchainType == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID) {
if (!ProjectFile::isObjC(kind)) { 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.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["arguments"] = args;
fileObject["directory"] = buildDir.toString(); fileObject["directory"] = buildDir.toString();
return fileObject; return fileObject;
@@ -269,7 +269,7 @@ QJsonArray clangOptionsForFile(const ProjectFile &file, const ProjectPart &proje
? ProjectFile::CHeader : ProjectFile::CXXHeader; ? ProjectFile::CHeader : ProjectFile::CXXHeader;
} }
if (usePch == UsePrecompiledHeaders::Yes if (usePch == UsePrecompiledHeaders::Yes
&& projectPart.precompiledHeaders.contains(file.path)) { && projectPart.precompiledHeaders.contains(file.path.path())) {
usePch = UsePrecompiledHeaders::No; usePch = UsePrecompiledHeaders::No;
} }
optionsBuilder.updateFileLanguage(fileKind); optionsBuilder.updateFileLanguage(fileKind);

View File

@@ -312,16 +312,14 @@ static FileInfos sortedFileInfos(const QVector<CppEditor::ProjectPart::ConstPtr>
for (const CppEditor::ProjectFile &file : std::as_const(projectPart->files)) { for (const CppEditor::ProjectFile &file : std::as_const(projectPart->files)) {
QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unclassified, continue); QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unclassified, continue);
QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unsupported, continue); QTC_ASSERT(file.kind != CppEditor::ProjectFile::Unsupported, continue);
if (file.path == CppEditor::CppModelManager::configurationFileName().path()) if (file.path == CppEditor::CppModelManager::configurationFileName())
continue; continue;
if (file.active if (file.active
&& (CppEditor::ProjectFile::isSource(file.kind) && (CppEditor::ProjectFile::isSource(file.kind)
|| CppEditor::ProjectFile::isHeader(file.kind))) { || CppEditor::ProjectFile::isHeader(file.kind))) {
ProjectFile::Kind sourceKind = CppEditor::ProjectFile::sourceKind(file.kind); ProjectFile::Kind sourceKind = CppEditor::ProjectFile::sourceKind(file.kind);
fileInfos.emplace_back(Utils::FilePath::fromString(file.path), fileInfos.emplace_back(file.path, sourceKind, projectPart);
sourceKind,
projectPart);
} }
} }
} }

View File

@@ -135,20 +135,19 @@ static FileInfo getFileInfo(const FilePath &file, Project *project)
for (const ProjectFile &projectFile : std::as_const(projectPart->files)) { for (const ProjectFile &projectFile : std::as_const(projectPart->files)) {
QTC_ASSERT(projectFile.kind != ProjectFile::Unclassified, continue); QTC_ASSERT(projectFile.kind != ProjectFile::Unclassified, continue);
QTC_ASSERT(projectFile.kind != ProjectFile::Unsupported, continue); QTC_ASSERT(projectFile.kind != ProjectFile::Unsupported, continue);
if (projectFile.path == CppModelManager::configurationFileName().path()) if (projectFile.path == CppModelManager::configurationFileName())
continue; continue;
const auto projectFilePath = FilePath::fromString(projectFile.path); if (file != projectFile.path)
if (file != projectFilePath)
continue; continue;
if (!projectFile.active) if (!projectFile.active)
continue; continue;
// found the best candidate, early return // found the best candidate, early return
ProjectFile::Kind sourceKind = ProjectFile::sourceKind(projectFile.kind); ProjectFile::Kind sourceKind = ProjectFile::sourceKind(projectFile.kind);
if (projectPart->buildTargetType != BuildTargetType::Unknown) if (projectPart->buildTargetType != BuildTargetType::Unknown)
return FileInfo(projectFilePath, sourceKind, projectPart); return FileInfo(projectFile.path, sourceKind, projectPart);
// found something but keep looking for better candidates // found something but keep looking for better candidates
if (candidate.projectPart.isNull()) if (candidate.projectPart.isNull())
candidate = FileInfo(projectFilePath, sourceKind, projectPart); candidate = FileInfo(projectFile.path, sourceKind, projectPart);
} }
} }

View File

@@ -22,10 +22,11 @@
#include <QThread> #include <QThread>
using namespace Utils;
namespace Cppcheck::Internal { namespace Cppcheck::Internal {
CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progressId) :
const Utils::Id &progressId) :
m_manager(manager), m_manager(manager),
m_progressRegexp("^.* checked (\\d+)% done$"), m_progressRegexp("^.* checked (\\d+)% done$"),
m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"), m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"),
@@ -194,13 +195,12 @@ void CppcheckTool::check(const Utils::FilePaths &files)
return; return;
} }
std::map<CppEditor::ProjectPart::ConstPtr, Utils::FilePaths> groups; std::map<CppEditor::ProjectPart::ConstPtr, FilePaths> groups;
for (const Utils::FilePath &file : std::as_const(filtered)) { for (const FilePath &file : std::as_const(filtered)) {
const QString stringed = file.toString();
for (const CppEditor::ProjectPart::ConstPtr &part : parts) { for (const CppEditor::ProjectPart::ConstPtr &part : parts) {
using CppEditor::ProjectFile; using CppEditor::ProjectFile;
QTC_ASSERT(part, continue); 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)) if (Utils::contains(part->files, match))
groups[part].push_back(file); groups[part].push_back(file);
} }

View File

@@ -78,8 +78,7 @@ void CppcheckTrigger::checkEditors(const QList<IEditor *> &editors)
if (!m_currentProject->isKnownFile(path)) if (!m_currentProject->isKnownFile(path))
continue; continue;
const QString &pathString = path.toString(); if (!info->sourceFiles().contains(path))
if (!info->sourceFiles().contains(pathString))
continue; continue;
connect(document, &IDocument::aboutToReload, connect(document, &IDocument::aboutToReload,

View File

@@ -29,7 +29,7 @@ AbstractEditorSupport::~AbstractEditorSupport()
void AbstractEditorSupport::updateDocument() void AbstractEditorSupport::updateDocument()
{ {
++m_revision; ++m_revision;
m_modelmanager->updateSourceFiles(QSet<QString>{filePath().toString()}); m_modelmanager->updateSourceFiles({filePath()});
} }
void AbstractEditorSupport::notifyAboutUpdatedContents() const void AbstractEditorSupport::notifyAboutUpdatedContents() const

View File

@@ -240,11 +240,10 @@ QVariant ProjectFilesModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
const int row = index.row(); const int row = index.row();
const int column = index.column(); const int column = index.column();
if (column == FileKindColumn) { if (column == FileKindColumn)
return CMI::Utils::toString(m_files.at(row).kind); return CMI::Utils::toString(m_files.at(row).kind);
} else if (column == FilePathColumn) { if (column == FilePathColumn)
return m_files.at(row).path; return m_files.at(row).path.toVariant();
}
} else if (role == Qt::ForegroundRole) { } else if (role == Qt::ForegroundRole) {
if (!m_files.at(index.row()).active) { if (!m_files.at(index.row()).active) {
return QApplication::palette().color(QPalette::ColorGroup::Disabled, return QApplication::palette().color(QPalette::ColorGroup::Disabled,

View File

@@ -457,8 +457,7 @@ void CppFindReferences::onReplaceButtonClicked(Core::SearchResult *search,
{ {
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase); const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!filePaths.isEmpty()) { if (!filePaths.isEmpty()) {
m_modelManager->updateSourceFiles( m_modelManager->updateSourceFiles(Utils::toSet(filePaths));
Utils::transform<QSet>(filePaths, &Utils::FilePath::toString));
SearchResultWindow::instance()->hide(); SearchResultWindow::instance()->hide();
} }

View File

@@ -169,7 +169,7 @@ public:
// The members below are cached/(re)calculated from the projects and/or their project parts // The members below are cached/(re)calculated from the projects and/or their project parts
bool m_dirty; bool m_dirty;
QStringList m_projectFiles; Utils::FilePaths m_projectFiles;
ProjectExplorer::HeaderPaths m_headerPaths; ProjectExplorer::HeaderPaths m_headerPaths;
ProjectExplorer::Macros m_definedMacros; ProjectExplorer::Macros m_definedMacros;
@@ -262,9 +262,9 @@ const char pp_configuration[] =
"#define __ptr32\n" "#define __ptr32\n"
"#define __ptr64\n"; "#define __ptr64\n";
QSet<QString> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck) QSet<FilePath> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck)
{ {
QSet<QString> sourceFiles; QSet<FilePath> sourceFiles;
for (const Document::Ptr &doc : documentsToCheck) { for (const Document::Ptr &doc : documentsToCheck) {
const QDateTime lastModified = doc->lastModified(); const QDateTime lastModified = doc->lastModified();
@@ -273,7 +273,7 @@ QSet<QString> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr>
const FilePath filePath = doc->filePath(); const FilePath filePath = doc->filePath();
if (filePath.exists() && filePath.lastModified() != lastModified) 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 ToolChain * tc = nullptr;
const ProjectFile classifier(filePath.toString(), ProjectFile::classify(filePath.toString())); const ProjectFile classifier(filePath, ProjectFile::classify(filePath.toString()));
if (classifier.isC()) { if (classifier.isC()) {
tc = ToolChainKitAspect::cToolChain(project->activeTarget()->kit()); tc = ToolChainKitAspect::cToolChain(project->activeTarget()->kit());
} else if (classifier.isCxx() || classifier.isHeader()) { } else if (classifier.isCxx() || classifier.isHeader()) {
@@ -890,8 +890,8 @@ void CppModelManager::initCppTools()
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged, connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged,
this, &CppModelManager::updateModifiedSourceFiles); this, &CppModelManager::updateModifiedSourceFiles);
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally, connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally,
[this](const Utils::FilePaths &filePaths) { [this](const FilePaths &filePaths) {
updateSourceFiles(Utils::transform<QSet>(filePaths, &Utils::FilePath::toString)); updateSourceFiles(toSet(filePaths));
}); });
connect(this, &CppModelManager::documentUpdated, connect(this, &CppModelManager::documentUpdated,
@@ -1027,16 +1027,16 @@ void CppModelManager::ensureUpdated()
d->m_dirty = false; 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 ProjectData &projectData : std::as_const(d->m_projectData)) {
for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) { for (const ProjectPart::ConstPtr &part : projectData.projectInfo->projectParts()) {
for (const ProjectFile &file : part->files) for (const ProjectFile &file : part->files)
files += file.path; files += file.path;
} }
} }
files.removeDuplicates(); FilePath::removeDuplicates(files);
return files; return files;
} }
@@ -1272,13 +1272,14 @@ static QSet<QString> filteredFilesRemoved(const QSet<QString> &files, int fileSi
return result; return result;
} }
QFuture<void> CppModelManager::updateSourceFiles(const QSet<QString> &sourceFiles, QFuture<void> CppModelManager::updateSourceFiles(const QSet<FilePath> &sourceFiles,
ProgressNotificationMode mode) ProgressNotificationMode mode)
{ {
if (sourceFiles.isEmpty() || !d->m_indexerEnabled) if (sourceFiles.isEmpty() || !d->m_indexerEnabled)
return QFuture<void>(); return QFuture<void>();
const QSet<QString> filteredFiles = filteredFilesRemoved(sourceFiles, indexerFileSizeLimitInMb(), const QSet<QString> filteredFiles = filteredFilesRemoved(transform(sourceFiles, &FilePath::toString),
indexerFileSizeLimitInMb(),
codeModelSettings()->ignoreFiles(), codeModelSettings()->ignoreFiles(),
codeModelSettings()->ignorePattern()); codeModelSettings()->ignorePattern());
@@ -1304,11 +1305,10 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec
QMutexLocker snapshotLocker(&d->m_snapshotMutex); QMutexLocker snapshotLocker(&d->m_snapshotMutex);
for (const ProjectPart::ConstPtr &projectPart : projectInfo.projectParts()) { for (const ProjectPart::ConstPtr &projectPart : projectInfo.projectParts()) {
for (const ProjectFile &cxxFile : std::as_const(projectPart->files)) { for (const ProjectFile &cxxFile : std::as_const(projectPart->files)) {
const QSet<FilePath> filePaths = d->m_snapshot.allIncludesForDocument( const QSet<FilePath> filePaths = d->m_snapshot.allIncludesForDocument(cxxFile.path);
FilePath::fromString(cxxFile.path));
for (const FilePath &filePath : filePaths) for (const FilePath &filePath : filePaths)
d->m_snapshot.remove(filePath); 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<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() con
} }
/// \brief Remove all given files from the snapshot. /// \brief Remove all given files from the snapshot.
void CppModelManager::removeFilesFromSnapshot(const QSet<QString> &filesToRemove) void CppModelManager::removeFilesFromSnapshot(const QSet<FilePath> &filesToRemove)
{ {
QMutexLocker snapshotLocker(&d->m_snapshotMutex); QMutexLocker snapshotLocker(&d->m_snapshotMutex);
for (const QString &file : filesToRemove) for (const FilePath &file : filesToRemove)
d->m_snapshot.remove(FilePath::fromString(file)); d->m_snapshot.remove(file);
} }
class ProjectInfoComparer class ProjectInfoComparer
@@ -1342,16 +1342,16 @@ public:
bool configurationChanged() const { return m_new.configurationChanged(m_old); } bool configurationChanged() const { return m_new.configurationChanged(m_old); }
bool configurationOrFilesChanged() const { return m_new.configurationOrFilesChanged(m_old); } bool configurationOrFilesChanged() const { return m_new.configurationOrFilesChanged(m_old); }
QSet<QString> addedFiles() const QSet<FilePath> addedFiles() const
{ {
QSet<QString> addedFilesSet = m_newSourceFiles; QSet<FilePath> addedFilesSet = m_newSourceFiles;
addedFilesSet.subtract(m_oldSourceFiles); addedFilesSet.subtract(m_oldSourceFiles);
return addedFilesSet; return addedFilesSet;
} }
QSet<QString> removedFiles() const QSet<FilePath> removedFiles() const
{ {
QSet<QString> removedFilesSet = m_oldSourceFiles; QSet<FilePath> removedFilesSet = m_oldSourceFiles;
removedFilesSet.subtract(m_newSourceFiles); removedFilesSet.subtract(m_newSourceFiles);
return removedFilesSet; return removedFilesSet;
} }
@@ -1364,14 +1364,14 @@ public:
} }
/// Returns a list of common files that have a changed timestamp. /// Returns a list of common files that have a changed timestamp.
QSet<QString> timeStampModifiedFiles(const Snapshot &snapshot) const QSet<FilePath> timeStampModifiedFiles(const Snapshot &snapshot) const
{ {
QSet<QString> commonSourceFiles = m_newSourceFiles; QSet<FilePath> commonSourceFiles = m_newSourceFiles;
commonSourceFiles.intersect(m_oldSourceFiles); commonSourceFiles.intersect(m_oldSourceFiles);
QList<Document::Ptr> documentsToCheck; QList<Document::Ptr> documentsToCheck;
for (const QString &file : commonSourceFiles) { for (const FilePath &file : commonSourceFiles) {
if (Document::Ptr document = snapshot.document(FilePath::fromString(file))) if (Document::Ptr document = snapshot.document(file))
documentsToCheck << document; documentsToCheck << document;
} }
@@ -1391,10 +1391,10 @@ private:
private: private:
const ProjectInfo &m_old; const ProjectInfo &m_old;
const QSet<QString> m_oldSourceFiles; const QSet<FilePath> m_oldSourceFiles;
const ProjectInfo &m_new; const ProjectInfo &m_new;
const QSet<QString> m_newSourceFiles; const QSet<FilePath> m_newSourceFiles;
}; };
/// Make sure that m_projectLock is locked for writing when calling this. /// 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()) { for (const ProjectPart::ConstPtr &projectPart : projectData.projectInfo->projectParts()) {
d->m_projectPartIdToProjectProjectPart[projectPart->id()] = projectPart; d->m_projectPartIdToProjectProjectPart[projectPart->id()] = projectPart;
for (const ProjectFile &cxxFile : projectPart->files) for (const ProjectFile &cxxFile : projectPart->files)
d->m_fileToProjectParts[Utils::FilePath::fromString(cxxFile.path).canonicalPath()].append( d->m_fileToProjectParts[cxxFile.path.canonicalPath()].append(projectPart);
projectPart);
} }
} }
@@ -1464,12 +1463,12 @@ void CppModelManager::updateCppEditorDocuments(bool projectsUpdated) const
} }
QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo,
const QSet<QString> &additionalFiles) const QSet<FilePath> &additionalFiles)
{ {
if (!newProjectInfo) if (!newProjectInfo)
return {}; return {};
QSet<QString> filesToReindex; QSet<FilePath> filesToReindex;
QStringList removedProjectParts; QStringList removedProjectParts;
bool filesRemoved = false; bool filesRemoved = false;
@@ -1481,7 +1480,7 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne
{ // Only hold the lock for a limited scope, so the dumping afterwards does not deadlock. { // Only hold the lock for a limited scope, so the dumping afterwards does not deadlock.
QWriteLocker projectLocker(&d->m_projectLock); QWriteLocker projectLocker(&d->m_projectLock);
const QSet<QString> newSourceFiles = newProjectInfo->sourceFiles(); const QSet<FilePath> newSourceFiles = newProjectInfo->sourceFiles();
// Check if we can avoid a full reindexing // Check if we can avoid a full reindexing
const auto it = d->m_projectData.find(project); const auto it = d->m_projectData.find(project);
@@ -1503,18 +1502,18 @@ QFuture<void> CppModelManager::updateProjectInfo(const ProjectInfo::ConstPtr &ne
// Otherwise check for added and modified files // Otherwise check for added and modified files
} else { } else {
const QSet<QString> addedFiles = comparer.addedFiles(); const QSet<FilePath> addedFiles = comparer.addedFiles();
filesToReindex.unite(addedFiles); filesToReindex.unite(addedFiles);
const QSet<QString> modifiedFiles = comparer.timeStampModifiedFiles(snapshot()); const QSet<FilePath> modifiedFiles = comparer.timeStampModifiedFiles(snapshot());
filesToReindex.unite(modifiedFiles); filesToReindex.unite(modifiedFiles);
} }
// Announce and purge the removed files from the snapshot // Announce and purge the removed files from the snapshot
const QSet<QString> removedFiles = comparer.removedFiles(); const QSet<FilePath> removedFiles = comparer.removedFiles();
if (!removedFiles.isEmpty()) { if (!removedFiles.isEmpty()) {
filesRemoved = true; filesRemoved = true;
emit aboutToRemoveFiles(Utils::toList(removedFiles)); emit aboutToRemoveFiles(transform<QStringList>(removedFiles, &FilePath::toString));
removeFilesFromSnapshot(removedFiles); removeFilesFromSnapshot(removedFiles);
} }
} }
@@ -1935,8 +1934,7 @@ void CppModelManager::GC()
// The configuration file is part of the project files, which is just fine. // 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 // If single files are open, without any project, then there is no need to
// keep the configuration file around. // keep the configuration file around.
FilePaths todo = filesInEditorSupports; FilePaths todo = filesInEditorSupports + projectFiles();
todo += transform(projectFiles(), &FilePath::fromString);
// Collect all files that are reachable from the project files // Collect all files that are reachable from the project files
while (!todo.isEmpty()) { while (!todo.isEmpty()) {
@@ -2032,7 +2030,7 @@ CppIndexingSupport *CppModelManager::indexingSupport()
return d->m_internalIndexingSupport; return d->m_internalIndexingSupport;
} }
QStringList CppModelManager::projectFiles() FilePaths CppModelManager::projectFiles()
{ {
QWriteLocker locker(&d->m_projectLock); QWriteLocker locker(&d->m_projectLock);
ensureUpdated(); ensureUpdated();

View File

@@ -87,7 +87,7 @@ public:
ReservedProgressNotification ReservedProgressNotification
}; };
QFuture<void> updateSourceFiles(const QSet<QString> &sourceFiles, QFuture<void> updateSourceFiles(const QSet<Utils::FilePath> &sourceFiles,
ProgressNotificationMode mode = ReservedProgressNotification); ProgressNotificationMode mode = ReservedProgressNotification);
void updateCppEditorDocuments(bool projectsUpdated = false) const; void updateCppEditorDocuments(bool projectsUpdated = false) const;
WorkingCopy workingCopy() const; WorkingCopy workingCopy() const;
@@ -103,7 +103,7 @@ public:
ProjectInfoList projectInfos() const; ProjectInfoList projectInfos() const;
ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const; ProjectInfo::ConstPtr projectInfo(ProjectExplorer::Project *project) const;
QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo, QFuture<void> updateProjectInfo(const ProjectInfo::ConstPtr &newProjectInfo,
const QSet<QString> &additionalFiles = {}); const QSet<Utils::FilePath> &additionalFiles = {});
/// \return The project part with the given project file /// \return The project part with the given project file
ProjectPart::ConstPtr projectPartForId(const QString &projectPartId) const; ProjectPart::ConstPtr projectPartForId(const QString &projectPartId) const;
@@ -192,7 +192,7 @@ public:
CppIndexingSupport *indexingSupport(); CppIndexingSupport *indexingSupport();
QStringList projectFiles(); Utils::FilePaths projectFiles();
ProjectExplorer::HeaderPaths headerPaths(); ProjectExplorer::HeaderPaths headerPaths();
@@ -207,7 +207,7 @@ public:
QThreadPool *sharedThreadPool(); QThreadPool *sharedThreadPool();
static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck); static QSet<Utils::FilePath> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
static Internal::CppSourceProcessor *createSourceProcessor(); static Internal::CppSourceProcessor *createSourceProcessor();
static const Utils::FilePath &configurationFileName(); static const Utils::FilePath &configurationFileName();
@@ -284,13 +284,13 @@ private:
void recalculateProjectPartMappings(); void recalculateProjectPartMappings();
void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot); void replaceSnapshot(const CPlusPlus::Snapshot &newSnapshot);
void removeFilesFromSnapshot(const QSet<QString> &removedFiles); void removeFilesFromSnapshot(const QSet<Utils::FilePath> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo); void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
WorkingCopy buildWorkingCopyList(); WorkingCopy buildWorkingCopyList();
void ensureUpdated(); void ensureUpdated();
QStringList internalProjectFiles() const; Utils::FilePaths internalProjectFiles() const;
ProjectExplorer::HeaderPaths internalHeaderPaths() const; ProjectExplorer::HeaderPaths internalHeaderPaths() const;
ProjectExplorer::Macros internalDefinedMacros() const; ProjectExplorer::Macros internalDefinedMacros() const;
@@ -301,4 +301,4 @@ private:
Internal::CppModelManagerPrivate *d; Internal::CppModelManagerPrivate *d;
}; };
} // namespace CppEditor } // CppEditor

View File

@@ -103,7 +103,7 @@ public:
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
const ProjectFiles rppFiles = Utils::transform<ProjectFiles>(projectFiles, const ProjectFiles rppFiles = Utils::transform<ProjectFiles>(projectFiles,
[](const FilePath &file) { [](const FilePath &file) {
return ProjectFile(file.toString(), ProjectFile::classify(file.toString())); return ProjectFile(file, ProjectFile::classify(file.toString()));
}); });
const auto project = modelManagerTestHelper->createProject( const auto project = modelManagerTestHelper->createProject(
name, Utils::FilePath::fromString(dir).pathAppended(name + ".pro")); name, Utils::FilePath::fromString(dir).pathAppended(name + ".pro"));
@@ -217,7 +217,7 @@ void ModelManagerTest::testFrameworkHeaders()
const FilePath source = const FilePath source =
testDataDir.fileFromSourcesDir("test_modelmanager_framework_headers.cpp"); testDataDir.fileFromSourcesDir("test_modelmanager_framework_headers.cpp");
const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, 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), {}, {}), const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}),
{part}); {part});
@@ -262,7 +262,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles()
rpp.setMacros({{"OH_BEHAVE", "-1"}}); rpp.setMacros({{"OH_BEHAVE", "-1"}});
rpp.setHeaderPaths({HeaderPath::makeUser(testDataDir.includeDir(false))}); rpp.setHeaderPaths({HeaderPath::makeUser(testDataDir.includeDir(false))});
auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, 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}); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part});
QSet<FilePath> refreshedFiles = helper.updateProjectInfo(pi); QSet<FilePath> refreshedFiles = helper.updateProjectInfo(pi);
@@ -280,7 +280,7 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles()
// Introduce a define that will enable another define once the document is reparsed. // Introduce a define that will enable another define once the document is reparsed.
rpp.setMacros({{"TEST_DEFINE", "1"}}); rpp.setMacros({{"TEST_DEFINE", "1"}});
part = ProjectPart::create(project->projectFilePath(), rpp, {}, part = ProjectPart::create(project->projectFilePath(), rpp, {},
{ProjectFile(testCpp.toString(), ProjectFile::CXXSource)}); {ProjectFile(testCpp, ProjectFile::CXXSource)});
pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part});
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
@@ -317,9 +317,9 @@ void ModelManagerTest::testRefreshSeveralTimes()
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
const ProjectFiles files = { const ProjectFiles files = {
ProjectFile(testHeader1.toString(), ProjectFile::CXXHeader), ProjectFile(testHeader1, ProjectFile::CXXHeader),
ProjectFile(testHeader2.toString(), ProjectFile::CXXHeader), ProjectFile(testHeader2, ProjectFile::CXXHeader),
ProjectFile(testCpp.toString(), ProjectFile::CXXSource) ProjectFile(testCpp, ProjectFile::CXXSource)
}; };
const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files);
auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part});
@@ -369,7 +369,7 @@ void ModelManagerTest::testRefreshTestForChanges()
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
const MyTestDataDir testDataDir(_("testdata_refresh")); 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"), const auto project = helper.createProject(_("test_modelmanager_refresh_2"),
Utils::FilePath::fromString("blubb.pro")); Utils::FilePath::fromString("blubb.pro"));
@@ -384,7 +384,7 @@ void ModelManagerTest::testRefreshTestForChanges()
QFuture<void> firstFuture = mm->updateProjectInfo(pi); QFuture<void> firstFuture = mm->updateProjectInfo(pi);
QVERIFY(firstFuture.isStarted() || firstFuture.isRunning()); QVERIFY(firstFuture.isStarted() || firstFuture.isRunning());
firstFuture.waitForFinished(); firstFuture.waitForFinished();
const QSet<QString> refreshedFiles = helper.waitForRefreshedSourceFiles(); const QSet<FilePath> refreshedFiles = helper.waitForRefreshedSourceFiles();
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
QVERIFY(refreshedFiles.contains(testCpp)); QVERIFY(refreshedFiles.contains(testCpp));
@@ -411,8 +411,8 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved()
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, const auto part = ProjectPart::create(project->projectFilePath(), rpp, {},
{{testCpp.toString(), ProjectFile::CXXSource}, {{testCpp, ProjectFile::CXXSource},
{testHeader1.toString(), ProjectFile::CXXHeader}}); {testHeader1, ProjectFile::CXXHeader}});
auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part});
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
@@ -430,8 +430,8 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved()
// Now add testHeader2 and remove testHeader1 // Now add testHeader2 and remove testHeader1
const auto newPart = ProjectPart::create(project->projectFilePath(), rpp, {}, const auto newPart = ProjectPart::create(project->projectFilePath(), rpp, {},
{{testCpp.toString(), ProjectFile::CXXSource}, {{testCpp, ProjectFile::CXXSource},
{testHeader2.toString(), ProjectFile::CXXHeader}}); {testHeader2, ProjectFile::CXXHeader}});
pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {newPart}); pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {newPart});
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
@@ -468,7 +468,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
auto files = Utils::transform<ProjectFiles>(initialProjectFilePaths, [](const FilePath &f) { auto files = Utils::transform<ProjectFiles>(initialProjectFilePaths, [](const FilePath &f) {
return ProjectFile(f.toString(), ProjectFile::CXXSource); return ProjectFile(f, ProjectFile::CXXSource);
}); });
auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, files);
auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); 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. // Add or remove source file. The configuration stays the same.
files = Utils::transform<ProjectFiles>(finalProjectFilePaths, [](const FilePath &f) { files = Utils::transform<ProjectFiles>(finalProjectFilePaths, [](const FilePath &f) {
return ProjectFile(f.toString(), ProjectFile::CXXSource); return ProjectFile(f, ProjectFile::CXXSource);
}); });
part = ProjectPart::create(project->projectFilePath(), rpp, {}, files); part = ProjectPart::create(project->projectFilePath(), rpp, {}, files);
pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part});
@@ -732,9 +732,9 @@ void ModelManagerTest::testDefinesPerProject()
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
MyTestDataDir testDataDirectory(_("testdata_defines")); MyTestDataDir testDataDirectory(_("testdata_defines"));
const QString main1File = testDataDirectory.file(_("main1.cpp")); const FilePath main1File = testDataDirectory.filePath("main1.cpp");
const QString main2File = testDataDirectory.file(_("main2.cpp")); const FilePath main2File = testDataDirectory.filePath("main2.cpp");
const QString header = testDataDirectory.file(_("header.h")); const FilePath header = testDataDirectory.filePath("header.h");
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
@@ -766,7 +766,7 @@ void ModelManagerTest::testDefinesPerProject()
struct Data { struct Data {
QString firstDeclarationName; QString firstDeclarationName;
QString fileName; FilePath filePath;
} d[] = { } d[] = {
{_("one"), main1File}, {_("one"), main1File},
{_("two"), main2File} {_("two"), main2File}
@@ -774,15 +774,14 @@ void ModelManagerTest::testDefinesPerProject()
for (auto &i : d) { for (auto &i : d) {
const QString firstDeclarationName = i.firstDeclarationName; 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); EditorCloser closer(editor);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
Document::Ptr doc = mm->document(filePath); Document::Ptr doc = mm->document(i.filePath);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
} }
} }
@@ -794,9 +793,9 @@ void ModelManagerTest::testPrecompiledHeaders()
MyTestDataDir testDataDirectory(_("testdata_defines")); MyTestDataDir testDataDirectory(_("testdata_defines"));
const FilePath main1File = testDataDirectory.filePath("main1.cpp"); const FilePath main1File = testDataDirectory.filePath("main1.cpp");
const FilePath main2File = testDataDirectory.filePath("main2.cpp"); const FilePath main2File = testDataDirectory.filePath("main2.cpp");
const QString header = testDataDirectory.file(_("header.h")); const FilePath header = testDataDirectory.filePath("header.h");
const QString pch1File = testDataDirectory.file(_("pch1.h")); const FilePath pch1File = testDataDirectory.filePath("pch1.h");
const QString pch2File = testDataDirectory.file(_("pch2.h")); const FilePath pch2File = testDataDirectory.filePath("pch2.h");
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
@@ -806,18 +805,18 @@ void ModelManagerTest::testPrecompiledHeaders()
RawProjectPart rpp1; RawProjectPart rpp1;
rpp1.setProjectFileLocation("project1.projectfile"); rpp1.setProjectFileLocation("project1.projectfile");
rpp1.setQtVersion(Utils::QtMajorVersion::None); rpp1.setQtVersion(Utils::QtMajorVersion::None);
rpp1.setPreCompiledHeaders({pch1File}); rpp1.setPreCompiledHeaders({pch1File.toString()});
rpp1.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); rpp1.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))});
const auto part1 = ProjectPart::create(project->projectFilePath(), rpp1, {}, const auto part1 = ProjectPart::create(project->projectFilePath(), rpp1, {},
{{main1File.toString(), ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}}); {{main1File, ProjectFile::CXXSource}, {header, ProjectFile::CXXHeader}});
RawProjectPart rpp2; RawProjectPart rpp2;
rpp2.setProjectFileLocation("project2.projectfile"); rpp2.setProjectFileLocation("project2.projectfile");
rpp2.setQtVersion(Utils::QtMajorVersion::None); rpp2.setQtVersion(Utils::QtMajorVersion::None);
rpp2.setPreCompiledHeaders({pch2File}); rpp2.setPreCompiledHeaders({pch2File.toString()});
rpp2.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))}); rpp2.setHeaderPaths({HeaderPath::makeUser(testDataDirectory.includeDir(false))});
const auto part2 = ProjectPart::create(project->projectFilePath(), rpp2, {}, 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}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part1, part2});
@@ -874,9 +873,9 @@ void ModelManagerTest::testDefinesPerEditor()
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
MyTestDataDir testDataDirectory(_("testdata_defines")); MyTestDataDir testDataDirectory(_("testdata_defines"));
const QString main1File = testDataDirectory.file(_("main1.cpp")); const FilePath main1File = testDataDirectory.filePath("main1.cpp");
const QString main2File = testDataDirectory.file(_("main2.cpp")); const FilePath main2File = testDataDirectory.filePath("main2.cpp");
const QString header = testDataDirectory.file(_("header.h")); const FilePath header = testDataDirectory.filePath("header.h");
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
@@ -914,8 +913,7 @@ void ModelManagerTest::testDefinesPerEditor()
const QString editorDefines = i.editorDefines; const QString editorDefines = i.editorDefines;
const QString firstDeclarationName = i.firstDeclarationName; const QString firstDeclarationName = i.firstDeclarationName;
Core::IEditor *editor = Core::EditorManager::openEditor( Core::IEditor *editor = Core::EditorManager::openEditor(main1File);
Utils::FilePath::fromString(main1File));
EditorCloser closer(editor); EditorCloser closer(editor);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
@@ -929,7 +927,7 @@ void ModelManagerTest::testDefinesPerEditor()
parser->update({CppModelManager::instance()->workingCopy(), nullptr, parser->update({CppModelManager::instance()->workingCopy(), nullptr,
Utils::Language::Cxx, false}); Utils::Language::Cxx, false});
Document::Ptr doc = mm->document(FilePath::fromString(main1File)); Document::Ptr doc = mm->document(main1File);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
} }
} }
@@ -970,7 +968,7 @@ void ModelManagerTest::testUpdateEditorsAfterProjectUpdate()
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::None); rpp.setQtVersion(Utils::QtMajorVersion::None);
const auto part = ProjectPart::create(project->projectFilePath(), rpp, {}, 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}); const auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part});
helper.updateProjectInfo(pi); helper.updateProjectInfo(pi);
@@ -1004,23 +1002,22 @@ void ModelManagerTest::testRenameIncludes()
const MyTestDataDir testDir(_("testdata_project1")); const MyTestDataDir testDir(_("testdata_project1"));
// Copy test files to a temporary directory // Copy test files to a temporary directory
QSet<QString> sourceFiles; QSet<FilePath> sourceFiles;
for (const QString &fileName : std::as_const(fileNames)) { for (const QString &fileName : std::as_const(fileNames)) {
const QString &file = workingDir.filePath(fileName); const QString &file = workingDir.filePath(fileName);
QVERIFY(QFile::copy(testDir.file(fileName), file)); QVERIFY(QFile::copy(testDir.file(fileName), file));
// Saving source file names for the model manager update, // Saving source file names for the model manager update,
// so we can update just the relevant files. // so we can update just the relevant files.
if (ProjectFile::classify(file) == ProjectFile::CXXSource) 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 // Update the c++ model manager and check for the old includes
modelManager->updateSourceFiles(sourceFiles).waitForFinished(); modelManager->updateSourceFiles(sourceFiles).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
CPlusPlus::Snapshot snapshot = modelManager->snapshot(); CPlusPlus::Snapshot snapshot = modelManager->snapshot();
for (const QString &sourceFile : std::as_const(sourceFiles)) { for (const FilePath &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{oldHeader});
QSet<FilePath>{oldHeader});
} }
// Renaming the header // Renaming the header
@@ -1032,9 +1029,8 @@ void ModelManagerTest::testRenameIncludes()
modelManager->updateSourceFiles(sourceFiles).waitForFinished(); modelManager->updateSourceFiles(sourceFiles).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
snapshot = modelManager->snapshot(); snapshot = modelManager->snapshot();
for (const QString &sourceFile : std::as_const(sourceFiles)) { for (const FilePath &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<FilePath>{newHeader});
QSet<FilePath>{newHeader});
} }
} }
@@ -1066,22 +1062,22 @@ void ModelManagerTest::testRenameIncludesInEditor()
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
// Copy test files to a temporary directory // Copy test files to a temporary directory
QSet<QString> sourceFiles; QSet<FilePath> sourceFiles;
for (const QString &fileName : fileNames) { for (const QString &fileName : fileNames) {
const QString &file = workingDir.filePath(fileName); const QString &file = workingDir.filePath(fileName);
QVERIFY(QFile::copy(testDir.file(fileName), file)); QVERIFY(QFile::copy(testDir.file(fileName), file));
// Saving source file names for the model manager update, // Saving source file names for the model manager update,
// so we can update just the relevant files. // so we can update just the relevant files.
if (ProjectFile::classify(file) == ProjectFile::CXXSource) 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 // Update the c++ model manager and check for the old includes
modelManager->updateSourceFiles(sourceFiles).waitForFinished(); modelManager->updateSourceFiles(sourceFiles).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
CPlusPlus::Snapshot snapshot = modelManager->snapshot(); CPlusPlus::Snapshot snapshot = modelManager->snapshot();
for (const QString &sourceFile : std::as_const(sourceFiles)) { for (const FilePath &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), QCOMPARE(snapshot.allIncludesForDocument(sourceFile),
QSet<FilePath>{headerWithPragmaOnce}); QSet<FilePath>{headerWithPragmaOnce});
} }
@@ -1160,8 +1156,8 @@ void ModelManagerTest::testRenameIncludesInEditor()
modelManager->updateSourceFiles(sourceFiles).waitForFinished(); modelManager->updateSourceFiles(sourceFiles).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
snapshot = modelManager->snapshot(); snapshot = modelManager->snapshot();
for (const QString &sourceFile : std::as_const(sourceFiles)) { for (const FilePath &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)), QCOMPARE(snapshot.allIncludesForDocument(sourceFile),
QSet<FilePath>{renamedHeaderWithPragmaOnce}); QSet<FilePath>{renamedHeaderWithPragmaOnce});
} }
} }

View File

@@ -13,7 +13,7 @@
namespace CppEditor { namespace CppEditor {
ProjectFile::ProjectFile(const QString &filePath, Kind kind, bool active) ProjectFile::ProjectFile(const Utils::FilePath &filePath, Kind kind, bool active)
: path(filePath) : path(filePath)
, kind(kind) , kind(kind)
, active(active) , active(active)

View File

@@ -5,7 +5,7 @@
#include "cppeditor_global.h" #include "cppeditor_global.h"
#include <QString> #include <utils/filepath.h>
namespace Utils { class FilePath; } namespace Utils { class FilePath; }
@@ -31,7 +31,7 @@ public:
}; };
ProjectFile() = default; 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 classifyByMimeType(const QString &mt);
static Kind classify(const QString &filePath); static Kind classify(const QString &filePath);
@@ -58,7 +58,7 @@ public:
friend QDebug operator<<(QDebug stream, const CppEditor::ProjectFile &projectFile); friend QDebug operator<<(QDebug stream, const CppEditor::ProjectFile &projectFile);
public: public:
QString path; Utils::FilePath path;
Kind kind = Unclassified; Kind kind = Unclassified;
bool active = true; bool active = true;
}; };
@@ -67,4 +67,4 @@ using ProjectFiles = QVector<ProjectFile>;
const char *projectFileKindToText(ProjectFile::Kind kind); const char *projectFileKindToText(ProjectFile::Kind kind);
} // namespace CppEditor } // CppEditor

View File

@@ -4,6 +4,9 @@
#include "cppprojectfilecategorizer.h" #include "cppprojectfilecategorizer.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/filepath.h>
using namespace Utils;
namespace CppEditor { namespace CppEditor {
@@ -38,7 +41,7 @@ ProjectFiles ProjectFileCategorizer::classifyFiles(const QStringList &filePaths,
ProjectFiles ambiguousHeaders; ProjectFiles ambiguousHeaders;
for (const QString &filePath : filePaths) { for (const QString &filePath : filePaths) {
const ProjectFile projectFile(filePath, const ProjectFile projectFile(FilePath::fromString(filePath),
getMimeType getMimeType
? ProjectFile::classifyByMimeType(getMimeType(filePath)) ? ProjectFile::classifyByMimeType(getMimeType(filePath))
: ProjectFile::classify(filePath), : ProjectFile::classify(filePath),

View File

@@ -19,6 +19,7 @@
#include <QFutureInterface> #include <QFutureInterface>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace CppEditor { namespace CppEditor {
@@ -134,11 +135,11 @@ void CppProjectUpdater::checkForExtraCompilersFinished()
m_projectUpdateFutureInterface.reset(); m_projectUpdateFutureInterface.reset();
QList<ExtraCompiler *> extraCompilers; QList<ExtraCompiler *> extraCompilers;
QSet<QString> compilerFiles; QSet<FilePath> compilerFiles;
for (const QPointer<ExtraCompiler> &compiler : std::as_const(m_extraCompilers)) { for (const QPointer<ExtraCompiler> &compiler : std::as_const(m_extraCompilers)) {
if (compiler) { if (compiler) {
extraCompilers += compiler.data(); extraCompilers += compiler.data();
compilerFiles += Utils::transform<QSet>(compiler->targets(), &Utils::FilePath::toString); compilerFiles += Utils::toSet(compiler->targets());
} }
} }
GeneratedCodeModelSupport::update(extraCompilers); GeneratedCodeModelSupport::update(extraCompilers);

View File

@@ -244,7 +244,7 @@ void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection,
void CppRefactoringChangesData::fileChanged(const FilePath &filePath) void CppRefactoringChangesData::fileChanged(const FilePath &filePath)
{ {
m_modelManager->updateSourceFiles({filePath.toString()}); m_modelManager->updateSourceFiles({filePath});
} }
} // CppEditor } // CppEditor

View File

@@ -283,8 +283,7 @@ CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEdito
bool TestCase::parseFiles(const QSet<FilePath> &filePaths) bool TestCase::parseFiles(const QSet<FilePath> &filePaths)
{ {
QSet<QString> filePaths_ = transform(filePaths, &FilePath::toString); CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished();
CppModelManager::instance()->updateSourceFiles(filePaths_).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
const CPlusPlus::Snapshot snapshot = globalSnapshot(); const CPlusPlus::Snapshot snapshot = globalSnapshot();
if (snapshot.isEmpty()) { if (snapshot.isEmpty()) {

View File

@@ -137,9 +137,9 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
for (const ProjectInfo::ConstPtr &info : projectInfos) { for (const ProjectInfo::ConstPtr &info : projectInfos) {
qDebug() << "Project" << info->projectFilePath().toUserOutput() << "- files to process:" qDebug() << "Project" << info->projectFilePath().toUserOutput() << "- files to process:"
<< info->sourceFiles().size(); << info->sourceFiles().size();
const QSet<QString> sourceFiles = info->sourceFiles(); const QSet<FilePath> sourceFiles = info->sourceFiles();
for (const QString &sourceFile : sourceFiles) for (const FilePath &sourceFile : sourceFiles)
filesToOpen << FilePath::fromString(sourceFile); filesToOpen << sourceFile;
} }
Utils::sort(filesToOpen); Utils::sort(filesToOpen);

View File

@@ -83,7 +83,7 @@ QSet<FilePath> ModelManagerTestHelper::updateProjectInfo(
resetRefreshedSourceFiles(); resetRefreshedSourceFiles();
CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished(); CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
return Utils::transform(waitForRefreshedSourceFiles(), &FilePath::fromString); return waitForRefreshedSourceFiles();
} }
void ModelManagerTestHelper::resetRefreshedSourceFiles() void ModelManagerTestHelper::resetRefreshedSourceFiles()
@@ -92,12 +92,12 @@ void ModelManagerTestHelper::resetRefreshedSourceFiles()
m_refreshHappened = false; m_refreshHappened = false;
} }
QSet<QString> ModelManagerTestHelper::waitForRefreshedSourceFiles() QSet<FilePath> ModelManagerTestHelper::waitForRefreshedSourceFiles()
{ {
while (!m_refreshHappened) while (!m_refreshHappened)
QCoreApplication::processEvents(); QCoreApplication::processEvents();
return m_lastRefreshedSourceFiles; return Utils::transform(m_lastRefreshedSourceFiles, &FilePath::fromString);
} }
void ModelManagerTestHelper::waitForFinishedGc() void ModelManagerTestHelper::waitForFinishedGc()

View File

@@ -43,7 +43,7 @@ public:
QSet<Utils::FilePath> updateProjectInfo(const ProjectInfo::ConstPtr &projectInfo); QSet<Utils::FilePath> updateProjectInfo(const ProjectInfo::ConstPtr &projectInfo);
void resetRefreshedSourceFiles(); void resetRefreshedSourceFiles();
QSet<QString> waitForRefreshedSourceFiles(); QSet<Utils::FilePath> waitForRefreshedSourceFiles();
void waitForFinishedGc(); void waitForFinishedGc();
signals: signals:

View File

@@ -9,6 +9,8 @@
#include <projectexplorer/rawprojectpart.h> #include <projectexplorer/rawprojectpart.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
using namespace Utils;
namespace CppEditor { namespace CppEditor {
ProjectInfo::ConstPtr ProjectInfo::create(const ProjectExplorer::ProjectUpdateInfo &updateInfo, 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)); return ConstPtr(new ProjectInfo(updateInfo, projectParts));
} }
const QVector<ProjectPart::ConstPtr> ProjectInfo::projectParts() const
{
return m_projectParts;
}
const QSet<QString> ProjectInfo::sourceFiles() const
{
return m_sourceFiles;
}
bool ProjectInfo::operator ==(const ProjectInfo &other) const bool ProjectInfo::operator ==(const ProjectInfo &other) const
{ {
return m_projectName == other.m_projectName 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; return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles;
} }
static QSet<QString> getSourceFiles(const QVector<ProjectPart::ConstPtr> &projectParts) static QSet<FilePath> getSourceFiles(const QVector<ProjectPart::ConstPtr> &projectParts)
{ {
QSet<QString> sourceFiles; QSet<FilePath> sourceFiles;
for (const ProjectPart::ConstPtr &part : projectParts) { for (const ProjectPart::ConstPtr &part : projectParts) {
for (const ProjectFile &file : std::as_const(part->files)) for (const ProjectFile &file : std::as_const(part->files))
sourceFiles.insert(file.path); sourceFiles.insert(file.path);

View File

@@ -10,7 +10,8 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/rawprojectpart.h> #include <projectexplorer/rawprojectpart.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <utils/fileutils.h>
#include <utils/filepath.h>
#include <QHash> #include <QHash>
#include <QList> #include <QList>
@@ -28,8 +29,8 @@ public:
static ConstPtr create(const ProjectExplorer::ProjectUpdateInfo &updateInfo, static ConstPtr create(const ProjectExplorer::ProjectUpdateInfo &updateInfo,
const QVector<ProjectPart::ConstPtr> &projectParts); const QVector<ProjectPart::ConstPtr> &projectParts);
const QVector<ProjectPart::ConstPtr> projectParts() const; const QVector<ProjectPart::ConstPtr> &projectParts() const { return m_projectParts; }
const QSet<QString> sourceFiles() const; const QSet<Utils::FilePath> &sourceFiles() const { return m_sourceFiles; }
QString projectName() const { return m_projectName; } QString projectName() const { return m_projectName; }
Utils::FilePath projectFilePath() const { return m_projectFilePath; } Utils::FilePath projectFilePath() const { return m_projectFilePath; }
Utils::FilePath projectRoot() const { return m_projectFilePath.parentDir(); } Utils::FilePath projectRoot() const { return m_projectFilePath.parentDir(); }
@@ -51,7 +52,7 @@ private:
const Utils::FilePath m_projectFilePath; const Utils::FilePath m_projectFilePath;
const Utils::FilePath m_buildRoot; const Utils::FilePath m_buildRoot;
const ProjectExplorer::HeaderPaths m_headerPaths; const ProjectExplorer::HeaderPaths m_headerPaths;
const QSet<QString> m_sourceFiles; const QSet<Utils::FilePath> m_sourceFiles;
const ProjectExplorer::Macros m_defines; const ProjectExplorer::Macros m_defines;
}; };

View File

@@ -14,6 +14,8 @@
#include <cctype> #include <cctype>
using namespace Utils;
namespace Todo { namespace Todo {
namespace Internal { namespace Internal {
@@ -35,7 +37,7 @@ void CppTodoItemsScanner::scannerParamsChanged()
CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance();
QSet<QString> filesToBeUpdated; QSet<FilePath> filesToBeUpdated;
const CppEditor::ProjectInfoList infoList = modelManager->projectInfos(); const CppEditor::ProjectInfoList infoList = modelManager->projectInfos();
for (const CppEditor::ProjectInfo::ConstPtr &info : infoList) for (const CppEditor::ProjectInfo::ConstPtr &info : infoList)
filesToBeUpdated.unite(info->sourceFiles()); filesToBeUpdated.unite(info->sourceFiles());