CPlusPlus: Proliferate FilePath use

The starts with CppDocument::filePath(), plus a bit of the fallout

This is one patch of potentially many. It is hard to draw the
line where to stop this kind of chunk, this here converts a few
additional functions for which including it in the patch looked
like less churn than without.

Converting is mostly fromString/toString, with a few exceptions
for "already seem" like caches, that use cheaper "path()" to
avoid likely performance regressions (on Windows FilePath
comparison is currently case-insenstive, and more expensive).

There should be no difference for local operation with this patch.

Change-Id: I7b35f98a0a6f0bfed4ea0f8f987faf586f7a8f2b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-21 16:48:50 +01:00
parent 822e2a224a
commit fa1adf4d40
69 changed files with 351 additions and 313 deletions

View File

@@ -205,7 +205,7 @@ public:
const QString fileName = QString::fromUtf8(fileId->chars(), fileId->size()); const QString fileName = QString::fromUtf8(fileId->chars(), fileId->size());
if (fileName != doc->fileName()) if (fileName != doc->filePath().pathView())
return; return;
const QString message = QString::vasprintf(format, ap); const QString message = QString::vasprintf(format, ap);
@@ -220,7 +220,7 @@ public:
} }
#endif // DO_NOT_DUMP_ALL_PARSER_ERRORS #endif // DO_NOT_DUMP_ALL_PARSER_ERRORS
Document::DiagnosticMessage m(convertLevel(level), doc->fileName(), Document::DiagnosticMessage m(convertLevel(level), doc->filePath(),
line, column, message); line, column, message);
messages->append(m); messages->append(m);
} }
@@ -244,7 +244,7 @@ private:
Document::Document(const QString &fileName) Document::Document(const QString &fileName)
: _fileName(QDir::cleanPath(fileName)), : _filePath(Utils::FilePath::fromUserInput(QDir::cleanPath(fileName))),
_globalNamespace(nullptr), _globalNamespace(nullptr),
_revision(0), _revision(0),
_editorRevision(0), _editorRevision(0),
@@ -652,7 +652,7 @@ bool Document::DiagnosticMessage::operator==(const Document::DiagnosticMessage &
_column == other._column && _column == other._column &&
_length == other._length && _length == other._length &&
_level == other._level && _level == other._level &&
_fileName == other._fileName && _filePath == other._filePath &&
_text == other._text; _text == other._text;
} }
@@ -697,7 +697,7 @@ bool Snapshot::contains(const Utils::FilePath &fileName) const
void Snapshot::insert(Document::Ptr doc) void Snapshot::insert(Document::Ptr doc)
{ {
if (doc) { if (doc) {
_documents.insert(Utils::FilePath::fromString(doc->fileName()), doc); _documents.insert(doc->filePath(), doc);
m_deps.files.clear(); // Will trigger re-build when accessed. m_deps.files.clear(); // Will trigger re-build when accessed.
} }
} }
@@ -848,7 +848,7 @@ Snapshot Snapshot::simplified(Document::Ptr doc) const
if (doc) { if (doc) {
snapshot.insert(doc); snapshot.insert(doc);
const QSet<QString> fileNames = allIncludesForDocument(doc->fileName()); const QSet<QString> fileNames = allIncludesForDocument(doc->filePath().toString());
for (const QString &fileName : fileNames) for (const QString &fileName : fileNames)
if (Document::Ptr inc = document(fileName)) if (Document::Ptr inc = document(fileName))
snapshot.insert(inc); snapshot.insert(inc);

View File

@@ -49,7 +49,7 @@ public:
const QDateTime &lastModified() const { return _lastModified; } const QDateTime &lastModified() const { return _lastModified; }
void setLastModified(const QDateTime &lastModified); void setLastModified(const QDateTime &lastModified);
const QString &fileName() const { return _fileName; } const Utils::FilePath &filePath() const { return _filePath; }
void appendMacro(const Macro &macro); void appendMacro(const Macro &macro);
void addMacroUse(const Macro &macro, void addMacroUse(const Macro &macro,
@@ -125,13 +125,13 @@ public:
}; };
public: public:
DiagnosticMessage(int level, const QString &fileName, DiagnosticMessage(int level, const Utils::FilePath &filePath,
int line, int column, int line, int column,
const QString &text, const QString &text,
int length = 0) int length = 0)
: _level(level), : _level(level),
_line(line), _line(line),
_fileName(fileName), _filePath(filePath),
_column(column), _column(column),
_length(length), _length(length),
_text(text) _text(text)
@@ -149,8 +149,8 @@ public:
bool isFatal() const bool isFatal() const
{ return _level == Fatal; } { return _level == Fatal; }
const QString &fileName() const const Utils::FilePath &filePath() const
{ return _fileName; } { return _filePath; }
int line() const int line() const
{ return _line; } { return _line; }
@@ -170,7 +170,7 @@ public:
private: private:
int _level; int _level;
int _line; int _line;
QString _fileName; Utils::FilePath _filePath;
int _column; int _column;
int _length; int _length;
QString _text; QString _text;
@@ -334,7 +334,7 @@ public:
{ return static_cast<CheckMode>(_checkMode); } { return static_cast<CheckMode>(_checkMode); }
private: private:
QString _fileName; Utils::FilePath _filePath;
Control *_control; Control *_control;
TranslationUnit *_translationUnit; TranslationUnit *_translationUnit;
Namespace *_globalNamespace; Namespace *_globalNamespace;

View File

@@ -8,6 +8,7 @@
#include <QDir> #include <QDir>
using namespace Utils;
using namespace CPlusPlus; using namespace CPlusPlus;
FastPreprocessor::FastPreprocessor(const Snapshot &snapshot) FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
@@ -23,12 +24,12 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc,
std::swap(newDoc, _currentDoc); std::swap(newDoc, _currentDoc);
_addIncludesToCurrentDoc = _currentDoc->resolvedIncludes().isEmpty() _addIncludesToCurrentDoc = _currentDoc->resolvedIncludes().isEmpty()
&& _currentDoc->unresolvedIncludes().isEmpty(); && _currentDoc->unresolvedIncludes().isEmpty();
const QString fileName = _currentDoc->fileName(); const FilePath filePath = _currentDoc->filePath();
_preproc.setExpandFunctionlikeMacros(false); _preproc.setExpandFunctionlikeMacros(false);
_preproc.setKeepComments(true); _preproc.setKeepComments(true);
if (Document::Ptr doc = _snapshot.document(fileName)) { if (Document::Ptr doc = _snapshot.document(filePath)) {
_merged.insert(fileName); _merged.insert(filePath.toString());
for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) { for (Snapshot::const_iterator i = _snapshot.begin(), ei = _snapshot.end(); i != ei; ++i) {
if (isInjectedFile(i.key().toString())) if (isInjectedFile(i.key().toString()))
@@ -43,7 +44,7 @@ QByteArray FastPreprocessor::run(Document::Ptr newDoc,
_env.addMacros(_currentDoc->definedMacros()); _env.addMacros(_currentDoc->definedMacros());
} }
const QByteArray preprocessed = _preproc.run(fileName, source); const QByteArray preprocessed = _preproc.run(filePath, source);
// qDebug("FastPreprocessor::run for %s produced [[%s]]", fileName.toUtf8().constData(), preprocessed.constData()); // qDebug("FastPreprocessor::run for %s produced [[%s]]", fileName.toUtf8().constData(), preprocessed.constData());
std::swap(newDoc, _currentDoc); std::swap(newDoc, _currentDoc);
return preprocessed; return preprocessed;

View File

@@ -118,7 +118,7 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand
lineText = matchingLine(tk); lineText = matchingLine(tk);
const int len = tk.utf16chars(); const int len = tk.utf16chars();
const Usage u(Utils::FilePath::fromString(_doc->fileName()), lineText, const Usage u(_doc->filePath(), lineText,
getContainingFunction(line, col), getTags(line, col, tokenIndex), getContainingFunction(line, col), getTags(line, col, tokenIndex),
line, col - 1, len); line, col - 1, len);
_usages.append(u); _usages.append(u);

View File

@@ -20,8 +20,8 @@ void SnapshotSymbolVisitor::accept(Document::Ptr doc)
void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed) void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed)
{ {
if (doc && doc->globalNamespace() && ! processed->contains(doc->fileName())) { if (doc && doc->globalNamespace() && ! processed->contains(doc->filePath().path())) {
processed->insert(doc->fileName()); processed->insert(doc->filePath().path());
const QList<Document::Include> includes = doc->resolvedIncludes(); const QList<Document::Include> includes = doc->resolvedIncludes();
for (const Document::Include &i : includes) { for (const Document::Include &i : includes) {

View File

@@ -13,7 +13,7 @@
#include <QSet> #include <QSet>
using namespace CPlusPlus; namespace CPlusPlus {
TypeOfExpression::TypeOfExpression(): TypeOfExpression::TypeOfExpression():
m_ast(nullptr), m_ast(nullptr),
@@ -132,8 +132,8 @@ ExpressionAST *TypeOfExpression::expressionAST() const
void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env, void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
QSet<QString> *processed) const QSet<QString> *processed) const
{ {
if (doc && ! processed->contains(doc->fileName())) { if (doc && ! processed->contains(doc->filePath().path())) {
processed->insert(doc->fileName()); processed->insert(doc->filePath().path());
const QList<Document::Include> includes = doc->resolvedIncludes(); const QList<Document::Include> includes = doc->resolvedIncludes();
for (const Document::Include &incl : includes) for (const Document::Include &incl : includes)
@@ -158,11 +158,9 @@ QByteArray TypeOfExpression::preprocessedExpression(const QByteArray &utf8code)
} }
Preprocessor preproc(nullptr, m_environment.data()); Preprocessor preproc(nullptr, m_environment.data());
return preproc.run(QLatin1String("<expression>"), utf8code); return preproc.run(Utils::FilePath::fromParts({}, {}, u"<expression>"), utf8code);
} }
namespace CPlusPlus {
ExpressionAST *extractExpressionAST(Document::Ptr doc) ExpressionAST *extractExpressionAST(Document::Ptr doc)
{ {
if (! doc->translationUnit()->ast()) if (! doc->translationUnit()->ast())

View File

@@ -31,6 +31,7 @@
#include <cplusplus/cppassert.h> #include <cplusplus/cppassert.h>
#include <utils/executeondestruction.h> #include <utils/executeondestruction.h>
#include <utils/filepath.h>
#include <utils/scopedswap.h> #include <utils/scopedswap.h>
#include <QDebug> #include <QDebug>
@@ -235,7 +236,6 @@ struct Value
}; };
} // namespace Internal } // namespace Internal
} // namespace CPlusPlus
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CPlusPlus::Internal; using namespace CPlusPlus::Internal;
@@ -251,7 +251,7 @@ Macro *macroDefinition(const ByteArrayRef &name,
unsigned bytesOffset, unsigned bytesOffset,
unsigned utf16charsOffset, unsigned utf16charsOffset,
unsigned line, unsigned line,
Environment *env, CPlusPlus::Environment *env,
Client *client) Client *client)
{ {
Macro *m = env->resolve(name); Macro *m = env->resolve(name);
@@ -320,7 +320,7 @@ class ExpressionEvaluator
void operator = (const ExpressionEvaluator &other); void operator = (const ExpressionEvaluator &other);
public: public:
ExpressionEvaluator(Client *client, Environment *env) ExpressionEvaluator(Client *client, CPlusPlus::Environment *env)
: client(client), env(env), _lex(nullptr) : client(client), env(env), _lex(nullptr)
{ } { }
@@ -726,6 +726,14 @@ Preprocessor::Preprocessor(Client *client, Environment *env)
{ {
} }
QByteArray Preprocessor::run(const Utils::FilePath &filePath,
const QByteArray &source,
bool noLines,
bool markGeneratedTokens)
{
return run(filePath.toString(), source, noLines, markGeneratedTokens);
}
QByteArray Preprocessor::run(const QString &fileName, QByteArray Preprocessor::run(const QString &fileName,
const QByteArray &source, const QByteArray &source,
bool noLines, bool noLines,
@@ -2158,3 +2166,5 @@ void Preprocessor::maybeStartOutputLine()
if (*ch == '\\') if (*ch == '\\')
buffer.append('\n'); buffer.append('\n');
} }
} // namespace CPlusPlus

View File

@@ -36,6 +36,8 @@
#include <functional> #include <functional>
namespace Utils { class FilePath; }
namespace CPlusPlus { namespace CPlusPlus {
class Environment; class Environment;
@@ -57,6 +59,8 @@ public:
public: public:
Preprocessor(Client *client, Environment *env); Preprocessor(Client *client, Environment *env);
QByteArray run(const Utils::FilePath &filePath, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true);
QByteArray run(const QString &filename, const QByteArray &source, QByteArray run(const QString &filename, const QByteArray &source,
bool noLines = false, bool markGeneratedTokens = true); bool noLines = false, bool markGeneratedTokens = true);

View File

@@ -248,7 +248,7 @@ protected:
translationUnit()->getTokenStartPosition(nameExp->firstToken(), &line, &column); translationUnit()->getTokenStartPosition(nameExp->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage( _messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning, Document::DiagnosticMessage::Warning,
_doc->fileName(), _doc->filePath(),
line, column, line, column,
QmlJS::FindExportedCppTypes::tr( QmlJS::FindExportedCppTypes::tr(
"The type will only be available in the QML editors when the type name is a string literal.")); "The type will only be available in the QML editors when the type name is a string literal."));
@@ -309,7 +309,7 @@ protected:
translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column); translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage( _messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning, Document::DiagnosticMessage::Warning,
_doc->fileName(), _doc->filePath(),
line, column, line, column,
QmlJS::FindExportedCppTypes::tr( QmlJS::FindExportedCppTypes::tr(
"The module URI cannot be determined by static analysis. The type will not be available\n" "The module URI cannot be determined by static analysis. The type will not be available\n"
@@ -491,7 +491,7 @@ protected:
translationUnit()->getTokenStartPosition(ast->expression_list->value->firstToken(), &line, &column); translationUnit()->getTokenStartPosition(ast->expression_list->value->firstToken(), &line, &column);
_messages += Document::DiagnosticMessage( _messages += Document::DiagnosticMessage(
Document::DiagnosticMessage::Warning, Document::DiagnosticMessage::Warning,
_doc->fileName(), _doc->filePath(),
line, column, line, column,
QmlJS::FindExportedCppTypes::tr( QmlJS::FindExportedCppTypes::tr(
"must be a string literal to be available in the QML editor")); "must be a string literal to be available in the QML editor"));
@@ -840,7 +840,7 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
FindExportsVisitor finder(document); FindExportsVisitor finder(document);
finder(); finder();
static const QString kindKey = QLatin1String("QmlJSTools.ExportedQmlTypesDiagnostic"); static const QString kindKey = QLatin1String("QmlJSTools.ExportedQmlTypesDiagnostic");
CppModelManagerBase::trySetExtraDiagnostics(document->fileName(), kindKey, CppModelManagerBase::trySetExtraDiagnostics(document->filePath().toString(), kindKey,
finder.messages()); finder.messages());
// if nothing was found, done // if nothing was found, done
@@ -852,7 +852,8 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
// context properties need lookup inside function scope, and thus require a full check // context properties need lookup inside function scope, and thus require a full check
CPlusPlus::Document::Ptr localDoc = document; CPlusPlus::Document::Ptr localDoc = document;
if (document->checkMode() != CPlusPlus::Document::FullCheck && !contextPropertyDescriptions.isEmpty()) { if (document->checkMode() != CPlusPlus::Document::FullCheck && !contextPropertyDescriptions.isEmpty()) {
localDoc = m_snapshot.documentFromSource(document->utf8Source(), document->fileName()); localDoc = m_snapshot.documentFromSource(document->utf8Source(),
document->filePath().toString());
localDoc->check(); localDoc->check();
} }

View File

@@ -1350,10 +1350,10 @@ void ModelManagerInterface::maybeQueueCppQmlTypeUpdate(const CPlusPlus::Document
void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan) void ModelManagerInterface::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc, bool scan)
{ {
QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->fileName()); QPair<CPlusPlus::Document::Ptr, bool> prev = m_queuedCppDocuments.value(doc->filePath().path());
if (prev.first && prev.second) if (prev.first && prev.second)
prev.first->releaseSourceAndAST(); prev.first->releaseSourceAndAST();
m_queuedCppDocuments.insert(doc->fileName(), {doc, scan}); m_queuedCppDocuments.insert(doc->filePath().path(), {doc, scan});
m_updateCppQmlTypesTimer->start(); m_updateCppQmlTypesTimer->start();
} }
@@ -1439,13 +1439,13 @@ void ModelManagerInterface::updateCppQmlTypes(
CPlusPlus::Document::Ptr doc = pair.first; CPlusPlus::Document::Ptr doc = pair.first;
const bool scan = pair.second; const bool scan = pair.second;
const QString fileName = doc->fileName(); const FilePath filePath = doc->filePath();
if (!scan) { if (!scan) {
hasNewInfo = newData.remove(fileName) || hasNewInfo; hasNewInfo = newData.remove(filePath.path()) || hasNewInfo;
const auto savedDocs = newDeclarations.value(fileName); const auto savedDocs = newDeclarations.value(filePath.path());
for (const CPlusPlus::Document::Ptr &savedDoc : savedDocs) { for (const CPlusPlus::Document::Ptr &savedDoc : savedDocs) {
finder(savedDoc); finder(savedDoc);
hasNewInfo = rescanExports(savedDoc->fileName(), finder, newData) || hasNewInfo; hasNewInfo = rescanExports(savedDoc->filePath().path(), finder, newData) || hasNewInfo;
} }
continue; continue;
} }
@@ -1453,7 +1453,7 @@ void ModelManagerInterface::updateCppQmlTypes(
for (auto it = newDeclarations.begin(), end = newDeclarations.end(); it != end;) { for (auto it = newDeclarations.begin(), end = newDeclarations.end(); it != end;) {
for (auto docIt = it->begin(), endDocIt = it->end(); docIt != endDocIt;) { for (auto docIt = it->begin(), endDocIt = it->end(); docIt != endDocIt;) {
const CPlusPlus::Document::Ptr &savedDoc = *docIt; const CPlusPlus::Document::Ptr &savedDoc = *docIt;
if (savedDoc->fileName() == fileName) { if (savedDoc->filePath() == filePath) {
savedDoc->releaseSourceAndAST(); savedDoc->releaseSourceAndAST();
it->erase(docIt); it->erase(docIt);
break; break;
@@ -1472,7 +1472,7 @@ void ModelManagerInterface::updateCppQmlTypes(
doc->keepSourceAndAST(); // keep for later reparsing when dependent doc changes doc->keepSourceAndAST(); // keep for later reparsing when dependent doc changes
} }
hasNewInfo = rescanExports(fileName, finder, newData) || hasNewInfo; hasNewInfo = rescanExports(filePath.path(), finder, newData) || hasNewInfo;
doc->releaseSourceAndAST(); doc->releaseSourceAndAST();
} }

View File

@@ -57,14 +57,12 @@ static bool includesBoostTest(const CPlusPlus::Document::Ptr &doc,
return true; return true;
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->fileName())) { for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) {
if (boostTestHpp.match(include).hasMatch()) if (boostTestHpp.match(include).hasMatch())
return true; return true;
} }
return CppParser::precompiledHeaderContains(snapshot, return CppParser::precompiledHeaderContains(snapshot, doc->filePath(), boostTestHpp);
Utils::FilePath::fromString(doc->fileName()),
boostTestHpp);
} }
static bool hasBoostTestMacros(const CPlusPlus::Document::Ptr &doc) static bool hasBoostTestMacros(const CPlusPlus::Document::Ptr &doc)

View File

@@ -13,6 +13,8 @@
#include <QRegularExpression> #include <QRegularExpression>
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -59,7 +61,7 @@ static bool includesCatchHeader(const CPlusPlus::Document::Ptr &doc,
} }
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->fileName())) { for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) {
for (const QString &catchHeader : catchHeaders) { for (const QString &catchHeader : catchHeaders) {
if (include.endsWith(catchHeader)) if (include.endsWith(catchHeader))
return true; return true;
@@ -67,9 +69,7 @@ static bool includesCatchHeader(const CPlusPlus::Document::Ptr &doc,
} }
for (const QString &catchHeader : catchHeaders) { for (const QString &catchHeader : catchHeaders) {
if (CppParser::precompiledHeaderContains(snapshot, if (CppParser::precompiledHeaderContains(snapshot, doc->filePath(), catchHeader))
Utils::FilePath::fromString(doc->fileName()),
catchHeader))
return true; return true;
} }
return false; return false;
@@ -99,7 +99,7 @@ bool CatchTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futu
return false; return false;
const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance();
const QString &filePath = doc->fileName(); const QString &filePath = doc->filePath().toString();
const QByteArray &fileContent = getFileContent(fileName); const QByteArray &fileContent = getFileContent(fileName);
if (!hasCatchNames(doc)) { if (!hasCatchNames(doc)) {

View File

@@ -13,6 +13,8 @@
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -45,14 +47,12 @@ static bool includesGTest(const CPlusPlus::Document::Ptr &doc,
return true; return true;
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->fileName())) { for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) {
if (include.endsWith(gtestH)) if (include.endsWith(gtestH))
return true; return true;
} }
return CppParser::precompiledHeaderContains(snapshot, return CppParser::precompiledHeaderContains(snapshot, doc->filePath(), gtestH);
Utils::FilePath::fromString(doc->fileName()),
gtestH);
} }
static bool hasGTestNames(const CPlusPlus::Document::Ptr &document) static bool hasGTestNames(const CPlusPlus::Document::Ptr &document)
@@ -84,7 +84,7 @@ bool GTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futureIn
return false; return false;
} }
const QString &filePath = doc->fileName(); const FilePath filePath = doc->filePath();
const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); const CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance();
CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName); CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName);
document->check(); document->check();

View File

@@ -12,6 +12,8 @@
#include <QRegularExpressionMatchIterator> #include <QRegularExpressionMatchIterator>
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -51,7 +53,7 @@ static bool includesQtTest(const CPlusPlus::Document::Ptr &doc, const CPlusPlus:
} }
} }
const QSet<QString> allIncludes = snapshot.allIncludesForDocument(doc->fileName()); const QSet<QString> allIncludes = snapshot.allIncludesForDocument(doc->filePath().toString());
for (const QString &include : allIncludes) { for (const QString &include : allIncludes) {
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (include.endsWith(QString("%1/qtest.h").arg(prefix))) if (include.endsWith(QString("%1/qtest.h").arg(prefix)))
@@ -61,7 +63,7 @@ static bool includesQtTest(const CPlusPlus::Document::Ptr &doc, const CPlusPlus:
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (CppParser::precompiledHeaderContains(snapshot, if (CppParser::precompiledHeaderContains(snapshot,
Utils::FilePath::fromString(doc->fileName()), doc->filePath(),
QString("%1/qtest.h").arg(prefix))) { QString("%1/qtest.h").arg(prefix))) {
return true; return true;
} }
@@ -82,10 +84,10 @@ static bool qtTestLibDefined(const Utils::FilePath &fileName)
} }
TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager, TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager,
const Utils::FilePath &fileName) const const Utils::FilePath &filePath) const
{ {
const QByteArray &fileContent = getFileContent(fileName); const QByteArray &fileContent = getFileContent(filePath);
CPlusPlus::Document::Ptr document = modelManager->document(fileName.toString()); CPlusPlus::Document::Ptr document = modelManager->document(filePath);
if (document.isNull()) if (document.isNull())
return {}; return {};
@@ -101,7 +103,7 @@ TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager
} }
} }
// check if one has used a self-defined macro or QTest::qExec() directly // check if one has used a self-defined macro or QTest::qExec() directly
document = m_cppSnapshot.preprocessedDocument(fileContent, fileName); document = m_cppSnapshot.preprocessedDocument(fileContent, filePath);
document->check(); document->check();
CPlusPlus::AST *ast = document->translationUnit()->ast(); CPlusPlus::AST *ast = document->translationUnit()->ast();
TestAstVisitor astVisitor(document, m_cppSnapshot); TestAstVisitor astVisitor(document, m_cppSnapshot);
@@ -288,7 +290,7 @@ static QtTestCodeLocationList tagLocationsFor(const QtTestParseResult *func,
static bool isQObject(const CPlusPlus::Document::Ptr &declaringDoc) static bool isQObject(const CPlusPlus::Document::Ptr &declaringDoc)
{ {
const QString file = declaringDoc->fileName(); const FilePath file = declaringDoc->filePath();
return (Utils::HostOsInfo::isMacHost() && file.endsWith("QtCore.framework/Headers/qobject.h")) return (Utils::HostOsInfo::isMacHost() && file.endsWith("QtCore.framework/Headers/qobject.h"))
|| file.endsWith("QtCore/qobject.h") || file.endsWith("kernel/qobject.h"); || file.endsWith("QtCore/qobject.h") || file.endsWith("kernel/qobject.h");
} }
@@ -337,8 +339,7 @@ std::optional<bool> QtTestParser::fillTestCaseData(
const QString &testCaseName, const CPlusPlus::Document::Ptr &doc, const QString &testCaseName, const CPlusPlus::Document::Ptr &doc,
TestCaseData &data) const TestCaseData &data) const
{ {
const Utils::FilePath filePath = Utils::FilePath::fromString(doc->fileName()); const FilePaths &alternativeFiles = m_alternativeFiles.values(doc->filePath());
const Utils::FilePaths &alternativeFiles = m_alternativeFiles.values(filePath);
CPlusPlus::Document::Ptr declaringDoc = declaringDocument(doc, m_cppSnapshot, testCaseName, CPlusPlus::Document::Ptr declaringDoc = declaringDocument(doc, m_cppSnapshot, testCaseName,
alternativeFiles, alternativeFiles,
&(data.line), &(data.column)); &(data.line), &(data.column));
@@ -364,7 +365,7 @@ std::optional<bool> QtTestParser::fillTestCaseData(
for (const Utils::FilePath &file : files) for (const Utils::FilePath &file : files)
Utils::addToHash(&(data.dataTags), checkForDataTags(file)); Utils::addToHash(&(data.dataTags), checkForDataTags(file));
data.fileName = Utils::FilePath::fromString(declaringDoc->fileName()); data.fileName = declaringDoc->filePath();
data.valid = true; data.valid = true;
return std::optional<bool>(); return std::optional<bool>();
} }

View File

@@ -20,6 +20,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace QmlJS; using namespace QmlJS;
using namespace Utils;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -59,7 +60,7 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
} }
} }
for (const QString &include : snapshot.allIncludesForDocument(doc->fileName())) { for (const QString &include : snapshot.allIncludesForDocument(doc->filePath().toString())) {
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (include.endsWith(QString("%1/quicktest.h").arg(prefix))) if (include.endsWith(QString("%1/quicktest.h").arg(prefix)))
return true; return true;
@@ -68,7 +69,7 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
for (const QString &prefix : expectedHeaderPrefixes) { for (const QString &prefix : expectedHeaderPrefixes) {
if (CppParser::precompiledHeaderContains(snapshot, if (CppParser::precompiledHeaderContains(snapshot,
Utils::FilePath::fromString(doc->fileName()), doc->filePath(),
QString("%1/quicktest.h").arg(prefix))) { QString("%1/quicktest.h").arg(prefix))) {
return true; return true;
} }
@@ -101,7 +102,7 @@ static QString quickTestSrcDir(const CppEditor::CppModelManager *cppMM,
QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) const QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) const
{ {
const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses(); const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses();
const Utils::FilePath filePath = Utils::FilePath::fromString(doc->fileName()); const Utils::FilePath filePath = doc->filePath();
for (const CPlusPlus::Document::MacroUse &macro : macros) { for (const CPlusPlus::Document::MacroUse &macro : macros) {
if (!macro.isFunctionLike() || macro.arguments().isEmpty()) if (!macro.isFunctionLike() || macro.arguments().isEmpty())
@@ -253,11 +254,11 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> &fu
if (quickTestName(document).isEmpty()) if (quickTestName(document).isEmpty())
return false; return false;
QList<CppEditor::ProjectPart::ConstPtr> ppList = modelManager->projectPart(document->fileName()); QList<CppEditor::ProjectPart::ConstPtr> ppList = modelManager->projectPart(document->filePath());
if (ppList.isEmpty()) // happens if shutting down while parsing if (ppList.isEmpty()) // happens if shutting down while parsing
return false; return false;
const Utils::FilePath cppFileName = Utils::FilePath::fromString(document->fileName()); const FilePath cppFileName = document->filePath();
const Utils::FilePath proFile = Utils::FilePath::fromString(ppList.at(0)->projectFile); const FilePath proFile = Utils::FilePath::fromString(ppList.at(0)->projectFile);
m_mainCppFiles.insert(cppFileName, proFile); m_mainCppFiles.insert(cppFileName, proFile);
const Utils::FilePath srcDir = Utils::FilePath::fromString( const Utils::FilePath srcDir = Utils::FilePath::fromString(
quickTestSrcDir(modelManager, cppFileName)); quickTestSrcDir(modelManager, cppFileName));

View File

@@ -161,7 +161,7 @@ void TestCodeParser::onDocumentUpdated(const Utils::FilePath &fileName, bool isQ
void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document) void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document)
{ {
onDocumentUpdated(Utils::FilePath::fromString(document->fileName())); onDocumentUpdated(document->filePath());
} }
void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document) void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document)

View File

@@ -41,7 +41,7 @@ ClangEditorDocumentProcessor::ClangEditorDocumentProcessor(TextEditor::TextDocum
connect(static_cast<CppEditor::BuiltinEditorDocumentParser *>(parser().data()), connect(static_cast<CppEditor::BuiltinEditorDocumentParser *>(parser().data()),
&CppEditor::BuiltinEditorDocumentParser::finished, &CppEditor::BuiltinEditorDocumentParser::finished,
this, [this] { this, [this] {
emit parserConfigChanged(Utils::FilePath::fromString(filePath()), parserConfig()); emit parserConfigChanged(filePath(), parserConfig());
}); });
setSemanticHighlightingChecker([this] { setSemanticHighlightingChecker([this] {
return !ClangModelManagerSupport::clientForFile(m_document.filePath()); return !ClangModelManagerSupport::clientForFile(m_document.filePath());
@@ -84,7 +84,7 @@ void ClangEditorDocumentProcessor::setParserConfig(
const CppEditor::BaseEditorDocumentParser::Configuration &config) const CppEditor::BaseEditorDocumentParser::Configuration &config)
{ {
CppEditor::BuiltinEditorDocumentProcessor::setParserConfig(config); CppEditor::BuiltinEditorDocumentProcessor::setParserConfig(config);
emit parserConfigChanged(Utils::FilePath::fromString(filePath()), config); emit parserConfigChanged(filePath(), config);
} }
CppEditor::BaseEditorDocumentParser::Configuration ClangEditorDocumentProcessor::parserConfig() CppEditor::BaseEditorDocumentParser::Configuration ClangEditorDocumentProcessor::parserConfig()

View File

@@ -275,7 +275,7 @@ void Manager::initialize()
if (doc.data() == nullptr) if (doc.data() == nullptr)
return; return;
d->m_awaitingDocuments.insert(FilePath::fromString(doc->fileName())); d->m_awaitingDocuments.insert(doc->filePath());
d->m_timer.start(400); // Accumulate multiple requests into one, restarts the timer d->m_timer.start(400); // Accumulate multiple requests into one, restarts the timer
}); });

View File

@@ -215,7 +215,7 @@ ParserTreeItem::ConstPtr Parser::getParseDocumentTree(const CPlusPlus::Document:
if (doc.isNull()) if (doc.isNull())
return ParserTreeItem::ConstPtr(); return ParserTreeItem::ConstPtr();
const FilePath fileName = FilePath::fromString(doc->fileName()); const FilePath fileName = doc->filePath();
ParserTreeItem::ConstPtr itemPtr = ParserTreeItem::parseDocument(doc); ParserTreeItem::ConstPtr itemPtr = ParserTreeItem::parseDocument(doc);
@@ -235,8 +235,7 @@ ParserTreeItem::ConstPtr Parser::getCachedOrParseDocumentTree(const CPlusPlus::D
if (doc.isNull()) if (doc.isNull())
return ParserTreeItem::ConstPtr(); return ParserTreeItem::ConstPtr();
const QString &fileName = doc->fileName(); const auto it = d->m_documentCache.constFind(doc->filePath());
const auto it = d->m_documentCache.constFind(FilePath::fromString(fileName));
if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull() if (it != d->m_documentCache.constEnd() && !it.value().tree.isNull()
&& it.value().treeRevision == doc->revision()) { && it.value().treeRevision == doc->revision()) {
return it.value().tree; return it.value().tree;

View File

@@ -22,7 +22,7 @@ namespace CppEditor {
*/ */
BaseEditorDocumentProcessor::BaseEditorDocumentProcessor(QTextDocument *textDocument, BaseEditorDocumentProcessor::BaseEditorDocumentProcessor(QTextDocument *textDocument,
const QString &filePath) const Utils::FilePath &filePath)
: m_filePath(filePath), : m_filePath(filePath),
m_textDocument(textDocument) m_textDocument(textDocument)
{ {

View File

@@ -10,6 +10,7 @@
#include "cpptoolsreuse.h" #include "cpptoolsreuse.h"
#include <coreplugin/helpitem.h> #include <coreplugin/helpitem.h>
#include <texteditor/codeassist/assistinterface.h> #include <texteditor/codeassist/assistinterface.h>
#include <texteditor/quickfix.h> #include <texteditor/quickfix.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
@@ -18,7 +19,6 @@
#include <cplusplus/CppDocument.h> #include <cplusplus/CppDocument.h>
#include <QTextEdit> #include <QTextEdit>
#include <QVariant> #include <QVariant>
#include <functional> #include <functional>
@@ -45,7 +45,7 @@ class CPPEDITOR_EXPORT BaseEditorDocumentProcessor : public QObject
Q_OBJECT Q_OBJECT
public: public:
BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath); BaseEditorDocumentProcessor(QTextDocument *textDocument, const Utils::FilePath &filePath);
~BaseEditorDocumentProcessor() override; ~BaseEditorDocumentProcessor() override;
void run(bool projectsUpdated = false); void run(bool projectsUpdated = false);
@@ -65,7 +65,7 @@ public:
virtual QFuture<CursorInfo> cursorInfo(const CursorInfoParams &params) = 0; virtual QFuture<CursorInfo> cursorInfo(const CursorInfoParams &params) = 0;
QString filePath() const { return m_filePath; } const Utils::FilePath &filePath() const { return m_filePath; }
signals: signals:
// Signal interface to implement // Signal interface to implement
@@ -94,7 +94,7 @@ private:
virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0; virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0;
private: private:
QString m_filePath; Utils::FilePath m_filePath;
QTextDocument *m_textDocument; QTextDocument *m_textDocument;
}; };

View File

@@ -270,7 +270,7 @@ bool handleMacroCase(const Document::Ptr document,
const int length = macro->nameToQString().size(); const int length = macro->nameToQString().size();
// Macro definition // Macro definition
if (macro->fileName() == document->fileName()) if (macro->fileName() == document->filePath().pathView())
ranges->append(toRange(textCursor, macro->utf16CharOffset(), length)); ranges->append(toRange(textCursor, macro->utf16CharOffset(), length));
// Other macro uses // Other macro uses

View File

@@ -137,15 +137,15 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
// Remove changed files from the snapshot // Remove changed files from the snapshot
QSet<Utils::FilePath> toRemove; QSet<Utils::FilePath> toRemove;
for (const Document::Ptr &doc : std::as_const(state.snapshot)) { for (const Document::Ptr &doc : std::as_const(state.snapshot)) {
const Utils::FilePath fileName = Utils::FilePath::fromString(doc->fileName()); const Utils::FilePath filePath = doc->filePath();
if (workingCopy.contains(fileName)) { if (workingCopy.contains(filePath)) {
if (workingCopy.get(fileName).second != doc->editorRevision()) if (workingCopy.get(filePath).second != doc->editorRevision())
addFileAndDependencies(&state.snapshot, &toRemove, fileName); addFileAndDependencies(&state.snapshot, &toRemove, filePath);
continue; continue;
} }
Document::Ptr otherDoc = globalSnapshot.document(fileName); Document::Ptr otherDoc = globalSnapshot.document(filePath);
if (!otherDoc.isNull() && otherDoc->revision() != doc->revision()) if (!otherDoc.isNull() && otherDoc->revision() != doc->revision())
addFileAndDependencies(&state.snapshot, &toRemove, fileName); addFileAndDependencies(&state.snapshot, &toRemove, filePath);
} }
if (!toRemove.isEmpty()) { if (!toRemove.isEmpty()) {
@@ -165,9 +165,8 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
state.snapshot.remove(filePath()); state.snapshot.remove(filePath());
Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) { Internal::CppSourceProcessor sourceProcessor(state.snapshot, [&](const Document::Ptr &doc) {
const QString fileName = doc->fileName(); const bool isInEditor = doc->filePath().toString() == filePath();
const bool isInEditor = fileName == filePath(); Document::Ptr otherDoc = modelManager->document(doc->filePath());
Document::Ptr otherDoc = modelManager->document(fileName);
unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1; unsigned newRev = otherDoc.isNull() ? 1U : otherDoc->revision() + 1;
if (isInEditor) if (isInEditor)
newRev = qMax(rev + 1, newRev); newRev = qMax(rev + 1, newRev);

View File

@@ -136,7 +136,7 @@ QList<TextEditor::BlockRange> toTextEditorBlocks(
} // anonymous namespace } // anonymous namespace
BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(TextEditor::TextDocument *document) BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(TextEditor::TextDocument *document)
: BaseEditorDocumentProcessor(document->document(), document->filePath().toString()) : BaseEditorDocumentProcessor(document->document(), document->filePath())
, m_parser(new BuiltinEditorDocumentParser(document->filePath().toString(), , m_parser(new BuiltinEditorDocumentParser(document->filePath().toString(),
indexerFileSizeLimitInMb())) indexerFileSizeLimitInMb()))
, m_codeWarningsUpdated(false) , m_codeWarningsUpdated(false)
@@ -241,13 +241,13 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d
if (document.isNull()) if (document.isNull())
return; return;
if (document->fileName() != filePath()) if (document->filePath() != filePath())
return; // some other document got updated return; // some other document got updated
if (document->editorRevision() != revision()) if (document->editorRevision() != revision())
return; // outdated content, wait for a new document to be parsed return; // outdated content, wait for a new document to be parsed
qCDebug(log) << "document parsed" << document->fileName() << document->editorRevision(); qCDebug(log) << "document parsed" << document->filePath() << document->editorRevision();
// Emit ifdefed out blocks // Emit ifdefed out blocks
const auto ifdefoutBlocks = toTextEditorBlocks(document->skippedBlocks()); const auto ifdefoutBlocks = toTextEditorBlocks(document->skippedBlocks());
@@ -261,14 +261,14 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d
m_documentSnapshot = snapshot; m_documentSnapshot = snapshot;
const auto source = createSemanticInfoSource(false); const auto source = createSemanticInfoSource(false);
QTC_CHECK(source.snapshot.contains(document->fileName())); QTC_CHECK(source.snapshot.contains(document->filePath()));
m_semanticInfoUpdater.updateDetached(source); m_semanticInfoUpdater.updateDetached(source);
} }
void BuiltinEditorDocumentProcessor::onSemanticInfoUpdated(const SemanticInfo semanticInfo) void BuiltinEditorDocumentProcessor::onSemanticInfoUpdated(const SemanticInfo semanticInfo)
{ {
qCDebug(log) << "semantic info updated" qCDebug(log) << "semantic info updated"
<< semanticInfo.doc->fileName() << semanticInfo.revision << semanticInfo.complete; << semanticInfo.doc->filePath() << semanticInfo.revision << semanticInfo.complete;
emit semanticInfoUpdated(semanticInfo); emit semanticInfoUpdated(semanticInfo);
@@ -283,7 +283,7 @@ void BuiltinEditorDocumentProcessor::onCodeWarningsUpdated(
if (document.isNull()) if (document.isNull())
return; return;
if (document->fileName() != filePath()) if (document->filePath() != filePath())
return; // some other document got updated return; // some other document got updated
if (document->editorRevision() != revision()) if (document->editorRevision() != revision())
@@ -302,10 +302,9 @@ void BuiltinEditorDocumentProcessor::onCodeWarningsUpdated(
SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bool force) const SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bool force) const
{ {
const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy(); const WorkingCopy workingCopy = CppModelManager::instance()->workingCopy();
const QString path = filePath(); return SemanticInfo::Source(filePath().toString(),
return SemanticInfo::Source(path, workingCopy.source(filePath()),
workingCopy.source(path), workingCopy.revision(filePath()),
workingCopy.revision(path),
m_documentSnapshot, m_documentSnapshot,
force); force);
} }

View File

@@ -71,7 +71,7 @@ public:
void process(const CPlusPlus::Document::Ptr document) void process(const CPlusPlus::Document::Ptr document)
{ {
using namespace CPlusPlus; using namespace CPlusPlus;
const QString fileName = document->fileName(); const QString fileName = document->filePath().toString();
const QList<Document::DiagnosticMessage> messages = document->diagnosticMessages(); const QList<Document::DiagnosticMessage> messages = document->diagnosticMessages();
for (const Document::DiagnosticMessage &message : messages) { for (const Document::DiagnosticMessage &message : messages) {
@@ -272,7 +272,7 @@ public:
future.waitForResume(); future.waitForResume();
if (future.isCanceled()) if (future.isCanceled())
break; break;
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) { if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
QVector<Core::SearchResultItem> resultItems; QVector<Core::SearchResultItem> resultItems;
auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult { auto filter = [&](const IndexItem::Ptr &info) -> IndexItem::VisitorResult {
if (matcher.match(info->symbolName()).hasMatch()) { if (matcher.match(info->symbolName()).hasMatch()) {

View File

@@ -312,7 +312,7 @@ void CheckSymbols::run()
{ {
CollectSymbols collectTypes(_doc, _context.snapshot()); CollectSymbols collectTypes(_doc, _context.snapshot());
_fileName = _doc->fileName(); _filePath = _doc->filePath();
_potentialTypes = collectTypes.types(); _potentialTypes = collectTypes.types();
_potentialFields = collectTypes.fields(); _potentialFields = collectTypes.fields();
_potentialFunctions = collectTypes.functions(); _potentialFunctions = collectTypes.functions();
@@ -334,7 +334,7 @@ void CheckSymbols::run()
bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length) bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length)
{ {
Document::DiagnosticMessage m(Document::DiagnosticMessage::Warning, _fileName, line, column, text, length); Document::DiagnosticMessage m(Document::DiagnosticMessage::Warning, _filePath, line, column, text, length);
_diagMsgs.append(m); _diagMsgs.append(m);
return false; return false;
} }

View File

@@ -170,7 +170,7 @@ private:
CPlusPlus::Document::Ptr _doc; CPlusPlus::Document::Ptr _doc;
CPlusPlus::LookupContext _context; CPlusPlus::LookupContext _context;
CPlusPlus::TypeOfExpression typeOfExpression; CPlusPlus::TypeOfExpression typeOfExpression;
QString _fileName; Utils::FilePath _filePath;
QSet<QByteArray> _potentialTypes; QSet<QByteArray> _potentialTypes;
QSet<QByteArray> _potentialFields; QSet<QByteArray> _potentialFields;
QSet<QByteArray> _potentialFunctions; QSet<QByteArray> _potentialFunctions;

View File

@@ -18,6 +18,7 @@
tests the InsertionPointLocator. tests the InsertionPointLocator.
*/ */
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::TemporaryDir;
@@ -42,10 +43,10 @@ Document::Ptr createDocumentAndFile(TemporaryDir *temporaryDir,
int expectedGlobalSymbolCount) int expectedGlobalSymbolCount)
{ {
QTC_ASSERT(temporaryDir, return Document::Ptr()); QTC_ASSERT(temporaryDir, return Document::Ptr());
const QString absoluteFilePath = temporaryDir->createFile(relativeFilePath, text); const FilePath absoluteFilePath = temporaryDir->createFile(relativeFilePath, text);
QTC_ASSERT(!absoluteFilePath.isEmpty(), return Document::Ptr()); QTC_ASSERT(!absoluteFilePath.isEmpty(), return Document::Ptr());
return createDocument(absoluteFilePath, text, expectedGlobalSymbolCount); return createDocument(absoluteFilePath.toString(), text, expectedGlobalSymbolCount);
} }
} // anonymous namespace } // anonymous namespace
@@ -73,7 +74,7 @@ void CodegenTest::testPublicInEmptyClass()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Public); InsertionPointLocator::Public);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -107,7 +108,7 @@ void CodegenTest::testPublicInNonemptyClass()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Public); InsertionPointLocator::Public);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -141,7 +142,7 @@ void CodegenTest::testPublicBeforeProtected()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Public); InsertionPointLocator::Public);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -176,7 +177,7 @@ void CodegenTest::testPrivateAfterProtected()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Private); InsertionPointLocator::Private);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -211,7 +212,7 @@ void CodegenTest::testProtectedInNonemptyClass()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Protected); InsertionPointLocator::Protected);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -246,7 +247,7 @@ void CodegenTest::testProtectedBetweenPublicAndPrivate()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::Protected); InsertionPointLocator::Protected);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -302,7 +303,7 @@ void CodegenTest::testQtdesignerIntegration()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass( InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(), doc->filePath(),
foo, foo,
InsertionPointLocator::PrivateSlot); InsertionPointLocator::PrivateSlot);
QVERIFY(loc.isValid()); QVERIFY(loc.isValid());
@@ -351,7 +352,7 @@ void CodegenTest::testDefinitionEmptyClass()
QList<InsertionLocation> locList = find.methodDefinition(decl); QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
QCOMPARE(loc.suffix(), QString()); QCOMPARE(loc.suffix(), QString());
QCOMPARE(loc.line(), 3); QCOMPARE(loc.line(), 3);
@@ -387,7 +388,7 @@ void CodegenTest::testDefinitionFirstMember()
Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3);
QVERIFY(sourceDocument); QVERIFY(sourceDocument);
sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"),
headerDocument->fileName(), 1, headerDocument->filePath().toString(), 1,
Client::IncludeLocal)); Client::IncludeLocal));
Snapshot snapshot; Snapshot snapshot;
@@ -409,7 +410,7 @@ void CodegenTest::testDefinitionFirstMember()
QList<InsertionLocation> locList = find.methodDefinition(decl); QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.line(), 4); QCOMPARE(loc.line(), 4);
QCOMPARE(loc.column(), 1); QCOMPARE(loc.column(), 1);
QCOMPARE(loc.suffix(), QLatin1String("\n\n")); QCOMPARE(loc.suffix(), QLatin1String("\n\n"));
@@ -446,7 +447,7 @@ void CodegenTest::testDefinitionLastMember()
Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3);
QVERIFY(sourceDocument); QVERIFY(sourceDocument);
sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"),
headerDocument->fileName(), 1, headerDocument->filePath().toString(), 1,
Client::IncludeLocal)); Client::IncludeLocal));
Snapshot snapshot; Snapshot snapshot;
@@ -468,7 +469,7 @@ void CodegenTest::testDefinitionLastMember()
QList<InsertionLocation> locList = find.methodDefinition(decl); QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.line(), 7); QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2); QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
@@ -512,7 +513,7 @@ void CodegenTest::testDefinitionMiddleMember()
Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 4); Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 4);
QVERIFY(sourceDocument); QVERIFY(sourceDocument);
sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"),
headerDocument->fileName(), 1, headerDocument->filePath().toString(), 1,
Client::IncludeLocal)); Client::IncludeLocal));
Snapshot snapshot; Snapshot snapshot;
@@ -534,7 +535,7 @@ void CodegenTest::testDefinitionMiddleMember()
QList<InsertionLocation> locList = find.methodDefinition(decl); QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.line(), 7); QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2); QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
@@ -572,7 +573,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3);
QVERIFY(sourceDocument); QVERIFY(sourceDocument);
sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"),
headerDocument->fileName(), 1, headerDocument->filePath().toString(), 1,
Client::IncludeLocal)); Client::IncludeLocal));
Snapshot snapshot; Snapshot snapshot;
@@ -594,7 +595,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
QList<InsertionLocation> locList = find.methodDefinition(decl); QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.line(), 4); QCOMPARE(loc.line(), 4);
QCOMPARE(loc.column(), 1); QCOMPARE(loc.column(), 1);
QCOMPARE(loc.prefix(), QString()); QCOMPARE(loc.prefix(), QString());
@@ -635,7 +636,7 @@ void CodegenTest::testDefinitionMemberSpecificFile()
Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3); Document::Ptr sourceDocument = createDocumentAndFile(&temporaryDir, "file.cpp", sourceText, 3);
QVERIFY(sourceDocument); QVERIFY(sourceDocument);
sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"), sourceDocument->addIncludeFile(Document::Include(QLatin1String("file.h"),
headerDocument->fileName(), 1, headerDocument->filePath().toString(), 1,
Client::IncludeLocal)); Client::IncludeLocal));
Snapshot snapshot; Snapshot snapshot;
@@ -654,10 +655,11 @@ void CodegenTest::testDefinitionMemberSpecificFile()
CppRefactoringChanges changes(snapshot); CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes); InsertionPointLocator find(changes);
QList<InsertionLocation> locList = find.methodDefinition(decl, true, sourceDocument->fileName()); QList<InsertionLocation> locList =
find.methodDefinition(decl, true, sourceDocument->filePath().toString());
QVERIFY(locList.size() == 1); QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first(); InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), sourceDocument->fileName()); QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
QCOMPARE(loc.line(), 7); QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2); QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n")); QCOMPARE(loc.prefix(), QLatin1String("\n\n"));

