CPlusPlus: Return FilePaths from Document::includedFile

... and fix fallout.

Change-Id: Ieaad57700fa48d0c4a0dd9bf2c284315579b9473
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
hjk
2022-11-23 16:28:12 +01:00
parent ef97774122
commit 40ba25b691
13 changed files with 108 additions and 91 deletions

View File

@@ -22,6 +22,8 @@
#include <cplusplus/TypeVisitor.h> #include <cplusplus/TypeVisitor.h>
#include <cplusplus/CoreTypes.h> #include <cplusplus/CoreTypes.h>
#include <utils/algorithm.h>
#include <QBitArray> #include <QBitArray>
#include <QByteArray> #include <QByteArray>
#include <QDebug> #include <QDebug>
@@ -297,13 +299,13 @@ void Document::setLastModified(const QDateTime &lastModified)
_lastModified = lastModified; _lastModified = lastModified;
} }
QStringList Document::includedFiles() const FilePaths Document::includedFiles() const
{ {
QStringList files; QStringList files;
for (const Include &i : std::as_const(_resolvedIncludes)) for (const Include &i : std::as_const(_resolvedIncludes))
files.append(i.resolvedFileName()); files.append(i.resolvedFileName());
files.removeDuplicates(); files.removeDuplicates();
return files; return transform(files, &FilePath::fromString);
} }
// This assumes to be called with a QDir::cleanPath cleaned fileName. // This assumes to be called with a QDir::cleanPath cleaned fileName.
@@ -762,18 +764,18 @@ Document::Ptr Snapshot::documentFromSource(const QByteArray &preprocessedCode,
return newDoc; return newDoc;
} }
QSet<QString> Snapshot::allIncludesForDocument(const QString &fileName) const QSet<FilePath> Snapshot::allIncludesForDocument(const FilePath &filePath) const
{ {
QSet<QString> result; QSet<FilePath> result;
QStack<QString> files; QStack<FilePath> files;
files.push(fileName); files.push(filePath);
while (!files.isEmpty()) { while (!files.isEmpty()) {
QString file = files.pop(); FilePath file = files.pop();
if (Document::Ptr doc = document(file)) { if (Document::Ptr doc = document(file)) {
const QStringList includedFiles = doc->includedFiles(); const FilePaths includedFiles = doc->includedFiles();
for (const QString &inc : includedFiles) { for (const FilePath &inc : includedFiles) {
if (!result.contains(inc)) { if (!result.contains(inc)) {
result.insert(inc); result.insert(inc);
files.push(inc); files.push(inc);
@@ -815,10 +817,10 @@ QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument(
return result; return result;
} }
Utils::FilePaths Snapshot::filesDependingOn(const Utils::FilePath &fileName) const FilePaths Snapshot::filesDependingOn(const FilePath &filePath) const
{ {
updateDependencyTable(); updateDependencyTable();
return m_deps.filesDependingOn(fileName); return m_deps.filesDependingOn(filePath);
} }
void Snapshot::updateDependencyTable() const void Snapshot::updateDependencyTable() const
@@ -838,9 +840,9 @@ bool Snapshot::operator==(const Snapshot &other) const
return _documents == other._documents; return _documents == other._documents;
} }
Document::Ptr Snapshot::document(const Utils::FilePath &fileName) const Document::Ptr Snapshot::document(const FilePath &filePath) const
{ {
return _documents.value(fileName); return _documents.value(filePath);
} }
Snapshot Snapshot::simplified(Document::Ptr doc) const Snapshot Snapshot::simplified(Document::Ptr doc) const
@@ -849,9 +851,9 @@ Snapshot Snapshot::simplified(Document::Ptr doc) const
if (doc) { if (doc) {
snapshot.insert(doc); snapshot.insert(doc);
const QSet<QString> fileNames = allIncludesForDocument(doc->filePath().toString()); const QSet<FilePath> filePaths = allIncludesForDocument(doc->filePath());
for (const QString &fileName : fileNames) for (const FilePath &filePath : filePaths)
if (Document::Ptr inc = document(fileName)) if (Document::Ptr inc = document(filePath))
snapshot.insert(inc); snapshot.insert(inc);
} }

View File

@@ -300,7 +300,7 @@ public:
} }
}; };
QStringList includedFiles() const; Utils::FilePaths includedFiles() const;
void addIncludeFile(const Include &include); void addIncludeFile(const Include &include);
const QList<Include> &resolvedIncludes() const const QList<Include> &resolvedIncludes() const
@@ -404,7 +404,7 @@ public:
Document::Ptr documentFromSource(const QByteArray &preprocessedDocument, Document::Ptr documentFromSource(const QByteArray &preprocessedDocument,
const Utils::FilePath &filePath) const; const Utils::FilePath &filePath) const;
QSet<QString> allIncludesForDocument(const QString &fileName) const; QSet<Utils::FilePath> allIncludesForDocument(const Utils::FilePath &filePath) const;
QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const; QList<IncludeLocation> includeLocationsOfDocument(const QString &fileNameOrPath) const;

View File

@@ -6,7 +6,9 @@
#include <QDebug> #include <QDebug>
#include <QFutureInterface> #include <QFutureInterface>
using namespace CPlusPlus; using namespace Utils;
namespace CPlusPlus {
Utils::FilePaths DependencyTable::filesDependingOn(const Utils::FilePath &fileName) const Utils::FilePaths DependencyTable::filesDependingOn(const Utils::FilePath &fileName) const
{ {
@@ -55,10 +57,10 @@ void DependencyTable::build(QFutureInterfaceBase &futureInterface, const Snapsho
if (Document::Ptr doc = snapshot.document(fileName)) { if (Document::Ptr doc = snapshot.document(fileName)) {
QBitArray bitmap(files.size()); QBitArray bitmap(files.size());
QList<int> directIncludes; QList<int> directIncludes;
const QStringList documentIncludes = doc->includedFiles(); const FilePaths documentIncludes = doc->includedFiles();
for (const QString &includedFile : documentIncludes) { for (const FilePath &includedFile : documentIncludes) {
int index = fileIndex.value(Utils::FilePath::fromString(includedFile)); int index = fileIndex.value(includedFile);
if (index == -1) if (index == -1)
continue; continue;
@@ -104,3 +106,5 @@ void DependencyTable::build(QFutureInterfaceBase &futureInterface, const Snapsho
return; return;
} while (changed); } while (changed);
} }
} // CPlusPlus

View File

@@ -12,6 +12,8 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -57,8 +59,8 @@ static bool includesBoostTest(const CPlusPlus::Document::Ptr &doc,
return true; return true;
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) { for (const FilePath &include : snapshot.allIncludesForDocument(doc->filePath())) {
if (boostTestHpp.match(include).hasMatch()) if (boostTestHpp.match(include.path()).hasMatch())
return true; return true;
} }

View File

@@ -61,7 +61,7 @@ static bool includesCatchHeader(const CPlusPlus::Document::Ptr &doc,
} }
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) { for (const FilePath &include : snapshot.allIncludesForDocument(doc->filePath())) {
for (const QString &catchHeader : catchHeaders) { for (const QString &catchHeader : catchHeaders) {
if (include.endsWith(catchHeader)) if (include.endsWith(catchHeader))
return true; return true;

View File

@@ -47,8 +47,8 @@ static bool includesGTest(const CPlusPlus::Document::Ptr &doc,
return true; return true;
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) { for (const FilePath &include : snapshot.allIncludesForDocument(doc->filePath())) {
if (include.endsWith(gtestH)) if (include.path().endsWith(gtestH))
return true; return true;
} }

View File

@@ -11,6 +11,8 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
using namespace Utils;
namespace Autotest { namespace Autotest {
using LookupInfo = QPair<QString, QString>; using LookupInfo = QPair<QString, QString>;
@@ -58,7 +60,7 @@ QByteArray CppParser::getFileContent(const Utils::FilePath &filePath) const
bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot, bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
const Utils::FilePath &filePath, const Utils::FilePath &filePath,
const QString &cacheString, const QString &cacheString,
const std::function<bool(const QString &)> &checker) const std::function<bool(const FilePath &)> &checker)
{ {
const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance();
const QList<CppEditor::ProjectPart::ConstPtr> projectParts = modelManager->projectPart(filePath); const QList<CppEditor::ProjectPart::ConstPtr> projectParts = modelManager->projectPart(filePath);
@@ -70,8 +72,8 @@ bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
auto it = s_pchLookupCache.find(info); auto it = s_pchLookupCache.find(info);
if (it == s_pchLookupCache.end()) { if (it == s_pchLookupCache.end()) {
it = s_pchLookupCache.insert(info, it = s_pchLookupCache.insert(info,
Utils::anyOf(snapshot.allIncludesForDocument(header), Utils::anyOf(snapshot.allIncludesForDocument(FilePath::fromString(header)),
checker)); checker));
} }
return it.value(); return it.value();
}; };
@@ -86,8 +88,8 @@ bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
return Autotest::precompiledHeaderContains(snapshot, return Autotest::precompiledHeaderContains(snapshot,
filePath, filePath,
headerFilePath, headerFilePath,
[&](const QString &include) { [&](const FilePath &include) {
return include.endsWith(headerFilePath); return include.path().endsWith(headerFilePath);
}); });
} }
@@ -98,8 +100,8 @@ bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
return Autotest::precompiledHeaderContains(snapshot, return Autotest::precompiledHeaderContains(snapshot,
filePath, filePath,
headerFileRegex.pattern(), headerFileRegex.pattern(),
[&](const QString &include) { [&](const FilePath &include) {
return headerFileRegex.match(include).hasMatch(); return headerFileRegex.match(include.path()).hasMatch();
}); });
} }

View File

@@ -53,10 +53,10 @@ static bool includesQtTest(const CPlusPlus::Document::Ptr &doc, const CPlusPlus:
} }
} }
const QSet<QString> allIncludes = snapshot.allIncludesForDocument(doc->filePath().toString()); const QSet<FilePath> allIncludes = snapshot.allIncludesForDocument(doc->filePath());
for (const QString &include : allIncludes) { for (const FilePath &include : allIncludes) {
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (include.endsWith(QString("%1/qtest.h").arg(prefix))) if (include.pathView().endsWith(QString("%1/qtest.h").arg(prefix)))
return true; return true;
} }
} }

