CppEditor: Proliferate FilePath use

Remove SnapShot::{find,contains}(QString) overloads and fix fallout.

Change-Id: I50c415826939e09ac111f33def611c7478fa5d97
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-23 15:49:49 +01:00
parent 74ba41f82c
commit 67e9c2d7a0
20 changed files with 114 additions and 90 deletions

View File

@@ -388,16 +388,12 @@ public:
const_iterator end() const { return _documents.end(); } const_iterator end() const { return _documents.end(); }
bool contains(const Utils::FilePath &fileName) const; bool contains(const Utils::FilePath &fileName) const;
bool contains(const QString &fileName) const
{ return contains(Utils::FilePath::fromString(fileName)); }
Document::Ptr document(const Utils::FilePath &fileName) const; Document::Ptr document(const Utils::FilePath &fileName) const;
Document::Ptr document(const QString &fileName) const Document::Ptr document(const QString &fileName) const
{ return document(Utils::FilePath::fromString(fileName)); } { return document(Utils::FilePath::fromString(fileName)); }
const_iterator find(const Utils::FilePath &fileName) const; const_iterator find(const Utils::FilePath &fileName) const;
const_iterator find(const QString &fileName) const
{ return find(Utils::FilePath::fromString(fileName)); }
Snapshot simplified(Document::Ptr doc) const; Snapshot simplified(Document::Ptr doc) const;

View File