View File

@@ -33,6 +33,8 @@
#include <numeric> #include <numeric>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
namespace CMI = CppEditor::CppCodeModelInspector; namespace CMI = CppEditor::CppCodeModelInspector;
namespace { namespace {
@@ -48,11 +50,11 @@ TextEditor::BaseTextEditor *currentEditor()
return qobject_cast<TextEditor::BaseTextEditor*>(Core::EditorManager::currentEditor()); return qobject_cast<TextEditor::BaseTextEditor*>(Core::EditorManager::currentEditor());
} }
QString fileInCurrentEditor() Utils::FilePath fileInCurrentEditor()
{ {
if (TextEditor::BaseTextEditor *editor = currentEditor()) if (TextEditor::BaseTextEditor *editor = currentEditor())
return editor->document()->filePath().toString(); return editor->document()->filePath();
return QString(); return {};
} }
QSizePolicy sizePolicyWithStretchFactor(int stretchFactor) QSizePolicy sizePolicyWithStretchFactor(int stretchFactor)
@@ -435,7 +437,7 @@ public:
void configure(const Snapshot &snapshot); void configure(const Snapshot &snapshot);
void setGlobalSnapshot(const Snapshot &snapshot); void setGlobalSnapshot(const Snapshot &snapshot);
QModelIndex indexForDocument(const QString &filePath); QModelIndex indexForDocument(const Utils::FilePath &filePath);
enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount }; enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount };
@@ -465,11 +467,11 @@ void SnapshotModel::setGlobalSnapshot(const Snapshot &snapshot)
m_globalSnapshot = snapshot; m_globalSnapshot = snapshot;
} }
QModelIndex SnapshotModel::indexForDocument(const QString &filePath) QModelIndex SnapshotModel::indexForDocument(const FilePath &filePath)
{ {
for (int i = 0, total = m_documents.size(); i < total; ++i) { for (int i = 0, total = m_documents.size(); i < total; ++i) {
const Document::Ptr document = m_documents.at(i); const Document::Ptr document = m_documents.at(i);
if (document->fileName() == filePath) if (document->filePath() == filePath)
return index(i, FilePathColumn); return index(i, FilePathColumn);
} }
return {}; return {};
@@ -493,12 +495,12 @@ QVariant SnapshotModel::data(const QModelIndex &index, int role) const
if (column == SymbolCountColumn) { if (column == SymbolCountColumn) {
return document->control()->symbolCount(); return document->control()->symbolCount();
} else if (column == SharedColumn) { } else if (column == SharedColumn) {
Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); Document::Ptr globalDocument = m_globalSnapshot.document(document->filePath());
const bool isShared const bool isShared
= globalDocument && globalDocument->fingerprint() == document->fingerprint(); = globalDocument && globalDocument->fingerprint() == document->fingerprint();
return CMI::Utils::toString(isShared); return CMI::Utils::toString(isShared);
} else if (column == FilePathColumn) { } else if (column == FilePathColumn) {
return QDir::toNativeSeparators(document->fileName()); return document->filePath().toUserOutput();
} }
} }
return QVariant(); return QVariant();
@@ -1200,7 +1202,7 @@ public:
WorkingCopyModel(QObject *parent); WorkingCopyModel(QObject *parent);
void configure(const WorkingCopy &workingCopy); void configure(const WorkingCopy &workingCopy);
QModelIndex indexForFile(const QString &filePath); QModelIndex indexForFile(const Utils::FilePath &filePath);
enum Columns { RevisionColumn, FilePathColumn, ColumnCount }; enum Columns { RevisionColumn, FilePathColumn, ColumnCount };
@@ -1211,11 +1213,11 @@ public:
private: private:
struct WorkingCopyEntry { struct WorkingCopyEntry {
WorkingCopyEntry(const QString &filePath, const QByteArray &source, unsigned revision) WorkingCopyEntry(const Utils::FilePath &filePath, const QByteArray &source, unsigned revision)
: filePath(filePath), source(source), revision(revision) : filePath(filePath), source(source), revision(revision)
{} {}
QString filePath; Utils::FilePath filePath;
QByteArray source; QByteArray source;
unsigned revision; unsigned revision;
}; };
@@ -1232,14 +1234,13 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy)
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
m_workingCopyList.clear(); m_workingCopyList.clear();
const WorkingCopy::Table &elements = workingCopy.elements(); const WorkingCopy::Table &elements = workingCopy.elements();
for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it)
m_workingCopyList << WorkingCopyEntry(it.key().toString(), it.value().first, m_workingCopyList << WorkingCopyEntry(it.key(), it.value().first, it.value().second);
it.value().second);
}
emit layoutChanged(); emit layoutChanged();
} }
QModelIndex WorkingCopyModel::indexForFile(const QString &filePath) QModelIndex WorkingCopyModel::indexForFile(const Utils::FilePath &filePath)
{ {
for (int i = 0, total = m_workingCopyList.size(); i < total; ++i) { for (int i = 0, total = m_workingCopyList.size(); i < total; ++i) {
const WorkingCopyEntry entry = m_workingCopyList.at(i); const WorkingCopyEntry entry = m_workingCopyList.at(i);
@@ -1267,7 +1268,7 @@ QVariant WorkingCopyModel::data(const QModelIndex &index, int role) const
if (column == RevisionColumn) if (column == RevisionColumn)
return m_workingCopyList.at(row).revision; return m_workingCopyList.at(row).revision;
else if (column == FilePathColumn) else if (column == FilePathColumn)
return m_workingCopyList.at(row).filePath; return m_workingCopyList.at(row).filePath.toString();
} else if (role == Qt::UserRole) { } else if (role == Qt::UserRole) {
return m_workingCopyList.at(row).source; return m_workingCopyList.at(row).source;
} }
@@ -1659,14 +1660,14 @@ void CppCodeModelInspectorDialog::updateDocumentData(const Document::Ptr &docume
// General // General
const KeyValueModel::Table table = { const KeyValueModel::Table table = {
{QString::fromLatin1("File Path"), QDir::toNativeSeparators(document->fileName())}, {QString::fromLatin1("File Path"), document->filePath().toUserOutput()},
{QString::fromLatin1("Last Modified"), CMI::Utils::toString(document->lastModified())}, {QString::fromLatin1("Last Modified"), CMI::Utils::toString(document->lastModified())},
{QString::fromLatin1("Revision"), CMI::Utils::toString(document->revision())}, {QString::fromLatin1("Revision"), CMI::Utils::toString(document->revision())},
{QString::fromLatin1("Editor Revision"), CMI::Utils::toString(document->editorRevision())}, {QString::fromLatin1("Editor Revision"), CMI::Utils::toString(document->editorRevision())},
{QString::fromLatin1("Check Mode"), CMI::Utils::toString(document->checkMode())}, {QString::fromLatin1("Check Mode"), CMI::Utils::toString(document->checkMode())},
{QString::fromLatin1("Tokenized"), CMI::Utils::toString(document->isTokenized())}, {QString::fromLatin1("Tokenized"), CMI::Utils::toString(document->isTokenized())},
{QString::fromLatin1("Parsed"), CMI::Utils::toString(document->isParsed())}, {QString::fromLatin1("Parsed"), CMI::Utils::toString(document->isParsed())},
{QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->fileName())} {QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->filePath())}
}; };
m_docGenericInfoModel->configure(table); m_docGenericInfoModel->configure(table);
resizeColumns<KeyValueModel>(m_ui->docGeneralView); resizeColumns<KeyValueModel>(m_ui->docGeneralView);

View File

@@ -384,10 +384,10 @@ QString Utils::toString(const ProjectExplorer::Abi &abi)
return QString("??"); return QString("??");
} }
QString Utils::partsForFile(const QString &fileName) QString Utils::partsForFile(const ::Utils::FilePath &filePath)
{ {
const QList<ProjectPart::ConstPtr> parts const QList<ProjectPart::ConstPtr> parts
= CppModelManager::instance()->projectPart(fileName); = CppModelManager::instance()->projectPart(filePath);
QString result; QString result;
for (const ProjectPart::ConstPtr &part : parts) for (const ProjectPart::ConstPtr &part : parts)
result += part->displayName + QLatin1Char(','); result += part->displayName + QLatin1Char(',');
@@ -580,7 +580,7 @@ void Dumper::dumpSnapshot(const CPlusPlus::Snapshot &snapshot, const QString &ti
QList<CPlusPlus::Document::Ptr> globallyShared; QList<CPlusPlus::Document::Ptr> globallyShared;
QList<CPlusPlus::Document::Ptr> notGloballyShared; QList<CPlusPlus::Document::Ptr> notGloballyShared;
for (const CPlusPlus::Document::Ptr &document : documents) { for (const CPlusPlus::Document::Ptr &document : documents) {
CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); CPlusPlus::Document::Ptr globalDocument = m_globalSnapshot.document(document->filePath());
if (globalDocument && globalDocument->fingerprint() == document->fingerprint()) if (globalDocument && globalDocument->fingerprint() == document->fingerprint())
globallyShared.append(document); globallyShared.append(document);
else else
@@ -641,18 +641,18 @@ void Dumper::dumpDocuments(const QList<CPlusPlus::Document::Ptr> &documents, boo
const QByteArray i4 = indent(4); const QByteArray i4 = indent(4);
for (const CPlusPlus::Document::Ptr &document : documents) { for (const CPlusPlus::Document::Ptr &document : documents) {
if (skipDetails) { if (skipDetails) {
m_out << i2 << "\"" << document->fileName() << "\"\n"; m_out << i2 << "\"" << document->filePath() << "\"\n";
continue; continue;
} }
m_out << i2 << "Document \"" << document->fileName() << "\"{{{3\n"; m_out << i2 << "Document \"" << document->filePath() << "\"{{{3\n";
m_out << i3 << "Last Modified : " << Utils::toString(document->lastModified()) << "\n"; m_out << i3 << "Last Modified : " << Utils::toString(document->lastModified()) << "\n";
m_out << i3 << "Revision : " << Utils::toString(document->revision()) << "\n"; m_out << i3 << "Revision : " << Utils::toString(document->revision()) << "\n";
m_out << i3 << "Editor Revision: " << Utils::toString(document->editorRevision()) << "\n"; m_out << i3 << "Editor Revision: " << Utils::toString(document->editorRevision()) << "\n";
m_out << i3 << "Check Mode : " << Utils::toString(document->checkMode()) << "\n"; m_out << i3 << "Check Mode : " << Utils::toString(document->checkMode()) << "\n";
m_out << i3 << "Tokenized : " << Utils::toString(document->isTokenized()) << "\n"; m_out << i3 << "Tokenized : " << Utils::toString(document->isTokenized()) << "\n";
m_out << i3 << "Parsed : " << Utils::toString(document->isParsed()) << "\n"; m_out << i3 << "Parsed : " << Utils::toString(document->isParsed()) << "\n";
m_out << i3 << "Project Parts : " << Utils::partsForFile(document->fileName()) << "\n"; m_out << i3 << "Project Parts : " << Utils::partsForFile(document->filePath()) << "\n";
const QList<CPlusPlus::Document::Include> includes = document->unresolvedIncludes() const QList<CPlusPlus::Document::Include> includes = document->unresolvedIncludes()
+ document->resolvedIncludes(); + document->resolvedIncludes();

View File

@@ -33,7 +33,7 @@ struct Utils
static QString toString(ProjectFile::Kind kind); static QString toString(ProjectFile::Kind kind);
static QString toString(CPlusPlus::Kind kind); static QString toString(CPlusPlus::Kind kind);
static QString toString(const ProjectExplorer::Abi &abi); static QString toString(const ProjectExplorer::Abi &abi);
static QString partsForFile(const QString &fileName); static QString partsForFile(const ::Utils::FilePath &filePath);
static QString unresolvedFileNameWithDelimiters(const CPlusPlus::Document::Include &include); static QString unresolvedFileNameWithDelimiters(const CPlusPlus::Document::Include &include);
static QString pathListToString(const QStringList &pathList); static QString pathListToString(const QStringList &pathList);
static QString pathListToString(const ProjectExplorer::HeaderPaths &pathList); static QString pathListToString(const ProjectExplorer::HeaderPaths &pathList);

View File

@@ -45,7 +45,8 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
Environment env; Environment env;
Preprocessor preprocess(nullptr, &env); Preprocessor preprocess(nullptr, &env);
const QByteArray preprocessedSource const QByteArray preprocessedSource
= preprocess.run(QLatin1String("<no-file>"), textDocument->toPlainText().toUtf8()); = preprocess.run(Utils::FilePath::fromParts({}, {}, u"<no-file>"),
textDocument->toPlainText().toUtf8());
Document::Ptr cppDocument = Document::create(QLatin1String("<no-file>")); Document::Ptr cppDocument = Document::create(QLatin1String("<no-file>"));
cppDocument->setUtf8Source(preprocessedSource); cppDocument->setUtf8Source(preprocessedSource);

View File

@@ -26,9 +26,11 @@
/*! /*!
Tests for code completion. Tests for code completion.
*/ */
using namespace Core;
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace TextEditor; using namespace TextEditor;
using namespace Core; using namespace Utils;
namespace CppEditor::Internal { namespace CppEditor::Internal {
namespace { namespace {
@@ -53,11 +55,11 @@ public:
m_temporaryDir.reset(new CppEditor::Tests::TemporaryDir()); m_temporaryDir.reset(new CppEditor::Tests::TemporaryDir());
QVERIFY(m_temporaryDir->isValid()); QVERIFY(m_temporaryDir->isValid());
const QByteArray fileExt = isObjC ? "mm" : "h"; const QByteArray fileExt = isObjC ? "mm" : "h";
const QString fileName = m_temporaryDir->createFile("file." + fileExt, m_source); const FilePath filePath = m_temporaryDir->createFile("file." + fileExt, m_source);
QVERIFY(!fileName.isEmpty()); QVERIFY(!filePath.isEmpty());
// Open in editor // Open in editor
m_editor = EditorManager::openEditor(Utils::FilePath::fromString(fileName)); m_editor = EditorManager::openEditor(filePath);
QVERIFY(m_editor); QVERIFY(m_editor);
closeEditorAtEndOfTestCase(m_editor); closeEditorAtEndOfTestCase(m_editor);
m_editorWidget = TextEditorWidget::fromEditor(m_editor); m_editorWidget = TextEditorWidget::fromEditor(m_editor);
@@ -66,7 +68,7 @@ public:
m_textDocument = m_editorWidget->document(); m_textDocument = m_editorWidget->document();
// Get Document // Get Document
const Document::Ptr document = waitForFileInGlobalSnapshot(fileName); const Document::Ptr document = waitForFileInGlobalSnapshot(filePath.toString());
QVERIFY(document); QVERIFY(document);
QVERIFY(document->diagnosticMessages().isEmpty()); QVERIFY(document->diagnosticMessages().isEmpty());

View File

@@ -1480,7 +1480,7 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope)
addKeywords(); addKeywords();
addMacros(CppModelManager::configurationFileName(), context.snapshot()); addMacros(CppModelManager::configurationFileName(), context.snapshot());
addMacros(context.thisDocument()->fileName(), context.snapshot()); addMacros(context.thisDocument()->filePath().toString(), context.snapshot());
addSnippets(); addSnippets();
return !m_completions.isEmpty(); return !m_completions.isEmpty();
} }
@@ -1860,10 +1860,10 @@ void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snap
{ {
Document::Ptr doc = snapshot.document(fileName); Document::Ptr doc = snapshot.document(fileName);
if (!doc || processed->contains(doc->fileName())) if (!doc || processed->contains(doc->filePath().path()))
return; return;
processed->insert(doc->fileName()); processed->insert(doc->filePath().path());
const QList<Document::Include> includes = doc->resolvedIncludes(); const QList<Document::Include> includes = doc->resolvedIncludes();
for (const Document::Include &i : includes) for (const Document::Include &i : includes)

View File

@@ -119,7 +119,7 @@ void CppCurrentDocumentFilter::accept(const Core::LocatorFilterEntry &selection,
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc) void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (m_currentFileName == doc->fileName()) if (m_currentFileName == doc->filePath())
m_itemsOfCurrentDoc.clear(); m_itemsOfCurrentDoc.clear();
} }
@@ -127,7 +127,7 @@ void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *currentEdit
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (currentEditor) if (currentEditor)
m_currentFileName = currentEditor->document()->filePath().toString(); m_currentFileName = currentEditor->document()->filePath();
else else
m_currentFileName.clear(); m_currentFileName.clear();
m_itemsOfCurrentDoc.clear(); m_itemsOfCurrentDoc.clear();
@@ -139,7 +139,7 @@ void CppCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutTo
return; return;
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
if (m_currentFileName == editorAboutToClose->document()->filePath().toString()) { if (m_currentFileName == editorAboutToClose->document()->filePath()) {
m_currentFileName.clear(); m_currentFileName.clear();
m_itemsOfCurrentDoc.clear(); m_itemsOfCurrentDoc.clear();
} }

View File

@@ -41,7 +41,7 @@ private:
SearchSymbols search; SearchSymbols search;
mutable QMutex m_mutex; mutable QMutex m_mutex;
QString m_currentFileName; Utils::FilePath m_currentFileName;
QList<IndexItem::Ptr> m_itemsOfCurrentDoc; QList<IndexItem::Ptr> m_itemsOfCurrentDoc;
}; };

View File

@@ -21,6 +21,8 @@ using CppEditor::Tests::TemporaryDir;
using CppEditor::Tests::TestCase; using CppEditor::Tests::TestCase;
using CppEditor::Internal::Tests::VerifyCleanCppModelManager; using CppEditor::Internal::Tests::VerifyCleanCppModelManager;
using namespace Utils;
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
namespace Tests { namespace Tests {
@@ -425,7 +427,7 @@ void DoxygenTest::runTest(const QByteArray &original,
} }
// Update Code Model // Update Code Model
QVERIFY(TestCase::parseFiles(testDocument.filePath())); QVERIFY(TestCase::parseFiles(testDocument.filePath().toString()));
// Open Editor // Open Editor
QVERIFY(TestCase::openCppEditor(testDocument.filePath(), &testDocument.m_editor, QVERIFY(TestCase::openCppEditor(testDocument.filePath(), &testDocument.m_editor,

View File

@@ -496,7 +496,7 @@ void CppEditorDocument::onDiagnosticsChanged(const QString &fileName, const QStr
const Utils::Id category = Utils::Id::fromString(kind); const Utils::Id category = Utils::Id::fromString(kind);
for (const auto &diagnostic : mm()->diagnosticMessages()) { for (const auto &diagnostic : mm()->diagnosticMessages()) {
if (FilePath::fromString(diagnostic.fileName()) == filePath()) { if (diagnostic.filePath() == filePath()) {
auto it = std::find_if(std::begin(removedMarks), auto it = std::find_if(std::begin(removedMarks),
std::end(removedMarks), std::end(removedMarks),
[&category, &diagnostic](TextMark *existing) { [&category, &diagnostic](TextMark *existing) {

View File

@@ -239,7 +239,7 @@ public:
categorize(categorize) categorize(categorize)
{ } { }
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName) QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath)
{ {
QList<CPlusPlus::Usage> usages; QList<CPlusPlus::Usage> usages;
if (future->isPaused()) if (future->isPaused())
@@ -248,18 +248,18 @@ public:
return usages; return usages;
const CPlusPlus::Identifier *symbolId = symbol->identifier(); const CPlusPlus::Identifier *symbolId = symbol->identifier();
if (CPlusPlus::Document::Ptr previousDoc = snapshot.document(fileName)) { if (CPlusPlus::Document::Ptr previousDoc = snapshot.document(filePath)) {
CPlusPlus::Control *control = previousDoc->control(); CPlusPlus::Control *control = previousDoc->control();
if (!control->findIdentifier(symbolId->chars(), symbolId->size())) if (!control->findIdentifier(symbolId->chars(), symbolId->size()))
return usages; // skip this document, it's not using symbolId. return usages; // skip this document, it's not using symbolId.
} }
CPlusPlus::Document::Ptr doc; CPlusPlus::Document::Ptr doc;
const QByteArray unpreprocessedSource = getSource(fileName, workingCopy); const QByteArray unpreprocessedSource = getSource(filePath, workingCopy);
if (symbolDocument && fileName == Utils::FilePath::fromString(symbolDocument->fileName())) { if (symbolDocument && filePath == symbolDocument->filePath()) {
doc = symbolDocument; doc = symbolDocument;
} else { } else {
doc = snapshot.preprocessedDocument(unpreprocessedSource, fileName); doc = snapshot.preprocessedDocument(unpreprocessedSource, filePath);
doc->tokenize(); doc->tokenize();
} }
@@ -541,10 +541,9 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete
CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile); CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
// document is not parsed and has no bindings yet, do it // document is not parsed and has no bindings yet, do it
QByteArray source = getSource(Utils::FilePath::fromString(newSymbolDocument->fileName()), QByteArray source = getSource(newSymbolDocument->filePath(), m_modelManager->workingCopy());
m_modelManager->workingCopy());
CPlusPlus::Document::Ptr doc = CPlusPlus::Document::Ptr doc =
snapshot.preprocessedDocument(source, FilePath::fromString(newSymbolDocument->fileName())); snapshot.preprocessedDocument(source, newSymbolDocument->filePath());
doc->check(); doc->check();
// find matching symbol in new document and return the new parameters // find matching symbol in new document and return the new parameters

View File

@@ -182,8 +182,8 @@ Class *VirtualFunctionHelper::staticClassOfFunctionCallExpression_internal() con
Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snapshot &snapshot, Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snapshot &snapshot,
QSet<QString> *processed) QSet<QString> *processed)
{ {
if (doc && !name.startsWith('<') && !processed->contains(doc->fileName())) { if (doc && !name.startsWith('<') && !processed->contains(doc->filePath().path())) {
processed->insert(doc->fileName()); processed->insert(doc->filePath().path());
for (const Macro &macro : doc->definedMacros()) { for (const Macro &macro : doc->definedMacros()) {
if (macro.name() == name) { if (macro.name() == name) {

View File

@@ -198,8 +198,7 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
// find the start/end offsets // find the start/end offsets
CppRefactoringChanges refactoringChanges(snapshot); CppRefactoringChanges refactoringChanges(snapshot);
CppRefactoringFilePtr sourceFile = refactoringChanges.file( CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->filePath());
Utils::FilePath::fromString(doc->fileName()));
sourceFile->setCppDocument(doc); sourceFile->setCppDocument(doc);
int start, end; int start, end;
declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end); declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end);

View File

@@ -17,6 +17,7 @@
#include <QtTest> #include <QtTest>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::TemporaryDir;
@@ -56,7 +57,7 @@ public:
{ {
QVERIFY(succeededSoFar()); QVERIFY(succeededSoFar());
QSet<QString> filePaths; QSet<FilePath> filePaths;
const int sourceListSize = sourceList.size(); const int sourceListSize = sourceList.size();
TemporaryDir temporaryDir; TemporaryDir temporaryDir;
@@ -67,14 +68,13 @@ public:
// Write source to file // Write source to file
const QString fileName = QString::fromLatin1("file%1.h").arg(i+1); const QString fileName = QString::fromLatin1("file%1.h").arg(i+1);
const QString absoluteFilePath = temporaryDir.createFile(fileName.toLatin1(), source); filePaths << temporaryDir.createFile(fileName.toLatin1(), source);
filePaths << absoluteFilePath;
} }
// Open Editor // Open Editor
const QString fileName = temporaryDir.path() + QLatin1String("/file1.h"); const Utils::FilePath filePath = temporaryDir.filePath() / "file1.h";
TextEditor::BaseTextEditor *editor; TextEditor::BaseTextEditor *editor;
QVERIFY(openCppEditor(fileName, &editor)); QVERIFY(openCppEditor(filePath, &editor));
closeEditorAtEndOfTestCase(editor); closeEditorAtEndOfTestCase(editor);
// Update Code Model // Update Code Model

View File

@@ -25,7 +25,7 @@ void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
bool isPending = false; bool isPending = false;
for (int i = 0, ei = m_pendingDocuments.size(); i < ei; ++i) { for (int i = 0, ei = m_pendingDocuments.size(); i < ei; ++i) {
const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i); const CPlusPlus::Document::Ptr &doc = m_pendingDocuments.at(i);
if (doc->fileName() == document->fileName()) { if (doc->filePath() == document->filePath()) {
isPending = true; isPending = true;
if (document->revision() >= doc->revision()) if (document->revision() >= doc->revision())
m_pendingDocuments[i] = document; m_pendingDocuments[i] = document;
@@ -33,7 +33,7 @@ void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
} }
} }
if (!isPending && QFileInfo(document->fileName()).suffix() != "moc") if (!isPending && document->filePath().suffix() != "moc")
m_pendingDocuments.append(document); m_pendingDocuments.append(document);
flushPendingDocument(false); flushPendingDocument(false);
@@ -50,7 +50,7 @@ void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
m_infosByFile.remove(file); m_infosByFile.remove(file);
for (int i = 0; i < m_pendingDocuments.size(); ++i) { for (int i = 0; i < m_pendingDocuments.size(); ++i) {
if (m_pendingDocuments.at(i)->fileName() == file) { if (m_pendingDocuments.at(i)->filePath().path() == file) {
m_pendingDocuments.remove(i); m_pendingDocuments.remove(i);
break; break;
} }
@@ -70,7 +70,7 @@ void CppLocatorData::flushPendingDocument(bool force) const
return; return;
for (CPlusPlus::Document::Ptr doc : std::as_const(m_pendingDocuments)) for (CPlusPlus::Document::Ptr doc : std::as_const(m_pendingDocuments))
m_infosByFile.insert(Internal::StringTable::insert(doc->fileName()), m_search(doc)); m_infosByFile.insert(Internal::StringTable::insert(doc->filePath()), m_search(doc));
m_pendingDocuments.clear(); m_pendingDocuments.clear();
m_pendingDocuments.reserve(MaxPendingDocuments); m_pendingDocuments.reserve(MaxPendingDocuments);

View File

@@ -263,10 +263,10 @@ QSet<QString> CppModelManager::timeStampModifiedFiles(const QList<Document::Ptr>
const QDateTime lastModified = doc->lastModified(); const QDateTime lastModified = doc->lastModified();
if (!lastModified.isNull()) { if (!lastModified.isNull()) {
QFileInfo fileInfo(doc->fileName()); const FilePath filePath = doc->filePath();
if (fileInfo.exists() && fileInfo.lastModified() != lastModified) if (filePath.exists() && filePath.lastModified() != lastModified)
sourceFiles.insert(doc->fileName()); sourceFiles.insert(filePath.toString());
} }
} }
@@ -286,7 +286,7 @@ CppSourceProcessor *CppModelManager::createSourceProcessor()
{ {
CppModelManager *that = instance(); CppModelManager *that = instance();
return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) { return new CppSourceProcessor(that->snapshot(), [that](const Document::Ptr &doc) {
const Document::Ptr previousDocument = that->document(doc->fileName()); const Document::Ptr previousDocument = that->document(doc->filePath());
const unsigned newRevision = previousDocument.isNull() const unsigned newRevision = previousDocument.isNull()
? 1U ? 1U
: previousDocument->revision() + 1; : previousDocument->revision() + 1;
@@ -816,10 +816,10 @@ Snapshot CppModelManager::snapshot() const
return d->m_snapshot; return d->m_snapshot;
} }
Document::Ptr CppModelManager::document(const QString &fileName) const Document::Ptr CppModelManager::document(const FilePath &filePath) const
{ {
QMutexLocker locker(&d->m_snapshotMutex); QMutexLocker locker(&d->m_snapshotMutex);
return d->m_snapshot.document(fileName); return d->m_snapshot.document(filePath);
} }
/// Replace the document in the snapshot. /// Replace the document in the snapshot.
@@ -829,7 +829,7 @@ bool CppModelManager::replaceDocument(Document::Ptr newDoc)
{ {
QMutexLocker locker(&d->m_snapshotMutex); QMutexLocker locker(&d->m_snapshotMutex);
Document::Ptr previous = d->m_snapshot.document(newDoc->fileName()); Document::Ptr previous = d->m_snapshot.document(newDoc->filePath());
if (previous && (newDoc->revision() != 0 && newDoc->revision() < previous->revision())) if (previous && (newDoc->revision() != 0 && newDoc->revision() < previous->revision()))
// the new document is outdated // the new document is outdated
return false; return false;
@@ -1617,7 +1617,7 @@ void CppModelManager::renameIncludes(const Utils::FilePath &oldFilePath,
const QList<Snapshot::IncludeLocation> locations = snapshot().includeLocationsOfDocument( const QList<Snapshot::IncludeLocation> locations = snapshot().includeLocationsOfDocument(
isUiFile ? oldFileName : oldFilePath.toString()); isUiFile ? oldFileName : oldFilePath.toString());
for (const Snapshot::IncludeLocation &loc : locations) { for (const Snapshot::IncludeLocation &loc : locations) {
const auto filePath = FilePath::fromString(loc.first->fileName()); const FilePath filePath = loc.first->filePath();
// Larger projects can easily have more than one ui file with the same name. // Larger projects can easily have more than one ui file with the same name.
// Replace only if ui file and including source file belong to the same product. // Replace only if ui file and including source file belong to the same product.

View File

@@ -118,7 +118,7 @@ public:
ProjectPart::ConstPtr fallbackProjectPart(); ProjectPart::ConstPtr fallbackProjectPart();
CPlusPlus::Snapshot snapshot() const override; CPlusPlus::Snapshot snapshot() const override;
Document::Ptr document(const QString &fileName) const; Document::Ptr document(const Utils::FilePath &filePath) const;
bool replaceDocument(Document::Ptr newDoc); bool replaceDocument(Document::Ptr newDoc);
void emitDocumentUpdated(Document::Ptr doc); void emitDocumentUpdated(Document::Ptr doc);

View File

@@ -33,6 +33,7 @@
QCOMPARE(document->revision(), expectedRevision); QCOMPARE(document->revision(), expectedRevision);
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
using CPlusPlus::Document; using CPlusPlus::Document;
@@ -66,6 +67,11 @@ public:
QString fileFromSourcesDir(const QString &fileName) const QString fileFromSourcesDir(const QString &fileName) const
{ return directory(_("sources")) + QLatin1Char('/') + fileName; } { return directory(_("sources")) + QLatin1Char('/') + fileName; }
FilePath filePath(const QString &p) const
{
return FilePath::fromString(TestDataDir::file(p));
}
}; };
QStringList toAbsolutePaths(const QStringList &relativePathList, QStringList toAbsolutePaths(const QStringList &relativePathList,
@@ -113,7 +119,7 @@ public:
class FileChangerAndRestorer class FileChangerAndRestorer
{ {
public: public:
explicit FileChangerAndRestorer(const QString &filePath) explicit FileChangerAndRestorer(const Utils::FilePath &filePath)
: m_filePath(filePath) : m_filePath(filePath)
{ {
} }
@@ -127,7 +133,7 @@ public:
bool readContents(QByteArray *contents) bool readContents(QByteArray *contents)
{ {
Utils::FileReader fileReader; Utils::FileReader fileReader;
const bool isFetchOk = fileReader.fetch(Utils::FilePath::fromString(m_filePath)); const bool isFetchOk = fileReader.fetch(m_filePath);
if (isFetchOk) { if (isFetchOk) {
m_originalFileContents = fileReader.data(); m_originalFileContents = fileReader.data();
if (contents) if (contents)
@@ -148,7 +154,7 @@ private:
} }
QByteArray m_originalFileContents; QByteArray m_originalFileContents;
const QString &m_filePath; const Utils::FilePath m_filePath;
}; };
ProjectPart::ConstPtr projectPartOfEditorDocument(const QString &filePath) ProjectPart::ConstPtr projectPartOfEditorDocument(const QString &filePath)
@@ -216,7 +222,7 @@ void ModelManagerTest::testFrameworkHeaders()
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QVERIFY(mm->snapshot().contains(source)); QVERIFY(mm->snapshot().contains(source));
Document::Ptr doc = mm->document(source); Document::Ptr doc = mm->document(Utils::FilePath::fromString(source));
QVERIFY(!doc.isNull()); QVERIFY(!doc.isNull());
CPlusPlus::Namespace *ns = doc->globalNamespace(); CPlusPlus::Namespace *ns = doc->globalNamespace();
QVERIFY(ns); QVERIFY(ns);
@@ -482,7 +488,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
// Modify the file // Modify the file
QTest::qSleep(1000); // Make sure the timestamp is different QTest::qSleep(1000); // Make sure the timestamp is different
FileChangerAndRestorer fileChangerAndRestorer(fileToChange); FileChangerAndRestorer fileChangerAndRestorer(FilePath::fromString(fileToChange));
QByteArray originalContents; QByteArray originalContents;
QVERIFY(fileChangerAndRestorer.readContents(&originalContents)); QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;"; const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
@@ -762,16 +768,15 @@ void ModelManagerTest::testDefinesPerProject()
for (auto &i : d) { for (auto &i : d) {
const QString firstDeclarationName = i.firstDeclarationName; const QString firstDeclarationName = i.firstDeclarationName;
const QString fileName = i.fileName; const Utils::FilePath filePath = Utils::FilePath::fromString(i.fileName);
Core::IEditor *editor = Core::EditorManager::openEditor( Core::IEditor *editor = Core::EditorManager::openEditor(filePath);
Utils::FilePath::fromString(fileName));
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(fileName); Document::Ptr doc = mm->document(filePath);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
} }
} }
@@ -845,7 +850,7 @@ void ModelManagerTest::testPrecompiledHeaders()
Utils::Language::Cxx, false}); Utils::Language::Cxx, false});
// Check if defines from pch are considered // Check if defines from pch are considered
Document::Ptr document = mm->document(fileName); Document::Ptr document = mm->document(Utils::FilePath::fromString(fileName));
QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName); QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName);
// Check if declarations from pch are considered // Check if declarations from pch are considered
@@ -919,7 +924,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(main1File); Document::Ptr doc = mm->document(FilePath::fromString(main1File));
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName); QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
} }
} }
@@ -1154,9 +1159,9 @@ void ModelManagerTest::testDocumentsAndRevisions()
// Index two files // Index two files
const MyTestDataDir testDir(_("testdata_project1")); const MyTestDataDir testDir(_("testdata_project1"));
const QString filePath1 = testDir.file(QLatin1String("foo.h")); const FilePath filePath1 = testDir.filePath(QLatin1String("foo.h"));
const QString filePath2 = testDir.file(QLatin1String("foo.cpp")); const FilePath filePath2 = testDir.filePath(QLatin1String("foo.cpp"));
const QSet<QString> filesToIndex = {filePath1,filePath2}; const QSet<FilePath> filesToIndex = {filePath1,filePath2};
QVERIFY(TestCase::parseFiles(filesToIndex)); QVERIFY(TestCase::parseFiles(filesToIndex));
CppModelManager *modelManager = CppModelManager::instance(); CppModelManager *modelManager = CppModelManager::instance();
@@ -1167,7 +1172,7 @@ void ModelManagerTest::testDocumentsAndRevisions()
TextEditor::BaseTextEditor *editor1; TextEditor::BaseTextEditor *editor1;
QVERIFY(helper.openCppEditor(filePath1, &editor1)); QVERIFY(helper.openCppEditor(filePath1, &editor1));
helper.closeEditorAtEndOfTestCase(editor1); helper.closeEditorAtEndOfTestCase(editor1);
QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1.toString()));
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U);
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 1U);
@@ -1180,7 +1185,7 @@ void ModelManagerTest::testDocumentsAndRevisions()
TextEditor::BaseTextEditor *editor2; TextEditor::BaseTextEditor *editor2;
QVERIFY(helper.openCppEditor(filePath2, &editor2)); QVERIFY(helper.openCppEditor(filePath2, &editor2));
helper.closeEditorAtEndOfTestCase(editor2); helper.closeEditorAtEndOfTestCase(editor2);
QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2.toString()));
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U);
VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath2), 3U);

View File

@@ -24,6 +24,7 @@
#include <QtTest> #include <QtTest>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
Q_DECLARE_METATYPE(CppEditor::Internal::Overview) Q_DECLARE_METATYPE(CppEditor::Internal::Overview)
@@ -63,15 +64,15 @@ public:
// Write source to temprorary file // Write source to temprorary file
CppEditor::Tests::TemporaryDir temporaryDir; CppEditor::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid()); QVERIFY(temporaryDir.isValid());
const QString filePath = temporaryDir.createFile("file.h", sourceWithoutCursorMarker); const FilePath filePath = temporaryDir.createFile("file.h", sourceWithoutCursorMarker);
QVERIFY(!filePath.isEmpty()); QVERIFY(!filePath.isEmpty());
// Preprocess source // Preprocess source
Environment env; CPlusPlus::Environment env;
Preprocessor preprocess(nullptr, &env); Preprocessor preprocess(nullptr, &env);
const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker); const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker);
Document::Ptr document = Document::create(filePath); Document::Ptr document = Document::create(filePath.toString());
document->setUtf8Source(preprocessedSource); document->setUtf8Source(preprocessedSource);
document->parse(parseMode); document->parse(parseMode);
document->check(); document->check();
@@ -83,9 +84,7 @@ public:
QScopedPointer<TextEditor::BaseTextEditor> editor( QScopedPointer<TextEditor::BaseTextEditor> editor(
TextEditor::PlainTextEditorFactory::createPlainTextEditor()); TextEditor::PlainTextEditorFactory::createPlainTextEditor());
QString error; QString error;
editor->document()->open(&error, editor->document()->open(&error, document->filePath(), document->filePath());
Utils::FilePath::fromString(document->fileName()),
Utils::FilePath::fromString(document->fileName()));
QVERIFY(error.isEmpty()); QVERIFY(error.isEmpty());
// Set cursor position // Set cursor position

View File

@@ -25,6 +25,7 @@
using namespace Core; using namespace Core;
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace TextEditor; using namespace TextEditor;
using namespace Utils;
using CppEditor::Tests::TemporaryDir; using CppEditor::Tests::TemporaryDir;
using CppEditor::Tests::Internal::TestIncludePaths; using CppEditor::Tests::Internal::TestIncludePaths;
@@ -92,7 +93,7 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc
} }
// Update Code Model // Update Code Model
QSet<QString> filePaths; QSet<FilePath> filePaths;
for (const TestDocumentPtr &document : std::as_const(m_testDocuments)) for (const TestDocumentPtr &document : std::as_const(m_testDocuments))
filePaths << document->filePath(); filePaths << document->filePath();
QVERIFY(parseFiles(filePaths)); QVERIFY(parseFiles(filePaths));
@@ -150,7 +151,7 @@ BaseQuickFixTestCase::~BaseQuickFixTestCase()
// Remove created files from file system // Remove created files from file system
for (const TestDocumentPtr &testDocument : std::as_const(m_testDocuments)) for (const TestDocumentPtr &testDocument : std::as_const(m_testDocuments))
QVERIFY(QFile::remove(testDocument->filePath())); QVERIFY(testDocument->filePath().removeFile());
} }
/// Leading whitespace is not removed, so we can check if the indetation ranges /// Leading whitespace is not removed, so we can check if the indetation ranges

View File

@@ -80,7 +80,7 @@
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace TextEditor; using namespace TextEditor;
using Utils::ChangeSet; using namespace Utils;
namespace CppEditor { namespace CppEditor {
@@ -2056,7 +2056,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
QString className; QString className;
QList<Core::LocatorFilterEntry> matches; QList<Core::LocatorFilterEntry> matches;
const QString currentDocumentFilePath = interface.semanticInfo().doc->fileName(); const QString currentDocumentFilePath = interface.semanticInfo().doc->filePath().toString();
const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath); const ProjectExplorer::HeaderPaths headerPaths = relevantHeaderPaths(currentDocumentFilePath);
QList<Utils::FilePath> headers; QList<Utils::FilePath> headers;
@@ -2530,7 +2530,7 @@ public:
const QString &targetFileName, const Class *targetSymbol, const QString &targetFileName, const Class *targetSymbol,
InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority) InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority)
: CppQuickFixOperation(interface, priority) : CppQuickFixOperation(interface, priority)
, m_targetFileName(targetFileName) , m_targetFileName(FilePath::fromString(targetFileName))
, m_targetSymbol(targetSymbol) , m_targetSymbol(targetSymbol)
, m_xsSpec(xsSpec) , m_xsSpec(xsSpec)
, m_decl(decl) , m_decl(decl)
@@ -2549,8 +2549,7 @@ public:
m_targetFileName, m_targetSymbol, m_xsSpec); m_targetFileName, m_targetSymbol, m_xsSpec);
QTC_ASSERT(loc.isValid(), return); QTC_ASSERT(loc.isValid(), return);
CppRefactoringFilePtr targetFile = refactoring.file( CppRefactoringFilePtr targetFile = refactoring.file(m_targetFileName);
Utils::FilePath::fromString(m_targetFileName));
int targetPosition1 = targetFile->position(loc.line(), loc.column()); int targetPosition1 = targetFile->position(loc.line(), loc.column());
int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1); int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1);
@@ -2565,7 +2564,7 @@ public:
static QString generateDeclaration(const Function *function); static QString generateDeclaration(const Function *function);
private: private:
QString m_targetFileName; FilePath m_targetFileName;
const Class *m_targetSymbol; const Class *m_targetSymbol;
InsertionPointLocator::AccessSpec m_xsSpec; InsertionPointLocator::AccessSpec m_xsSpec;
QString m_decl; QString m_decl;
@@ -2985,12 +2984,12 @@ private:
const CppRefactoringChanges refactoring(snapshot()); const CppRefactoringChanges refactoring(snapshot());
const InsertionPointLocator locator(refactoring); const InsertionPointLocator locator(refactoring);
const QString filePath = QString::fromUtf8(m_class->fileName()); const FilePath filePath = FilePath::fromUtf8(m_class->fileName());
const InsertionLocation loc = locator.methodDeclarationInClass( const InsertionLocation loc = locator.methodDeclarationInClass(
filePath, m_class, InsertionPointLocator::Private); filePath, m_class, InsertionPointLocator::Private);
QTC_ASSERT(loc.isValid(), return); QTC_ASSERT(loc.isValid(), return);
CppRefactoringFilePtr targetFile = refactoring.file(Utils::FilePath::fromString(filePath)); CppRefactoringFilePtr targetFile = refactoring.file(filePath);
const int targetPosition1 = targetFile->position(loc.line(), loc.column()); const int targetPosition1 = targetFile->position(loc.line(), loc.column());
const int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1); const int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1);
ChangeSet target; ChangeSet target;
@@ -3633,7 +3632,7 @@ protected:
if (insertionPoint != m_headerInsertionPoints.end()) if (insertionPoint != m_headerInsertionPoints.end())
return *insertionPoint; return *insertionPoint;
const InsertionLocation loc = m_locator.methodDeclarationInClass( const InsertionLocation loc = m_locator.methodDeclarationInClass(
m_headerFile->filePath().toString(), m_class, spec, m_headerFile->filePath(), m_class, spec,
InsertionPointLocator::ForceAccessSpec::Yes); InsertionPointLocator::ForceAccessSpec::Yes);
m_headerInsertionPoints.insert(spec, loc); m_headerInsertionPoints.insert(spec, loc);
return loc; return loc;
@@ -4943,10 +4942,10 @@ public:
// Write declaration, if necessary. // Write declaration, if necessary.
if (matchingClass) { if (matchingClass) {
InsertionPointLocator locator(refactoring); InsertionPointLocator locator(refactoring);
const QString fileName = QLatin1String(matchingClass->fileName()); const FilePath filePath = FilePath::fromUtf8(matchingClass->fileName());
const InsertionLocation &location = const InsertionLocation &location =
locator.methodDeclarationInClass(fileName, matchingClass, options.access); locator.methodDeclarationInClass(filePath, matchingClass, options.access);
CppRefactoringFilePtr declFile = refactoring.file(Utils::FilePath::fromString(fileName)); CppRefactoringFilePtr declFile = refactoring.file(filePath);
change.clear(); change.clear();
position = declFile->position(location.line(), location.column()); position = declFile->position(location.line(), location.column());
change.insert(position, location.prefix() + funcDecl + location.suffix()); change.insert(position, location.prefix() + funcDecl + location.suffix());
@@ -8081,8 +8080,7 @@ private:
while (!nodesWithProcessedParents.empty()) { while (!nodesWithProcessedParents.empty()) {
Node &node = nodesWithProcessedParents.back(); Node &node = nodesWithProcessedParents.back();
nodesWithProcessedParents.pop_back(); nodesWithProcessedParents.pop_back();
CppRefactoringFilePtr file = refactoring.file( CppRefactoringFilePtr file = refactoring.file(node.document->filePath());
Utils::FilePath::fromString(node.document->fileName()));
const bool parentHasUsing = Utils::anyOf(node.includes, &Node::hasGlobalUsingDirective); const bool parentHasUsing = Utils::anyOf(node.includes, &Node::hasGlobalUsingDirective);
const int startPos = parentHasUsing const int startPos = parentHasUsing
? 0 ? 0
@@ -8154,14 +8152,13 @@ private:
if (m_processed.contains(loc.first)) if (m_processed.contains(loc.first))
continue; continue;
CppRefactoringFilePtr file = refactoring.file( CppRefactoringFilePtr file = refactoring.file(loc.first->filePath());
Utils::FilePath::fromString(loc.first->fileName()));
const bool noGlobalUsing = refactorFile(file, const bool noGlobalUsing = refactorFile(file,
refactoring.snapshot(), refactoring.snapshot(),
file->position(loc.second, 1)); file->position(loc.second, 1));
m_processed.insert(loc.first); m_processed.insert(loc.first);
if (noGlobalUsing) if (noGlobalUsing)
processIncludes(refactoring, loc.first->fileName()); processIncludes(refactoring, loc.first->filePath().toString());
} }
} }