View File

@@ -60,9 +60,9 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
} }
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) { for (const FilePath &include : snapshot.allIncludesForDocument(doc->filePath())) {
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (include.endsWith(QString("%1/quicktest.h").arg(prefix))) if (include.pathView().endsWith(QString("%1/quicktest.h").arg(prefix)))
return true; return true;
} }
} }

View File

@@ -21,7 +21,12 @@ namespace CppEditor::Internal {
class CppIncludesIterator final : public BaseFileFilter::Iterator class CppIncludesIterator final : public BaseFileFilter::Iterator
{ {
public: public:
CppIncludesIterator(CPlusPlus::Snapshot snapshot, const QSet<QString> &seedPaths); CppIncludesIterator(CPlusPlus::Snapshot snapshot, const QSet<FilePath> &seedPaths)
: m_snapshot(snapshot),
m_paths(seedPaths)
{
toFront();
}
void toFront() override; void toFront() override;
bool hasNext() const override; bool hasNext() const override;
@@ -32,20 +37,14 @@ private:
void fetchMore(); void fetchMore();
CPlusPlus::Snapshot m_snapshot; CPlusPlus::Snapshot m_snapshot;
QSet<QString> m_paths; QSet<FilePath> m_paths;
QSet<QString> m_queuedPaths; QSet<FilePath> m_queuedPaths;
QSet<QString> m_allResultPaths; QSet<FilePath> m_allResultPaths;
QStringList m_resultQueue; FilePaths m_resultQueue;
FilePath m_currentPath; FilePath m_currentPath;
}; };
CppIncludesIterator::CppIncludesIterator(CPlusPlus::Snapshot snapshot,
const QSet<QString> &seedPaths)
: m_snapshot(snapshot),
m_paths(seedPaths)
{
toFront();
}
void CppIncludesIterator::toFront() void CppIncludesIterator::toFront()
{ {
@@ -64,7 +63,7 @@ FilePath CppIncludesIterator::next()
{ {
if (m_resultQueue.isEmpty()) if (m_resultQueue.isEmpty())
return {}; return {};
m_currentPath = FilePath::fromString(m_resultQueue.takeFirst()); m_currentPath = m_resultQueue.takeFirst();
if (m_resultQueue.isEmpty()) if (m_resultQueue.isEmpty())
fetchMore(); fetchMore();
return m_currentPath; return m_currentPath;
@@ -78,13 +77,13 @@ FilePath CppIncludesIterator::filePath() const
void CppIncludesIterator::fetchMore() void CppIncludesIterator::fetchMore()
{ {
while (!m_queuedPaths.isEmpty() && m_resultQueue.isEmpty()) { while (!m_queuedPaths.isEmpty() && m_resultQueue.isEmpty()) {
const QString filePath = *m_queuedPaths.begin(); const FilePath filePath = *m_queuedPaths.begin();
m_queuedPaths.remove(filePath); m_queuedPaths.remove(filePath);
CPlusPlus::Document::Ptr doc = m_snapshot.document(filePath); CPlusPlus::Document::Ptr doc = m_snapshot.document(filePath);
if (!doc) if (!doc)
continue; continue;
const QStringList includedFiles = doc->includedFiles(); const FilePaths includedFiles = doc->includedFiles();
for (const QString &includedPath : includedFiles ) { for (const FilePath &includedPath : includedFiles ) {
if (!m_allResultPaths.contains(includedPath)) { if (!m_allResultPaths.contains(includedPath)) {
m_allResultPaths.insert(includedPath); m_allResultPaths.insert(includedPath);
m_queuedPaths.insert(includedPath); m_queuedPaths.insert(includedPath);
@@ -127,16 +126,16 @@ void CppIncludesFilter::prepareSearch(const QString &entry)
Q_UNUSED(entry) Q_UNUSED(entry)
if (m_needsUpdate) { if (m_needsUpdate) {
m_needsUpdate = false; m_needsUpdate = false;
QSet<QString> seedPaths; QSet<FilePath> seedPaths;
for (Project *project : SessionManager::projects()) { for (Project *project : SessionManager::projects()) {
const Utils::FilePaths allFiles = project->files(Project::SourceFiles); const FilePaths allFiles = project->files(Project::SourceFiles);
for (const Utils::FilePath &filePath : allFiles ) for (const FilePath &filePath : allFiles )
seedPaths.insert(filePath.toString()); seedPaths.insert(filePath);
} }
const QList<DocumentModel::Entry *> entries = DocumentModel::entries(); const QList<DocumentModel::Entry *> entries = DocumentModel::entries();
for (DocumentModel::Entry *entry : entries) { for (DocumentModel::Entry *entry : entries) {
if (entry) if (entry)
seedPaths.insert(entry->fileName().toString()); seedPaths.insert(entry->fileName());
} }
CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot(); CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
setFileIterator(new CppIncludesIterator(snapshot, seedPaths)); setFileIterator(new CppIncludesIterator(snapshot, seedPaths));

View File

@@ -1309,9 +1309,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<QString> fileNames = d->m_snapshot.allIncludesForDocument(cxxFile.path); const QSet<FilePath> filePaths = d->m_snapshot.allIncludesForDocument(
for (const QString &fileName : fileNames) FilePath::fromString(cxxFile.path));
d->m_snapshot.remove(fileName); for (const FilePath &filePath : filePaths)
d->m_snapshot.remove(filePath);
d->m_snapshot.remove(cxxFile.path); d->m_snapshot.remove(cxxFile.path);
} }
} }
@@ -1939,19 +1940,18 @@ 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.
QStringList todo = filesInEditorSupports + projectFiles(); FilePaths todo = transform(filesInEditorSupports + 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()) {
const QString file = todo.last(); const FilePath filePath = todo.last();
todo.removeLast(); todo.removeLast();
const Utils::FilePath fileName = Utils::FilePath::fromString(file); if (reachableFiles.contains(filePath))
if (reachableFiles.contains(fileName))
continue; continue;
reachableFiles.insert(fileName); reachableFiles.insert(filePath);
if (Document::Ptr doc = currentSnapshot.document(file)) if (Document::Ptr doc = currentSnapshot.document(filePath))
todo += doc->includedFiles(); todo += doc->includedFiles();
} }

View File

@@ -626,10 +626,10 @@ void ModelManagerTest::testExtraeditorsupportUiFiles()
const CPlusPlus::Snapshot snapshot = mm->snapshot(); const CPlusPlus::Snapshot snapshot = mm->snapshot();
const Document::Ptr document = snapshot.document(fileIncludingTheUiFile); const Document::Ptr document = snapshot.document(fileIncludingTheUiFile);
QVERIFY(document); QVERIFY(document);
const QStringList includedFiles = document->includedFiles(); const FilePaths includedFiles = document->includedFiles();
QCOMPARE(includedFiles.size(), 2); QCOMPARE(includedFiles.size(), 2);
QCOMPARE(Utils::FilePath::fromString(includedFiles.at(0)).fileName(), _("mainwindow.h")); QCOMPARE(includedFiles.at(0).fileName(), _("mainwindow.h"));
QCOMPARE(Utils::FilePath::fromString(includedFiles.at(1)).fileName(), _("ui_mainwindow.h")); QCOMPARE(includedFiles.at(1).fileName(), _("ui_mainwindow.h"));
} }
/// QTCREATORBUG-9828: Locator shows symbols of closed files /// QTCREATORBUG-9828: Locator shows symbols of closed files
@@ -999,8 +999,8 @@ void ModelManagerTest::testRenameIncludes()
const QDir workingDir(tmpDir.path()); const QDir workingDir(tmpDir.path());
const QStringList fileNames = {"foo.h", "foo.cpp", "main.cpp"}; const QStringList fileNames = {"foo.h", "foo.cpp", "main.cpp"};
const QString oldHeader(workingDir.filePath(_("foo.h"))); const FilePath oldHeader = FilePath::fromString(workingDir.filePath("foo.h"));
const QString newHeader(workingDir.filePath(_("bar.h"))); const FilePath newHeader = FilePath::fromString(workingDir.filePath("bar.h"));
CppModelManager *modelManager = CppModelManager::instance(); CppModelManager *modelManager = CppModelManager::instance();
const MyTestDataDir testDir(_("testdata_project1")); const MyTestDataDir testDir(_("testdata_project1"));
@@ -1019,20 +1019,24 @@ void ModelManagerTest::testRenameIncludes()
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 QString &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>{oldHeader}); QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)),
QSet<FilePath>{oldHeader});
}
// Renaming the header // Renaming the header
QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(oldHeader), QVERIFY(Core::FileUtils::renameFile(oldHeader,
Utils::FilePath::fromString(newHeader), newHeader,
Core::HandleIncludeGuards::Yes)); Core::HandleIncludeGuards::Yes));
// Update the c++ model manager again and check for the new includes // Update the c++ model manager again and check for the new includes
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 QString &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>{newHeader}); QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)),
QSet<FilePath>{newHeader});
}
} }
void ModelManagerTest::testRenameIncludesInEditor() void ModelManagerTest::testRenameIncludesInEditor()
@@ -1047,8 +1051,8 @@ void ModelManagerTest::testRenameIncludesInEditor()
const QDir workingDir(tmpDir.path()); const QDir workingDir(tmpDir.path());
const QStringList fileNames = {"baz.h", "baz2.h", "baz3.h", "foo.h", "foo.cpp", "main.cpp"}; const QStringList fileNames = {"baz.h", "baz2.h", "baz3.h", "foo.h", "foo.cpp", "main.cpp"};
const QString headerWithPragmaOnce(workingDir.filePath(_("foo.h"))); const FilePath headerWithPragmaOnce = FilePath::fromString(workingDir.filePath("foo.h"));
const QString renamedHeaderWithPragmaOnce(workingDir.filePath(_("bar.h"))); const FilePath renamedHeaderWithPragmaOnce = FilePath::fromString(workingDir.filePath("bar.h"));
const QString headerWithNormalGuard(workingDir.filePath(_("baz.h"))); const QString headerWithNormalGuard(workingDir.filePath(_("baz.h")));
const QString renamedHeaderWithNormalGuard(workingDir.filePath(_("foobar2000.h"))); const QString renamedHeaderWithNormalGuard(workingDir.filePath(_("foobar2000.h")));
const QString headerWithUnderscoredGuard(workingDir.filePath(_("baz2.h"))); const QString headerWithUnderscoredGuard(workingDir.filePath(_("baz2.h")));
@@ -1077,8 +1081,10 @@ void ModelManagerTest::testRenameIncludesInEditor()
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 QString &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>{headerWithPragmaOnce}); QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)),
QSet<FilePath>{headerWithPragmaOnce});
}
// Open a file in the editor // Open a file in the editor
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0); QCOMPARE(Core::DocumentModel::openedDocuments().size(), 0);
@@ -1093,8 +1099,8 @@ void ModelManagerTest::testRenameIncludesInEditor()
QVERIFY(modelManager->workingCopy().contains(mainFile)); QVERIFY(modelManager->workingCopy().contains(mainFile));
// Test the renaming of a header file where a pragma once guard is present // Test the renaming of a header file where a pragma once guard is present
QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithPragmaOnce), QVERIFY(Core::FileUtils::renameFile(headerWithPragmaOnce,
Utils::FilePath::fromString(renamedHeaderWithPragmaOnce), renamedHeaderWithPragmaOnce,
Core::HandleIncludeGuards::Yes)); Core::HandleIncludeGuards::Yes));
// Test the renaming the header with include guard: // Test the renaming the header with include guard:
@@ -1155,8 +1161,10 @@ 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 QString &sourceFile : std::as_const(sourceFiles)) {
QCOMPARE(snapshot.allIncludesForDocument(sourceFile), QSet<QString>{renamedHeaderWithPragmaOnce}); QCOMPARE(snapshot.allIncludesForDocument(FilePath::fromString(sourceFile)),
QSet<FilePath>{renamedHeaderWithPragmaOnce});
}
} }
void ModelManagerTest::testDocumentsAndRevisions() void ModelManagerTest::testDocumentsAndRevisions()

View File

@@ -346,9 +346,9 @@ static ClassDocumentPtrPair
if (maxIncludeDepth) { if (maxIncludeDepth) {
// Check the includes // Check the includes
const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u; const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u;
const auto includedFiles = doc->includedFiles(); const FilePaths includedFiles = doc->includedFiles();
for (const QString &include : includedFiles) { for (const FilePath &include : includedFiles) {
const Snapshot::const_iterator it = docTable.find(FilePath::fromString(include)); const Snapshot::const_iterator it = docTable.find(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);