@@ -716,7 +716,11 @@ void Preprocessor::State::updateIncludeGuardState_helper(IncludeGuardStateHint h
#endif // DEBUG_INCLUDE_GUARD_TRACKING #endif // DEBUG_INCLUDE_GUARD_TRACKING
} }
QString Preprocessor::configurationFileName() { return QStringLiteral("<configuration>"); } const FilePath &Preprocessor::configurationFileName()
{
const static FilePath configurationFile = FilePath::fromPathPart(u"<configuration>");
return configurationFile;
}
Preprocessor::Preprocessor(Client *client, Environment *env) Preprocessor::Preprocessor(Client *client, Environment *env)
: m_client(client) : m_client(client)
@@ -2010,7 +2014,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk)
// the macro is a feature constraint(e.g. QT_NO_XXX) // the macro is a feature constraint(e.g. QT_NO_XXX)
if (checkUndefined && macroName.startsWith("QT_NO_")) { if (checkUndefined && macroName.startsWith("QT_NO_")) {
if (macro->fileName() == configurationFileName()) { if (macro->fileName() == configurationFileName().pathView()) {
// and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT) // and it' defined in a pro file (e.g. DEFINES += QT_NO_QOBJECT)
value = false; // take the branch value = false; // take the branch

View File

@@ -54,7 +54,7 @@ class CPLUSPLUS_EXPORT Preprocessor
typedef Internal::Value Value; typedef Internal::Value Value;
public: public:
static QString configurationFileName(); static const Utils::FilePath &configurationFileName();
public: public:
Preprocessor(Client *client, Environment *env); Preprocessor(Client *client, Environment *env);

View File

@@ -316,7 +316,7 @@ 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()) if (file.path == CppEditor::CppModelManager::configurationFileName().path())
continue; continue;
if (file.active if (file.active

View File

@@ -134,7 +134,7 @@ 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()) if (projectFile.path == CppModelManager::configurationFileName().path())
continue; continue;
const auto projectFilePath = FilePath::fromString(projectFile.path); const auto projectFilePath = FilePath::fromString(projectFile.path);
if (file != projectFilePath) if (file != projectFilePath)

View File

@@ -5,10 +5,13 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QString>
#include <QTest> #include <QTest>
using namespace Core::Tests; #include <utils/filepath.h>
using namespace Utils;
namespace Core::Tests {
TestDataDir::TestDataDir(const QString &directory) TestDataDir::TestDataDir(const QString &directory)
: m_directory(directory) : m_directory(directory)
@@ -23,6 +26,11 @@ QString TestDataDir::file(const QString &fileName) const
return directory() + QLatin1Char('/') + fileName; return directory() + QLatin1Char('/') + fileName;
} }
FilePath TestDataDir::filePath(const QString &fileName) const
{
return FilePath::fromString(directory()) / fileName;
}
QString TestDataDir::path() const QString TestDataDir::path() const
{ {
return m_directory; return m_directory;
@@ -37,3 +45,5 @@ QString TestDataDir::directory(const QString &subdir, bool clean) const
path = QDir::cleanPath(path); path = QDir::cleanPath(path);
return path; return path;
} }
} // Core::Tests

View File

@@ -15,6 +15,8 @@
: TestDataDir(QLatin1String(SRCDIR "/" PATH) + testDataDirectory) {} \ : TestDataDir(QLatin1String(SRCDIR "/" PATH) + testDataDirectory) {} \
}; };
namespace Utils { class FilePath; }
namespace Core { namespace Core {
namespace Tests { namespace Tests {
@@ -24,6 +26,7 @@ public:
TestDataDir(const QString &directory); TestDataDir(const QString &directory);
QString file(const QString &fileName) const; QString file(const QString &fileName) const;
Utils::FilePath filePath(const QString &fileName) const;
QString directory(const QString &subdir = QString(), bool clean = true) const; QString directory(const QString &subdir = QString(), bool clean = true) const;
QString path() const; QString path() const;

View File

@@ -12,6 +12,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
namespace CppEditor { namespace CppEditor {
@@ -157,7 +158,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
// Update the snapshot // Update the snapshot
if (invalidateSnapshot) { if (invalidateSnapshot) {
const QString configurationFileName = CppModelManager::configurationFileName(); const FilePath configurationFileName = CppModelManager::configurationFileName();
if (invalidateConfig) if (invalidateConfig)
state.snapshot.remove(configurationFileName); state.snapshot.remove(configurationFileName);
if (!state.snapshot.contains(configurationFileName)) if (!state.snapshot.contains(configurationFileName))
@@ -186,7 +187,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
sourceProcessor.setWorkingCopy(workingCopy); sourceProcessor.setWorkingCopy(workingCopy);
sourceProcessor.setHeaderPaths(state.headerPaths); sourceProcessor.setHeaderPaths(state.headerPaths);
sourceProcessor.setLanguageFeatures(features); sourceProcessor.setLanguageFeatures(features);
sourceProcessor.run(configurationFileName); sourceProcessor.run(configurationFileName.path());
if (baseConfig.usePrecompiledHeaders) { if (baseConfig.usePrecompiledHeaders) {
for (const QString &precompiledHeader : std::as_const(state.precompiledHeaders)) for (const QString &precompiledHeader : std::as_const(state.precompiledHeaders))
sourceProcessor.run(precompiledHeader); sourceProcessor.run(precompiledHeader);

View File

@@ -6,7 +6,6 @@
#include "builtineditordocumentparser.h" #include "builtineditordocumentparser.h"
#include "cppchecksymbols.h" #include "cppchecksymbols.h"
#include "cppeditorconstants.h" #include "cppeditorconstants.h"
#include "cppeditorplugin.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cppprojectfile.h" #include "cppprojectfile.h"
#include "cppsourceprocessor.h" #include "cppsourceprocessor.h"
@@ -26,8 +25,11 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QLoggingCategory>
#include <QRegularExpression> #include <QRegularExpression>
using namespace Utils;
namespace CppEditor::Internal { namespace CppEditor::Internal {
static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg) static Q_LOGGING_CATEGORY(indexerLog, "qtc.cppeditor.indexer", QtWarningMsg)
@@ -176,7 +178,7 @@ void index(QFutureInterface<void> &indexingFuture,
sourceProcessor->setTodo(Utils::toSet(files)); sourceProcessor->setTodo(Utils::toSet(files));
const QString conf = CppModelManager::configurationFileName(); const FilePath &conf = CppModelManager::configurationFileName();
bool processingHeaders = false; bool processingHeaders = false;
CppModelManager *cmm = CppModelManager::instance(); CppModelManager *cmm = CppModelManager::instance();
@@ -198,9 +200,9 @@ void index(QFutureInterface<void> &indexingFuture,
const bool isSourceFile = i < sourceCount; const bool isSourceFile = i < sourceCount;
if (isSourceFile) { if (isSourceFile) {
(void) sourceProcessor->run(conf); (void) sourceProcessor->run(conf.path());
} else if (!processingHeaders) { } else if (!processingHeaders) {
(void) sourceProcessor->run(conf); (void) sourceProcessor->run(conf.path());
processingHeaders = true; processingHeaders = true;
} }

View File

@@ -1479,7 +1479,7 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope)
completeNamespace(b); completeNamespace(b);
addKeywords(); addKeywords();
addMacros(CppModelManager::configurationFileName(), context.snapshot()); addMacros(CppModelManager::configurationFileName().path(), context.snapshot());
addMacros(context.thisDocument()->filePath().toString(), context.snapshot()); addMacros(context.thisDocument()->filePath().toString(), context.snapshot());
addSnippets(); addSnippets();
return !m_completions.isEmpty(); return !m_completions.isEmpty();

View File

@@ -536,7 +536,7 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete
{ {
QTC_ASSERT(context, return nullptr); QTC_ASSERT(context, return nullptr);
QString symbolFile = QLatin1String(parameters.symbolFileName); QString symbolFile = QLatin1String(parameters.symbolFileName);
if (!snapshot.contains(symbolFile)) if (!snapshot.contains(FilePath::fromString(symbolFile)))
return nullptr; return nullptr;
CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile); CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile);

View File

@@ -651,7 +651,7 @@ void FollowSymbolUnderCursor::findLink(
const QString fileName = use->macro().fileName(); const QString fileName = use->macro().fileName();
if (fileName == CppModelManager::editorConfigurationFileName()) { if (fileName == CppModelManager::editorConfigurationFileName()) {
editorWidget->showPreProcessorWidget(); editorWidget->showPreProcessorWidget();
} else if (fileName != CppModelManager::configurationFileName()) { } else if (fileName != CppModelManager::configurationFileName().path()) {
const Macro &macro = use->macro(); const Macro &macro = use->macro();
link.targetFilePath = Utils::FilePath::fromString(macro.fileName()); link.targetFilePath = Utils::FilePath::fromString(macro.fileName());
link.targetLine = macro.line(); link.targetLine = macro.line();

View File

@@ -848,7 +848,7 @@ Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const
return d->m_currentDocumentFilter.get(); return d->m_currentDocumentFilter.get();
} }
QString CppModelManager::configurationFileName() const FilePath &CppModelManager::configurationFileName()
{ {
return Preprocessor::configurationFileName(); return Preprocessor::configurationFileName();
} }

View File

@@ -210,7 +210,7 @@ public:
static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck); static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
static Internal::CppSourceProcessor *createSourceProcessor(); static Internal::CppSourceProcessor *createSourceProcessor();
static QString configurationFileName(); static const Utils::FilePath &configurationFileName();
static QString editorConfigurationFileName(); static QString editorConfigurationFileName();
void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);

View File

@@ -65,8 +65,10 @@ public:
QString frameworksDir(bool cleaned = true) const QString frameworksDir(bool cleaned = true) const
{ return directory(_("frameworks"), cleaned); } { return directory(_("frameworks"), cleaned); }
QString fileFromSourcesDir(const QString &fileName) const FilePath fileFromSourcesDir(const QString &fileName) const
{ return directory(_("sources")) + QLatin1Char('/') + fileName; } {
return FilePath::fromString(directory(_("sources"))).pathAppended(fileName);
}
FilePath filePath(const QString &p) const FilePath filePath(const QString &p) const
{ {
@@ -74,12 +76,12 @@ public:
} }
}; };
QStringList toAbsolutePaths(const QStringList &relativePathList, FilePaths toAbsolutePaths(const QStringList &relativePathList,
const TemporaryCopiedDir &temporaryDir) const TemporaryCopiedDir &temporaryDir)
{ {
QStringList result; FilePaths result;
for (const QString &file : relativePathList) for (const QString &file : relativePathList)
result << temporaryDir.absolutePath(file.toUtf8()); result << FilePath::fromString(temporaryDir.absolutePath(file.toUtf8()));
return result; return result;
} }
@@ -96,12 +98,14 @@ public:
{ {
const MyTestDataDir projectDir(dir); const MyTestDataDir projectDir(dir);
for (const QString &file : files) for (const QString &file : files)
projectFiles << projectDir.file(file); projectFiles << projectDir.filePath(file);
RawProjectPart rpp; RawProjectPart rpp;
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 QString &file) { return ProjectFile(file, ProjectFile::classify(file)); }); [](const FilePath &file) {
return ProjectFile(file.toString(), 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"));
@@ -112,7 +116,7 @@ public:
ModelManagerTestHelper *modelManagerTestHelper; ModelManagerTestHelper *modelManagerTestHelper;
ProjectInfo::ConstPtr projectInfo; ProjectInfo::ConstPtr projectInfo;
QStringList projectFiles; FilePaths projectFiles;
}; };
/// Changes a file on the disk and restores its original contents on destruction /// Changes a file on the disk and restores its original contents on destruction
@@ -211,10 +215,10 @@ void ModelManagerTest::testFrameworkHeaders()
rpp.setMacros({{"OH_BEHAVE", "-1"}}); rpp.setMacros({{"OH_BEHAVE", "-1"}});
rpp.setHeaderPaths({HeaderPath::makeUser(testDataDir.includeDir(false)), rpp.setHeaderPaths({HeaderPath::makeUser(testDataDir.includeDir(false)),
HeaderPath::makeFramework(testDataDir.frameworksDir(false))}); HeaderPath::makeFramework(testDataDir.frameworksDir(false))});
const QString &source = testDataDir.fileFromSourcesDir( const FilePath source =
_("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, ProjectFile::CXXSource)}); {ProjectFile(source.toString(), ProjectFile::CXXSource)});
const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), const auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}),
{part}); {part});
@@ -222,7 +226,7 @@ void ModelManagerTest::testFrameworkHeaders()
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QVERIFY(mm->snapshot().contains(source)); QVERIFY(mm->snapshot().contains(source));
Document::Ptr doc = mm->document(Utils::FilePath::fromString(source)); Document::Ptr doc = mm->document(source);
QVERIFY(!doc.isNull()); QVERIFY(!doc.isNull());
CPlusPlus::Namespace *ns = doc->globalNamespace(); CPlusPlus::Namespace *ns = doc->globalNamespace();
QVERIFY(ns); QVERIFY(ns);
@@ -248,8 +252,8 @@ void ModelManagerTest::testRefreshAlsoIncludesOfProjectFiles()
const MyTestDataDir testDataDir(_("testdata")); const MyTestDataDir testDataDir(_("testdata"));
const QString testCpp(testDataDir.fileFromSourcesDir(_("test_modelmanager_refresh.cpp"))); const FilePath testCpp = testDataDir.fileFromSourcesDir(_("test_modelmanager_refresh.cpp"));
const QString testHeader(testDataDir.fileFromSourcesDir( _("test_modelmanager_refresh.h"))); const FilePath testHeader = testDataDir.fileFromSourcesDir( _("test_modelmanager_refresh.h"));
const auto project const auto project
= helper.createProject(_("test_modelmanager_refresh_also_includes_of_project_files"), = helper.createProject(_("test_modelmanager_refresh_also_includes_of_project_files"),
@@ -259,10 +263,10 @@ 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, ProjectFile::CXXSource)}); {ProjectFile(testCpp.toString(), ProjectFile::CXXSource)});
auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part}); auto pi = ProjectInfo::create(ProjectUpdateInfo(project, KitInfo(nullptr), {}, {}), {part});
QSet<QString> refreshedFiles = helper.updateProjectInfo(pi); QSet<FilePath> refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), 1); QCOMPARE(refreshedFiles.size(), 1);
QVERIFY(refreshedFiles.contains(testCpp)); QVERIFY(refreshedFiles.contains(testCpp));
CPlusPlus::Snapshot snapshot = mm->snapshot(); CPlusPlus::Snapshot snapshot = mm->snapshot();
@@ -277,7 +281,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, ProjectFile::CXXSource)}); {ProjectFile(testCpp.toString(), 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);
@@ -305,25 +309,25 @@ void ModelManagerTest::testRefreshSeveralTimes()
const MyTestDataDir testDataDir(_("testdata_refresh")); const MyTestDataDir testDataDir(_("testdata_refresh"));
const QString testHeader1(testDataDir.file(_("defines.h"))); const FilePath testHeader1 = testDataDir.filePath("defines.h");
const QString testHeader2(testDataDir.file(_("header.h"))); const FilePath testHeader2 = testDataDir.filePath("header.h");
const QString testCpp(testDataDir.file(_("source.cpp"))); const FilePath testCpp = testDataDir.filePath("source.cpp");
const auto project = helper.createProject(_("test_modelmanager_refresh_several_times"), const auto project = helper.createProject(_("test_modelmanager_refresh_several_times"),
Utils::FilePath::fromString("blubb.pro")); Utils::FilePath::fromString("blubb.pro"));
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
const ProjectFiles files = { const ProjectFiles files = {
ProjectFile(testHeader1, ProjectFile::CXXHeader), ProjectFile(testHeader1.toString(), ProjectFile::CXXHeader),
ProjectFile(testHeader2, ProjectFile::CXXHeader), ProjectFile(testHeader2.toString(), ProjectFile::CXXHeader),
ProjectFile(testCpp, ProjectFile::CXXSource) ProjectFile(testCpp.toString(), 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});
mm->updateProjectInfo(pi); mm->updateProjectInfo(pi);
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<FilePath> refreshedFiles;
Document::Ptr document; Document::Ptr document;
ProjectExplorer::Macros macros = {{"FIRST_DEFINE"}}; ProjectExplorer::Macros macros = {{"FIRST_DEFINE"}};
@@ -399,20 +403,21 @@ void ModelManagerTest::testRefreshAddedAndPurgeRemoved()
const MyTestDataDir testDataDir(_("testdata_refresh")); const MyTestDataDir testDataDir(_("testdata_refresh"));
const QString testHeader1(testDataDir.file(_("header.h"))); const FilePath testHeader1 = testDataDir.filePath("header.h");
const QString testHeader2(testDataDir.file(_("defines.h"))); const FilePath testHeader2 = testDataDir.filePath("defines.h");
const QString testCpp(testDataDir.file(_("source.cpp"))); const FilePath testCpp = testDataDir.filePath("source.cpp");
const auto project = helper.createProject(_("test_modelmanager_refresh_3"), const auto project = helper.createProject(_("test_modelmanager_refresh_3"),
Utils::FilePath::fromString("blubb.pro")); Utils::FilePath::fromString("blubb.pro"));
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, ProjectFile::CXXSource}, {testHeader1, ProjectFile::CXXHeader}}); {{testCpp.toString(), ProjectFile::CXXSource},
{testHeader1.toString(), ProjectFile::CXXHeader}});
auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part}); auto pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {part});
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<FilePath> refreshedFiles;
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
@@ -426,7 +431,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, ProjectFile::CXXSource}, {testHeader2, ProjectFile::CXXHeader}}); {{testCpp.toString(), ProjectFile::CXXSource},
{testHeader2.toString(), ProjectFile::CXXHeader}});
pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {newPart}); pi = ProjectInfo::create({project, KitInfo(nullptr), {}, {}}, {newPart});
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
@@ -452,31 +458,31 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path()); TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path());
fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8()); fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8());
initialProjectFiles = toAbsolutePaths(initialProjectFiles, temporaryDir); const FilePaths initialProjectFilePaths = toAbsolutePaths(initialProjectFiles, temporaryDir);
finalProjectFiles = toAbsolutePaths(finalProjectFiles, temporaryDir); const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir);
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
const auto project = helper.createProject(_("test_modelmanager_refresh_timeStampModified"), const auto project = helper.createProject(_("test_modelmanager_refresh_timeStampModified"),
Utils::FilePath::fromString("blubb.pro")); FilePath::fromString("blubb.pro"));
RawProjectPart rpp; RawProjectPart rpp;
rpp.setQtVersion(Utils::QtMajorVersion::Qt5); rpp.setQtVersion(Utils::QtMajorVersion::Qt5);
auto files = Utils::transform<ProjectFiles>(initialProjectFiles, [](const QString &f) { auto files = Utils::transform<ProjectFiles>(initialProjectFilePaths, [](const FilePath &f) {
return ProjectFile(f, ProjectFile::CXXSource); return ProjectFile(f.toString(), 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});
Document::Ptr document; Document::Ptr document;
CPlusPlus::Snapshot snapshot; CPlusPlus::Snapshot snapshot;
QSet<QString> refreshedFiles; QSet<FilePath> refreshedFiles;
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), initialProjectFiles.size()); QCOMPARE(refreshedFiles.size(), initialProjectFilePaths.size());
snapshot = mm->snapshot(); snapshot = mm->snapshot();
for (const QString &file : std::as_const(initialProjectFiles)) { for (const FilePath &file : initialProjectFilePaths) {
QVERIFY(refreshedFiles.contains(file)); QVERIFY(refreshedFiles.contains(file));
QVERIFY(snapshot.contains(file)); QVERIFY(snapshot.contains(file));
} }
@@ -495,17 +501,17 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes)); QVERIFY(fileChangerAndRestorer.writeContents(newFileContentes));
// Add or remove source file. The configuration stays the same. // Add or remove source file. The configuration stays the same.
files = Utils::transform<ProjectFiles>(finalProjectFiles, [](const QString &f) { files = Utils::transform<ProjectFiles>(finalProjectFilePaths, [](const FilePath &f) {
return ProjectFile(f, ProjectFile::CXXSource); return ProjectFile(f.toString(), 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});
refreshedFiles = helper.updateProjectInfo(pi); refreshedFiles = helper.updateProjectInfo(pi);
QCOMPARE(refreshedFiles.size(), finalProjectFiles.size()); QCOMPARE(refreshedFiles.size(), finalProjectFilePaths.size());
snapshot = mm->snapshot(); snapshot = mm->snapshot();
for (const QString &file : std::as_const(finalProjectFiles)) { for (const FilePath &file : finalProjectFilePaths) {
QVERIFY(refreshedFiles.contains(file)); QVERIFY(refreshedFiles.contains(file));
QVERIFY(snapshot.contains(file)); QVERIFY(snapshot.contains(file));
} }
@@ -541,7 +547,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange_data()
/// files of the first project. /// files of the first project.
void ModelManagerTest::testSnapshotAfterTwoProjects() void ModelManagerTest::testSnapshotAfterTwoProjects()
{ {
QSet<QString> refreshedFiles; QSet<FilePath> refreshedFiles;
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
ProjectCreator project1(&helper); ProjectCreator project1(&helper);
ProjectCreator project2(&helper); ProjectCreator project2(&helper);
@@ -556,7 +562,7 @@ void ModelManagerTest::testSnapshotAfterTwoProjects()
QCOMPARE(refreshedFiles, Utils::toSet(project1.projectFiles)); QCOMPARE(refreshedFiles, Utils::toSet(project1.projectFiles));
const int snapshotSizeAfterProject1 = mm->snapshot().size(); const int snapshotSizeAfterProject1 = mm->snapshot().size();
for (const QString &file : std::as_const(project1.projectFiles)) for (const FilePath &file : std::as_const(project1.projectFiles))
QVERIFY(mm->snapshot().contains(file)); QVERIFY(mm->snapshot().contains(file));
// Project 2 // Project 2
@@ -571,9 +577,9 @@ void ModelManagerTest::testSnapshotAfterTwoProjects()
QVERIFY(snapshotSizeAfterProject2 > snapshotSizeAfterProject1); QVERIFY(snapshotSizeAfterProject2 > snapshotSizeAfterProject1);
QVERIFY(snapshotSizeAfterProject2 >= snapshotSizeAfterProject1 + project2.projectFiles.size()); QVERIFY(snapshotSizeAfterProject2 >= snapshotSizeAfterProject1 + project2.projectFiles.size());
for (const QString &file : std::as_const(project1.projectFiles)) for (const FilePath &file : std::as_const(project1.projectFiles))
QVERIFY(mm->snapshot().contains(file)); QVERIFY(mm->snapshot().contains(file));
for (const QString &file : std::as_const(project2.projectFiles)) for (const FilePath &file : std::as_const(project2.projectFiles))
QVERIFY(mm->snapshot().contains(file)); QVERIFY(mm->snapshot().contains(file));
} }
@@ -608,7 +614,7 @@ void ModelManagerTest::testExtraeditorsupportUiFiles()
fileNamesInWorkinCopy.sort(); fileNamesInWorkinCopy.sort();
const QString expectedUiHeaderFileName = _("ui_mainwindow.h"); const QString expectedUiHeaderFileName = _("ui_mainwindow.h");
QCOMPARE(fileNamesInWorkinCopy.at(0), mm->configurationFileName()); QCOMPARE(fileNamesInWorkinCopy.at(0), mm->configurationFileName().toString());
QCOMPARE(fileNamesInWorkinCopy.at(1), expectedUiHeaderFileName); QCOMPARE(fileNamesInWorkinCopy.at(1), expectedUiHeaderFileName);
// Check CppSourceProcessor / includes. // Check CppSourceProcessor / includes.
@@ -633,14 +639,14 @@ void ModelManagerTest::testGcIfLastCppeditorClosed()
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
MyTestDataDir testDataDirectory(_("testdata_guiproject1")); MyTestDataDir testDataDirectory(_("testdata_guiproject1"));
const QString file = testDataDirectory.file(_("main.cpp")); const FilePath file = testDataDirectory.filePath("main.cpp");
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString(file)); Core::IEditor *editor = Core::EditorManager::openEditor(file);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));
@@ -664,14 +670,14 @@ void ModelManagerTest::testDontGcOpenedFiles()
ModelManagerTestHelper helper; ModelManagerTestHelper helper;
MyTestDataDir testDataDirectory(_("testdata_guiproject1")); MyTestDataDir testDataDirectory(_("testdata_guiproject1"));
const QString file = testDataDirectory.file(_("main.cpp")); const FilePath file = testDataDirectory.filePath("main.cpp");
CppModelManager *mm = CppModelManager::instance(); CppModelManager *mm = CppModelManager::instance();
helper.resetRefreshedSourceFiles(); helper.resetRefreshedSourceFiles();
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString(file)); Core::IEditor *editor = Core::EditorManager::openEditor(file);
QVERIFY(editor); QVERIFY(editor);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor)); QVERIFY(mm->isCppEditor(editor));