View File

@@ -121,7 +121,7 @@ bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::So
&& currentSemanticInfo.revision == source.revision && currentSemanticInfo.revision == source.revision
&& currentSemanticInfo.doc && currentSemanticInfo.doc
&& currentSemanticInfo.doc->translationUnit()->ast() && currentSemanticInfo.doc->translationUnit()->ast()
&& currentSemanticInfo.doc->fileName() == source.fileName && currentSemanticInfo.doc->filePath().toString() == source.fileName
&& !currentSemanticInfo.snapshot.isEmpty() && !currentSemanticInfo.snapshot.isEmpty()
&& currentSemanticInfo.snapshot == source.snapshot) { && currentSemanticInfo.snapshot == source.snapshot) {
SemanticInfo newSemanticInfo; SemanticInfo newSemanticInfo;

View File

@@ -66,7 +66,7 @@ inline Message messageNoSuchFile(Document::Ptr &document, const QString &fileNam
{ {
const QString text = QCoreApplication::translate( const QString text = QCoreApplication::translate(
"CppSourceProcessor", "%1: No such file or directory").arg(fileName); "CppSourceProcessor", "%1: No such file or directory").arg(fileName);
return Message(Message::Warning, document->fileName(), line, /*column =*/ 0, text); return Message(Message::Warning, document->filePath(), line, /*column =*/ 0, text);
} }
inline Message messageNoFileContents(Document::Ptr &document, const QString &fileName, inline Message messageNoFileContents(Document::Ptr &document, const QString &fileName,
@@ -74,7 +74,7 @@ inline Message messageNoFileContents(Document::Ptr &document, const QString &fil
{ {
const QString text = QCoreApplication::translate( const QString text = QCoreApplication::translate(
"CppSourceProcessor", "%1: Could not get file contents").arg(fileName); "CppSourceProcessor", "%1: Could not get file contents").arg(fileName);
return Message(Message::Warning, document->fileName(), line, /*column =*/ 0, text); return Message(Message::Warning, document->filePath(), line, /*column =*/ 0, text);
} }
inline const CPlusPlus::Macro revision(const WorkingCopy &workingCopy, inline const CPlusPlus::Macro revision(const WorkingCopy &workingCopy,
@@ -244,7 +244,7 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ
if (m_currentDoc) { if (m_currentDoc) {
if (type == IncludeLocal) { if (type == IncludeLocal) {
const QFileInfo currentFileInfo(m_currentDoc->fileName()); const QFileInfo currentFileInfo = m_currentDoc->filePath().toFileInfo();
const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName; const QString path = cleanPath(currentFileInfo.absolutePath()) + fileName;
if (checkFile(path)) if (checkFile(path))
return path; return path;
@@ -252,7 +252,7 @@ QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType typ
// searching as if this would be a global include. // searching as if this would be a global include.
} else if (type == IncludeNext) { } else if (type == IncludeNext) {
const QFileInfo currentFileInfo(m_currentDoc->fileName()); const QFileInfo currentFileInfo = m_currentDoc->filePath().toFileInfo();
const QString currentDirPath = cleanPath(currentFileInfo.dir().path()); const QString currentDirPath = cleanPath(currentFileInfo.dir().path());
auto headerPathsEnd = m_headerPaths.end(); auto headerPathsEnd = m_headerPaths.end();
auto headerPathsIt = m_headerPaths.begin(); auto headerPathsIt = m_headerPaths.begin();
@@ -372,7 +372,7 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc)
if (!doc) if (!doc)
return; return;
const QString fn = doc->fileName(); const QString fn = doc->filePath().path();
if (m_processed.contains(fn)) if (m_processed.contains(fn))
return; return;
@@ -457,7 +457,8 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
document->setLastModified(info.lastModified()); document->setLastModified(info.lastModified());
const Document::Ptr previousDocument = switchCurrentDocument(document); const Document::Ptr previousDocument = switchCurrentDocument(document);
const QByteArray preprocessedCode = m_preprocess.run(absoluteFileName, contents); const QByteArray preprocessedCode =
m_preprocess.run(Utils::FilePath::fromString(absoluteFileName), contents);
// { // {
// QByteArray b(preprocessedCode); b.replace("\n", "<<<\n"); // QByteArray b(preprocessedCode); b.replace("\n", "<<<\n");
// qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData()); // qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData());
@@ -478,7 +479,7 @@ void CppSourceProcessor::sourceNeeded(int line, const QString &fileName, Include
document->setUtf8Source(preprocessedCode); document->setUtf8Source(preprocessedCode);
document->keepSourceAndAST(); document->keepSourceAndAST();
document->tokenize(); document->tokenize();
document->check(m_workingCopy.contains(document->fileName()) ? Document::FullCheck document->check(m_workingCopy.contains(document->filePath()) ? Document::FullCheck
: Document::FastCheck); : Document::FastCheck);
m_documentFinished(document); m_documentFinished(document);

View File

@@ -21,7 +21,8 @@
#include <QtTest> #include <QtTest>
using namespace CPlusPlus; using namespace CPlusPlus;
using ProjectExplorer::HeaderPathType; using namespace ProjectExplorer;
using namespace Utils;
using Include = Document::Include; using Include = Document::Include;
using CppEditor::Tests::TestCase; using CppEditor::Tests::TestCase;
@@ -46,7 +47,7 @@ public:
TestIncludePaths::directoryOfTestFile())}); TestIncludePaths::directoryOfTestFile())});
sourceProcessor->run(filePath); sourceProcessor->run(filePath);
Document::Ptr document = m_cmm->document(filePath); Document::Ptr document = m_cmm->document(Utils::FilePath::fromString(filePath));
return document; return document;
} }
@@ -96,7 +97,8 @@ void SourceProcessorTest::testIncludesCyclic()
{ {
const QString fileName1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h")); const QString fileName1 = TestIncludePaths::testFilePath(QLatin1String("cyclic1.h"));
const QString fileName2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h")); const QString fileName2 = TestIncludePaths::testFilePath(QLatin1String("cyclic2.h"));
const QSet<QString> sourceFiles = {fileName1, fileName2}; const QSet<FilePath> sourceFiles = {FilePath::fromString(fileName1),
FilePath::fromString(fileName2)};
// Create global snapshot (needed in BuiltinEditorDocumentParser) // Create global snapshot (needed in BuiltinEditorDocumentParser)
TestCase testCase; TestCase testCase;
@@ -104,7 +106,7 @@ void SourceProcessorTest::testIncludesCyclic()
// Open editor // Open editor
TextEditor::BaseTextEditor *editor; TextEditor::BaseTextEditor *editor;
QVERIFY(testCase.openCppEditor(fileName1, &editor)); QVERIFY(testCase.openCppEditor(FilePath::fromString(fileName1), &editor));
testCase.closeEditorAtEndOfTestCase(editor); testCase.closeEditorAtEndOfTestCase(editor);
// Check editor snapshot // Check editor snapshot
@@ -165,7 +167,7 @@ void SourceProcessorTest::testMacroUses()
static bool isMacroDefinedInDocument(const QByteArray &macroName, const Document::Ptr &document) static bool isMacroDefinedInDocument(const QByteArray &macroName, const Document::Ptr &document)
{ {
for (const Macro &macro : document->definedMacros()) { for (const CPlusPlus::Macro &macro : document->definedMacros()) {
if (macro.name() == macroName) if (macro.name() == macroName)
return true; return true;
} }

View File

@@ -84,15 +84,15 @@ TestDocumentPtr CppTestDocument::create(const QByteArray &fileName, const QByteA
return doc; return doc;
} }
QString CppTestDocument::filePath() const FilePath CppTestDocument::filePath() const
{ {
if (!m_baseDirectory.isEmpty()) if (!m_baseDirectory.isEmpty())
return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName); return FilePath::fromString(QDir::cleanPath(m_baseDirectory + '/' + m_fileName));
if (!QFileInfo(m_fileName).isAbsolute()) if (!QFileInfo(m_fileName).isAbsolute())
return Utils::TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName; return FilePath::fromString(TemporaryDirectory::masterDirectoryPath() + '/' + m_fileName);
return m_fileName; return FilePath::fromString(m_fileName);
} }
bool CppTestDocument::writeToDisk() const bool CppTestDocument::writeToDisk() const
@@ -212,11 +212,11 @@ bool TestCase::succeededSoFar() const
return m_succeededSoFar; return m_succeededSoFar;
} }
bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, bool TestCase::openCppEditor(const FilePath &filePath, TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget) CppEditorWidget **editorWidget)
{ {
if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>( if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(
Core::EditorManager::openEditor(FilePath::fromString(fileName)))) { Core::EditorManager::openEditor(filePath))) {
if (editor) { if (editor) {
*editor = e; *editor = e;
TextEditor::StorageSettings s = e->textDocument()->storageSettings(); TextEditor::StorageSettings s = e->textDocument()->storageSettings();
@@ -281,16 +281,17 @@ CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEdito
return editorWidget->semanticInfo().doc; return editorWidget->semanticInfo().doc;
} }
bool TestCase::parseFiles(const QSet<QString> &filePaths) bool TestCase::parseFiles(const QSet<FilePath> &filePaths)
{ {
CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); QSet<QString> filePaths_ = transform(filePaths, &FilePath::toString);
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()) {
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;
} }
@@ -299,7 +300,7 @@ bool TestCase::parseFiles(const QSet<QString> &filePaths)
bool TestCase::parseFiles(const QString &filePath) bool TestCase::parseFiles(const QString &filePath)
{ {
return parseFiles(QSet<QString>{filePath}); return parseFiles({FilePath::fromString(filePath)});
} }
void TestCase::closeEditorAtEndOfTestCase(Core::IEditor *editor) void TestCase::closeEditorAtEndOfTestCase(Core::IEditor *editor)
@@ -355,11 +356,11 @@ bool TestCase::waitUntilProjectIsFullyOpened(Project *project, int timeOutInMs)
timeOutInMs); timeOutInMs);
} }
bool TestCase::writeFile(const QString &filePath, const QByteArray &contents) bool TestCase::writeFile(const FilePath &filePath, const QByteArray &contents)
{ {
Utils::FileSaver saver(Utils::FilePath::fromString(filePath)); Utils::FileSaver saver(filePath);
if (!saver.write(contents) || !saver.finalize()) { if (!saver.write(contents) || !saver.finalize()) {
qWarning() << "Failed to write file to disk:" << qPrintable(filePath); qWarning() << "Failed to write file to disk:" << qPrintable(filePath.toUserOutput());
return false; return false;
} }
return true; return true;
@@ -419,15 +420,15 @@ TemporaryDir::TemporaryDir()
{ {
} }
QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArray &contents) FilePath TemporaryDir::createFile(const QByteArray &relativePath, const QByteArray &contents)
{ {
const QString relativePathString = QString::fromUtf8(relativePath); const QString relativePathString = QString::fromUtf8(relativePath);
if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute()) if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute())
return QString(); return {};
const QString filePath = m_temporaryDir.filePath(relativePathString).path(); const FilePath filePath = m_temporaryDir.filePath(relativePathString);
if (!TestCase::writeFile(filePath, contents)) if (!TestCase::writeFile(filePath, contents))
return QString(); return {};
return filePath; return filePath;
} }

View File

@@ -60,7 +60,7 @@ public:
QString baseDirectory() const { return m_baseDirectory; } QString baseDirectory() const { return m_baseDirectory; }
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; } void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
QString filePath() const; Utils::FilePath filePath() const;
bool writeToDisk() const; bool writeToDisk() const;
bool hasCursorMarker() const { return m_cursorPosition != -1; } bool hasCursorMarker() const { return m_cursorPosition != -1; }
@@ -123,14 +123,14 @@ public:
~TestCase(); ~TestCase();
bool succeededSoFar() const; bool succeededSoFar() const;
static bool openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, static bool openCppEditor(const Utils::FilePath &filePath, TextEditor::BaseTextEditor **editor,
CppEditorWidget **editorWidget = nullptr); CppEditorWidget **editorWidget = nullptr);
void closeEditorAtEndOfTestCase(Core::IEditor *editor); void closeEditorAtEndOfTestCase(Core::IEditor *editor);
static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor); static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor);
static bool parseFiles(const QString &filePath); static bool parseFiles(const QString &filePath);
static bool parseFiles(const QSet<QString> &filePaths); static bool parseFiles(const QSet<Utils::FilePath> &filePaths);
static CPlusPlus::Snapshot globalSnapshot(); static CPlusPlus::Snapshot globalSnapshot();
static bool garbageCollectGlobalSnapshot(); static bool garbageCollectGlobalSnapshot();
@@ -149,7 +149,7 @@ public:
const QStringList &filePaths, const QStringList &filePaths,
int timeOutInMs = defaultTimeOutInMs); int timeOutInMs = defaultTimeOutInMs);
static bool writeFile(const QString &filePath, const QByteArray &contents); static bool writeFile(const Utils::FilePath &filePath, const QByteArray &contents);
protected: protected:
CppModelManager *m_modelManager; CppModelManager *m_modelManager;
@@ -184,8 +184,9 @@ public:
bool isValid() const { return m_isValid; } bool isValid() const { return m_isValid; }
QString path() const { return m_temporaryDir.path().path(); } QString path() const { return m_temporaryDir.path().path(); }
Utils::FilePath filePath() const { return m_temporaryDir.path(); }
QString createFile(const QByteArray &relativePath, const QByteArray &contents); Utils::FilePath createFile(const QByteArray &relativePath, const QByteArray &contents);
protected: protected:
Utils::TemporaryDirectory m_temporaryDir; Utils::TemporaryDirectory m_temporaryDir;