View File

@@ -177,11 +177,11 @@ static bool closeEditorsWithoutGarbageCollectorInvocation(const QList<Core::IEdi
return closeEditorsSucceeded; return closeEditorsSucceeded;
} }
static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<QString> &filePaths) static bool snapshotContains(const CPlusPlus::Snapshot &snapshot, const QSet<FilePath> &filePaths)
{ {
for (const QString &filePath : filePaths) { for (const FilePath &filePath : filePaths) {
if (!snapshot.contains(filePath)) { if (!snapshot.contains(filePath)) {
qWarning() << "Missing file in snapshot:" << qPrintable(filePath); qWarning() << "Missing file in snapshot:" << qPrintable(filePath.toString());
return false; return false;
} }
} }
@@ -291,7 +291,7 @@ bool TestCase::parseFiles(const QSet<FilePath> &filePaths)
qWarning("After parsing: snapshot is empty."); qWarning("After parsing: snapshot is empty.");
return false; return false;
} }
if (!snapshotContains(snapshot, filePaths_)) { if (!snapshotContains(snapshot, filePaths)) {
qWarning("After parsing: snapshot does not contain all expected files."); qWarning("After parsing: snapshot does not contain all expected files.");
return false; return false;
} }

View File

@@ -4,23 +4,26 @@
#include "modelmanagertesthelper.h" #include "modelmanagertesthelper.h"
#include "cpptoolstestcase.h" #include "cpptoolstestcase.h"
#include "cppworkingcopy.h"
#include "projectinfo.h" #include "projectinfo.h"
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <utils/algorithm.h>
#include <QtTest> #include <QtTest>
#include <cassert> #include <cassert>
using namespace Utils;
namespace CppEditor::Tests { namespace CppEditor::Tests {
TestProject::TestProject(const QString &name, QObject *parent, const Utils::FilePath &filePath) : TestProject::TestProject(const QString &name, QObject *parent, const FilePath &filePath) :
ProjectExplorer::Project("x-binary/foo", filePath), ProjectExplorer::Project("x-binary/foo", filePath),
m_name(name) m_name(name)
{ {
setParent(parent); setParent(parent);
setId(Utils::Id::fromString(name)); setId(Id::fromString(name));
setDisplayName(name); setDisplayName(name);
qRegisterMetaType<QSet<QString> >(); qRegisterMetaType<QSet<QString> >();
} }
@@ -65,7 +68,7 @@ void ModelManagerTestHelper::cleanup()
} }
ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject( ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(
const QString &name, const Utils::FilePath &filePath) const QString &name, const FilePath &filePath)
{ {
auto tp = new TestProject(name, this, filePath); auto tp = new TestProject(name, this, filePath);
m_projects.push_back(tp); m_projects.push_back(tp);
@@ -74,13 +77,13 @@ ModelManagerTestHelper::Project *ModelManagerTestHelper::createProject(
return tp; return tp;
} }
QSet<QString> ModelManagerTestHelper::updateProjectInfo( QSet<FilePath> ModelManagerTestHelper::updateProjectInfo(
const ProjectInfo::ConstPtr &projectInfo) const ProjectInfo::ConstPtr &projectInfo)
{ {
resetRefreshedSourceFiles(); resetRefreshedSourceFiles();
CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished(); CppModelManager::instance()->updateProjectInfo(projectInfo).waitForFinished();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
return waitForRefreshedSourceFiles(); return Utils::transform(waitForRefreshedSourceFiles(), &FilePath::fromString);
} }
void ModelManagerTestHelper::resetRefreshedSourceFiles() void ModelManagerTestHelper::resetRefreshedSourceFiles()
@@ -116,4 +119,4 @@ void ModelManagerTestHelper::gcFinished()
m_gcFinished = true; m_gcFinished = true;
} }
} // namespace CppEditor::Tests } // CppEditor::Tests