View File

@@ -51,6 +51,7 @@
using namespace Core; using namespace Core;
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace TextEditor; using namespace TextEditor;
using namespace Utils;
namespace CppEditor::Internal::Tests { namespace CppEditor::Internal::Tests {
@@ -158,7 +159,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
QCOMPARE(DocumentModel::openedDocuments().size(), 0); QCOMPARE(DocumentModel::openedDocuments().size(), 0);
BaseTextEditor *editor; BaseTextEditor *editor;
CppEditorWidget *editorWidget; CppEditorWidget *editorWidget;
QVERIFY(openCppEditor(filePath, &editor, &editorWidget)); QVERIFY(openCppEditor(FilePath::fromString(filePath), &editor, &editorWidget));
QCOMPARE(DocumentModel::openedDocuments().size(), 1); QCOMPARE(DocumentModel::openedDocuments().size(), 1);
QVERIFY(m_modelManager->isCppEditor(editor)); QVERIFY(m_modelManager->isCppEditor(editor));

View File

@@ -62,6 +62,7 @@ using namespace CPlusPlus;
using namespace TextEditor; using namespace TextEditor;
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
class OverrideItem class OverrideItem
{ {
@@ -256,7 +257,8 @@ F2TestCase::F2TestCase(CppEditorAction action,
QVERIFY(testFile->baseDirectory().isEmpty()); QVERIFY(testFile->baseDirectory().isEmpty());
testFile->setBaseDirectory(temporaryDir.path()); testFile->setBaseDirectory(temporaryDir.path());
QVERIFY(testFile->writeToDisk()); QVERIFY(testFile->writeToDisk());
projectFileContent += QString::fromLatin1("\"%1\",").arg(testFile->filePath()); projectFileContent += QString::fromLatin1("\"%1\",")
.arg(testFile->filePath().toString());
} }
projectFileContent += "]}\n"; projectFileContent += "]}\n";
@@ -272,9 +274,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
CppTestDocument projectFile("project.qbs", projectFileContent.toUtf8()); CppTestDocument projectFile("project.qbs", projectFileContent.toUtf8());
projectFile.setBaseDirectory(temporaryDir.path()); projectFile.setBaseDirectory(temporaryDir.path());
QVERIFY(projectFile.writeToDisk()); QVERIFY(projectFile.writeToDisk());
const auto openProjectResult = const auto openProjectResult = ProjectExplorerPlugin::openProject(projectFile.filePath());
ProjectExplorerPlugin::openProject(
Utils::FilePath::fromString(projectFile.filePath()));
QVERIFY2(openProjectResult && openProjectResult.project(), QVERIFY2(openProjectResult && openProjectResult.project(),
qPrintable(openProjectResult.errorMessage())); qPrintable(openProjectResult.errorMessage()));
projectCloser.setProject(openProjectResult.project()); projectCloser.setProject(openProjectResult.project());
@@ -286,7 +286,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
} }
// Update Code Model // Update Code Model
QSet<QString> filePaths; QSet<FilePath> filePaths;
for (const TestDocumentPtr &testFile : testFiles) for (const TestDocumentPtr &testFile : testFiles)
filePaths << testFile->filePath(); filePaths << testFile->filePath();
QVERIFY(parseFiles(filePaths)); QVERIFY(parseFiles(filePaths));
@@ -302,7 +302,8 @@ F2TestCase::F2TestCase(CppEditorAction action,
// The file is "Full Checked" since it is in the working copy now, // The file is "Full Checked" since it is in the working copy now,
// that is the function bodies are processed. // that is the function bodies are processed.
forever { forever {
const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath()); const Document::Ptr document =
waitForFileInGlobalSnapshot(testFile->filePath().toString());
QVERIFY(document); QVERIFY(document);
if (document->checkMode() == Document::FullCheck) { if (document->checkMode() == Document::FullCheck) {
if (!document->diagnosticMessages().isEmpty()) if (!document->diagnosticMessages().isEmpty())
@@ -405,7 +406,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
BaseTextEditor *currentTextEditor = dynamic_cast<BaseTextEditor*>(currentEditor); BaseTextEditor *currentTextEditor = dynamic_cast<BaseTextEditor*>(currentEditor);
QVERIFY(currentTextEditor); QVERIFY(currentTextEditor);
QCOMPARE(currentTextEditor->document()->filePath().toString(), targetTestFile->filePath()); QCOMPARE(currentTextEditor->document()->filePath(), targetTestFile->filePath());
int expectedLine, expectedColumn; int expectedLine, expectedColumn;
if (useClangd && expectedVirtualFunctionProposal.size() == 1) { if (useClangd && expectedVirtualFunctionProposal.size() == 1) {
expectedLine = expectedVirtualFunctionProposal.first().line; expectedLine = expectedVirtualFunctionProposal.first().line;

View File

@@ -518,7 +518,7 @@ static QList<Include> includesForSource(const QString &filePath)
TestIncludePaths::globalIncludePath())}); TestIncludePaths::globalIncludePath())});
sourceProcessor->run(filePath); sourceProcessor->run(filePath);
Document::Ptr document = cmm->document(filePath); Document::Ptr document = cmm->document(FilePath::fromString(filePath));
return document->resolvedIncludes(); return document->resolvedIncludes();
} }

View File

@@ -251,13 +251,12 @@ InsertionPointLocator::InsertionPointLocator(const CppRefactoringChanges &refact
} }
InsertionLocation InsertionPointLocator::methodDeclarationInClass( InsertionLocation InsertionPointLocator::methodDeclarationInClass(
const QString &fileName, const Utils::FilePath &filePath,
const Class *clazz, const Class *clazz,
AccessSpec xsSpec, AccessSpec xsSpec,
ForceAccessSpec forceAccessSpec) const ForceAccessSpec forceAccessSpec) const
{ {
const Document::Ptr doc = m_refactoringChanges.file(Utils::FilePath::fromString(fileName)) const Document::Ptr doc = m_refactoringChanges.file(filePath)->cppDocument();
->cppDocument();
if (doc) { if (doc) {
FindInClass find(doc->translationUnit(), clazz); FindInClass find(doc->translationUnit(), clazz);
ClassSpecifierAST *classAST = find(); ClassSpecifierAST *classAST = find();

View File

@@ -80,8 +80,7 @@ public:
public: public:
explicit InsertionPointLocator(const CppRefactoringChanges &refactoringChanges); explicit InsertionPointLocator(const CppRefactoringChanges &refactoringChanges);
InsertionLocation methodDeclarationInClass( InsertionLocation methodDeclarationInClass(const Utils::FilePath &fileName,
const QString &fileName,
const CPlusPlus::Class *clazz, const CPlusPlus::Class *clazz,
AccessSpec xsSpec, AccessSpec xsSpec,
ForceAccessSpec forceAccessSpec = ForceAccessSpec::No ForceAccessSpec forceAccessSpec = ForceAccessSpec::No

View File

@@ -37,7 +37,7 @@ void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types)
IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope) IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
{ {
IndexItem::Ptr root = IndexItem::create(Internal::StringTable::insert(doc->fileName()), 100); IndexItem::Ptr root = IndexItem::create(Internal::StringTable::insert(doc->filePath()), 100);
{ // RAII scope { // RAII scope
ScopedIndexItemPtr parentRaii(_parent, root); ScopedIndexItemPtr parentRaii(_parent, root);
@@ -46,7 +46,7 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope
QTC_ASSERT(_parent, return IndexItem::Ptr()); QTC_ASSERT(_parent, return IndexItem::Ptr());
QTC_ASSERT(root, return IndexItem::Ptr()); QTC_ASSERT(root, return IndexItem::Ptr());
QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->fileName()), QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->filePath()),
return IndexItem::Ptr()); return IndexItem::Ptr());
for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i) for (int i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)

View File

@@ -56,6 +56,11 @@ StringTablePrivate::StringTablePrivate()
connect(&m_gcCountDown, &QTimer::timeout, this, &StringTablePrivate::startGC); connect(&m_gcCountDown, &QTimer::timeout, this, &StringTablePrivate::startGC);
} }
QString StringTable::insert(const Utils::FilePath &path)
{
return m_instance->insert(path.path());
}
QString StringTable::insert(const QString &string) QString StringTable::insert(const QString &string)
{ {
return m_instance->insert(string); return m_instance->insert(string);

View File

@@ -3,13 +3,14 @@
#pragma once #pragma once
#include <QString> #include <utils/filepath.h>
namespace CppEditor::Internal { namespace CppEditor::Internal {
class StringTable class StringTable
{ {
public: public:
static QString insert(const Utils::FilePath &string);
static QString insert(const QString &string); static QString insert(const QString &string);
static void scheduleGC(); static void scheduleGC();

View File

@@ -444,7 +444,7 @@ QStringList SymbolFinder::fileIterationOrder(const QString &referenceFile, const
checkCacheConsistency(referenceFile, snapshot); checkCacheConsistency(referenceFile, snapshot);
} else { } else {
for (Document::Ptr doc : snapshot) for (Document::Ptr doc : snapshot)
insertCache(referenceFile, doc->fileName()); insertCache(referenceFile, doc->filePath().path());
} }
QStringList files = m_filePriorityCache.value(referenceFile).toStringList(); QStringList files = m_filePriorityCache.value(referenceFile).toStringList();
@@ -468,8 +468,8 @@ void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Sna
// corresponding document and notices it's now null. // corresponding document and notices it's now null.
const QSet<QString> &meta = m_fileMetaCache.value(referenceFile); const QSet<QString> &meta = m_fileMetaCache.value(referenceFile);
for (const Document::Ptr &doc : snapshot) { for (const Document::Ptr &doc : snapshot) {
if (!meta.contains(doc->fileName())) if (!meta.contains(doc->filePath().path()))
insertCache(referenceFile, doc->fileName()); insertCache(referenceFile, doc->filePath().path());
} }
} }

View File

@@ -16,6 +16,8 @@
#include <QtTest> #include <QtTest>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace Utils;
using CppEditor::Internal::Tests::CppTestDocument; using CppEditor::Internal::Tests::CppTestDocument;
Q_DECLARE_METATYPE(QList<CppTestDocument>) Q_DECLARE_METATYPE(QList<CppTestDocument>)
@@ -82,7 +84,7 @@ public:
QList<CppTestDocument> documents_ = documents; QList<CppTestDocument> documents_ = documents;
// Write files // Write files
QSet<QString> filePaths; QSet<FilePath> filePaths;
for (auto &document : documents_) { for (auto &document : documents_) {
document.setBaseDirectory(temporaryDir.path()); document.setBaseDirectory(temporaryDir.path());
QVERIFY(document.writeToDisk()); QVERIFY(document.writeToDisk());

View File

@@ -52,7 +52,7 @@ static QString msgClassNotFound(const QString &uiClassName, const QList<Document
QString files; QString files;
for (const Document::Ptr &doc : docList) { for (const Document::Ptr &doc : docList) {
files += '\n'; files += '\n';
files += QDir::toNativeSeparators(doc->fileName()); files += doc->filePath().toUserOutput();
} }
return Designer::Tr::tr( return Designer::Tr::tr(
"The class containing \"%1\" could not be found in %2.\n" "The class containing \"%1\" could not be found in %2.\n"
@@ -241,7 +241,7 @@ static void addDeclaration(const Snapshot &snapshot,
CppEditor::CppRefactoringChanges refactoring(snapshot); CppEditor::CppRefactoringChanges refactoring(snapshot);
CppEditor::InsertionPointLocator find(refactoring); CppEditor::InsertionPointLocator find(refactoring);
const CppEditor::InsertionLocation loc = find.methodDeclarationInClass( const CppEditor::InsertionLocation loc = find.methodDeclarationInClass(
fileName, cl, CppEditor::InsertionPointLocator::PrivateSlot); FilePath::fromString(fileName), cl, CppEditor::InsertionPointLocator::PrivateSlot);
// //
//! \todo change this to use the Refactoring changes. //! \todo change this to use the Refactoring changes.
@@ -339,7 +339,7 @@ static ClassDocumentPtrPair
const Document::Ptr doc = context.thisDocument(); const Document::Ptr doc = context.thisDocument();
const Snapshot docTable = context.snapshot(); const Snapshot docTable = context.snapshot();
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << doc->fileName() << className << maxIncludeDepth; qDebug() << Q_FUNC_INFO << doc->filePath() << className << maxIncludeDepth;
// Check document // Check document
if (const Class *cl = findClass(doc->globalNamespace(), context, className)) if (const Class *cl = findClass(doc->globalNamespace(), context, className))
return ClassDocumentPtrPair(cl, doc); return ClassDocumentPtrPair(cl, doc);
@@ -455,8 +455,8 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file
DocumentMap docMap; DocumentMap docMap;
for (const Document::Ptr &d : docList) { for (const Document::Ptr &d : docList) {
const QFileInfo docFi(d->fileName()); docMap.insert(qAbs(d->filePath().absolutePath().toString()
docMap.insert(qAbs(docFi.absolutePath().compare(uiFolder, Qt::CaseInsensitive)), d); .compare(uiFolder, Qt::CaseInsensitive)), d);
} }
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
@@ -501,14 +501,14 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames); const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames);
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << "Found " << uiClass << declDoc->fileName() << " checking " << functionName << functionNameWithParameterNames; qDebug() << Q_FUNC_INFO << "Found " << uiClass << declDoc->filePath() << " checking " << functionName << functionNameWithParameterNames;
Function *fun = findDeclaration(cl, functionName); Function *fun = findDeclaration(cl, functionName);
QString declFilePath; QString declFilePath;
if (!fun) { if (!fun) {
// add function declaration to cl // add function declaration to cl
CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::instance()->workingCopy(); CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::instance()->workingCopy();
declFilePath = declDoc->fileName(); declFilePath = declDoc->filePath().toString();
getParsedDocument(declFilePath, workingCopy, docTable); getParsedDocument(declFilePath, workingCopy, docTable);
addDeclaration(docTable, declFilePath, cl, functionNameWithParameterNames); addDeclaration(docTable, declFilePath, cl, functionNameWithParameterNames);

View File

@@ -46,7 +46,7 @@ void CppTodoItemsScanner::scannerParamsChanged()
void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc) void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc)
{ {
CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance(); CppEditor::CppModelManager *modelManager = CppEditor::CppModelManager::instance();
if (!modelManager->projectPart(doc->fileName()).isEmpty()) if (!modelManager->projectPart(doc->filePath()).isEmpty())
processDocument(doc); processDocument(doc);
} }
@@ -84,13 +84,13 @@ void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc)
const int length = end - start + 1; const int length = end - start + 1;
if (length > 0) { if (length > 0) {
QString commentLine = QString::fromUtf8(start, length); QString commentLine = QString::fromUtf8(start, length);
processCommentLine(doc->fileName(), commentLine, lineNumber, itemList); processCommentLine(doc->filePath().toString(), commentLine, lineNumber, itemList);
} }
from = to + 1; from = to + 1;
} }
} }
emit itemsFetched(doc->fileName(), itemList); emit itemsFetched(doc->filePath().toString(), itemList);
} }
} }