View File

@@ -40,7 +40,7 @@ public:
Project *createProject(const QString &name, const Utils::FilePath &filePath = {}); Project *createProject(const QString &name, const Utils::FilePath &filePath = {});
QSet<QString> updateProjectInfo(const ProjectInfo::ConstPtr &projectInfo); QSet<Utils::FilePath> updateProjectInfo(const ProjectInfo::ConstPtr &projectInfo);
void resetRefreshedSourceFiles(); void resetRefreshedSourceFiles();
QSet<QString> waitForRefreshedSourceFiles(); QSet<QString> waitForRefreshedSourceFiles();

View File

@@ -348,7 +348,7 @@ static ClassDocumentPtrPair
const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u; const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u;
const auto includedFiles = doc->includedFiles(); const auto includedFiles = doc->includedFiles();
for (const QString &include : includedFiles) { for (const QString &include : includedFiles) {
const Snapshot::const_iterator it = docTable.find(include); const Snapshot::const_iterator it = docTable.find(FilePath::fromString(include));
if (it != docTable.end()) { if (it != docTable.end()) {
const Document::Ptr &includeDoc = it.value(); const Document::Ptr &includeDoc = it.value();
LookupContext context(includeDoc, docTable); LookupContext context(includeDoc, docTable);
@@ -437,8 +437,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
newDocTable.insert(i.value()); newDocTable.insert(i.value());
} }
} else { } else {
const Utils::FilePath configFileName = const FilePath configFileName = CppEditor::CppModelManager::configurationFileName();
Utils::FilePath::fromString(CppEditor::CppModelManager::configurationFileName());
const CppEditor::WorkingCopy::Table elements = const CppEditor::WorkingCopy::Table elements =
CppEditor::CppModelManager::instance()->workingCopy().elements(); CppEditor::CppModelManager::instance()->workingCopy().elements();
for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) {

View File

@@ -392,7 +392,7 @@ void QmakeBuildSystem::updateCppCodeModel()
}); });
} }
generators.append(proGenerators); generators.append(proGenerators);
fileList.prepend(CppEditor::CppModelManager::configurationFileName()); fileList.prepend(CppEditor::CppModelManager::configurationFileName().toString());
rpp.setFiles(fileList, [cumulativeSourceFiles](const QString &filePath) { rpp.setFiles(fileList, [cumulativeSourceFiles](const QString &filePath) {
// Keep this lambda thread-safe! // Keep this lambda thread-safe!
return !cumulativeSourceFiles.contains(filePath); return !cumulativeSourceFiles.contains(filePath);