View File

@@ -1,4 +1,4 @@
add_qtc_test(tst_cplusplus_checksymbols add_qtc_test(tst_cplusplus_checksymbols
DEPENDS CppEditor ProjectExplorer TextEditor DEPENDS CppEditor ProjectExplorer TextEditor Utils
SOURCES tst_checksymbols.cpp SOURCES tst_checksymbols.cpp
) )

View File

@@ -9,8 +9,11 @@
#include <cppeditor/cppchecksymbols.h> #include <cppeditor/cppchecksymbols.h>
#include <cppeditor/cppsemanticinfo.h> #include <cppeditor/cppsemanticinfo.h>
#include <cppeditor/cpptoolstestcase.h> #include <cppeditor/cpptoolstestcase.h>
#include <texteditor/semantichighlighter.h> #include <texteditor/semantichighlighter.h>
#include <utils/filepath.h>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QList> #include <QList>
@@ -26,6 +29,7 @@ enum { enableListing = 0 };
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CppEditor; using namespace CppEditor;
using namespace Utils;
typedef QByteArray _; typedef QByteArray _;
typedef CheckSymbols::Result Use; typedef CheckSymbols::Result Use;
@@ -89,7 +93,7 @@ public:
{ {
// Write source to temporary file // Write source to temporary file
const QString filePath = QDir::tempPath() + QLatin1String("/file.h"); const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
Tests::TestCase::writeFile(filePath, source); Tests::TestCase::writeFile(FilePath::fromString(filePath), source);
// Process source // Process source
const Document::Ptr document = createDocument(filePath, source); const Document::Ptr document = createDocument(filePath, source);
@@ -112,7 +116,7 @@ public:
static Document::Ptr createDocument(const QString &filePath, const QByteArray &source) static Document::Ptr createDocument(const QString &filePath, const QByteArray &source)
{ {
Environment env; CPlusPlus::Environment env;
Preprocessor preprocess(0, &env); Preprocessor preprocess(0, &env);
preprocess.setKeepComments(true); preprocess.setKeepComments(true);
const QByteArray preprocessedSource = preprocess.run(filePath, source); const QByteArray preprocessedSource = preprocess.run(filePath, source);
@@ -1142,10 +1146,10 @@ void tst_CheckSymbols::test_checksymbols_infiniteLoop()
QFETCH(QByteArray, source2); QFETCH(QByteArray, source2);
const QString filePath1 = QDir::tempPath() + QLatin1String("/file1.h"); const QString filePath1 = QDir::tempPath() + QLatin1String("/file1.h");
Tests::TestCase::writeFile(filePath1, source1); Tests::TestCase::writeFile(FilePath::fromString(filePath1), source1);
const QString filePath2 = QDir::tempPath() + QLatin1String("/file2.h"); const QString filePath2 = QDir::tempPath() + QLatin1String("/file2.h");
Tests::TestCase::writeFile(filePath2, source2); Tests::TestCase::writeFile(FilePath::fromString(filePath2), source2);
const Document::Ptr document1 = TestCase::createDocument(filePath1, source1); const Document::Ptr document1 = TestCase::createDocument(filePath1, source1);
document1->addIncludeFile(Document::Include("file2.h", filePath2, 1, Client::IncludeLocal)); document1->addIncludeFile(Document::Include("file2.h", filePath2, 1, Client::IncludeLocal));

View File

@@ -9,6 +9,8 @@
#include <cplusplus/TranslationUnit.h> #include <cplusplus/TranslationUnit.h>
#include <cplusplus/pp-engine.h> #include <cplusplus/pp-engine.h>
#include <utils/filepath.h>
#include <QtTest> #include <QtTest>
#include <QDebug> #include <QDebug>