forked from qt-creator/qt-creator
CppEditor: More migration to FilePath
Change-Id: I261b713671e00bb567f61b4ee5ecf6fa83473bff Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
18
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
18
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
@@ -34,7 +34,9 @@
|
|||||||
|
|
||||||
#include <utils/link.h>
|
#include <utils/link.h>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace CPlusPlus {
|
||||||
|
|
||||||
class Symbol::HashCode: protected NameVisitor
|
class Symbol::HashCode: protected NameVisitor
|
||||||
{
|
{
|
||||||
@@ -166,6 +168,12 @@ const char *Symbol::fileName() const
|
|||||||
int Symbol::fileNameLength() const
|
int Symbol::fileNameLength() const
|
||||||
{ return _fileId ? _fileId->size() : 0; }
|
{ return _fileId ? _fileId->size() : 0; }
|
||||||
|
|
||||||
|
Utils::FilePath Symbol::filePath() const
|
||||||
|
{
|
||||||
|
return _fileId ? Utils::FilePath::fromUtf8(_fileId->chars(), _fileId->size())
|
||||||
|
: Utils::FilePath();
|
||||||
|
}
|
||||||
|
|
||||||
const Name *Symbol::unqualifiedName() const
|
const Name *Symbol::unqualifiedName() const
|
||||||
{
|
{
|
||||||
if (! _name)
|
if (! _name)
|
||||||
@@ -280,10 +288,8 @@ void Symbol::copy(Symbol *other)
|
|||||||
_isDeprecated = other->_isDeprecated;
|
_isDeprecated = other->_isDeprecated;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Link Symbol::toLink() const
|
Link Symbol::toLink() const
|
||||||
{
|
{
|
||||||
const QString filename = QString::fromUtf8(fileName(), fileNameLength());
|
|
||||||
|
|
||||||
int line = this->line();
|
int line = this->line();
|
||||||
int column = this->column();
|
int column = this->column();
|
||||||
|
|
||||||
@@ -293,5 +299,7 @@ Utils::Link Symbol::toLink() const
|
|||||||
if (isGenerated())
|
if (isGenerated())
|
||||||
column = 0;
|
column = 0;
|
||||||
|
|
||||||
return Utils::Link(Utils::FilePath::fromString(filename), line, column);
|
return Link(filePath(), line, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // CPlusPlus
|
||||||
|
7
src/libs/3rdparty/cplusplus/Symbol.h
vendored
7
src/libs/3rdparty/cplusplus/Symbol.h
vendored
@@ -22,7 +22,10 @@
|
|||||||
|
|
||||||
#include "CPlusPlusForwardDeclarations.h"
|
#include "CPlusPlusForwardDeclarations.h"
|
||||||
|
|
||||||
namespace Utils { class Link; }
|
namespace Utils {
|
||||||
|
class FilePath;
|
||||||
|
class Link;
|
||||||
|
} // Utils
|
||||||
|
|
||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
|
|
||||||
@@ -78,6 +81,8 @@ public:
|
|||||||
/// Returns this Symbol's file name length.
|
/// Returns this Symbol's file name length.
|
||||||
int fileNameLength() const;
|
int fileNameLength() const;
|
||||||
|
|
||||||
|
Utils::FilePath filePath() const;
|
||||||
|
|
||||||
/// Returns this Symbol's name.
|
/// Returns this Symbol's name.
|
||||||
const Name *name() const { return _name; }
|
const Name *name() const { return _name; }
|
||||||
|
|
||||||
|
@@ -388,8 +388,6 @@ public:
|
|||||||
bool contains(const Utils::FilePath &filePath) const;
|
bool contains(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
Document::Ptr document(const Utils::FilePath &filePath) const;
|
Document::Ptr document(const Utils::FilePath &filePath) const;
|
||||||
Document::Ptr document(const QString &fileName) const
|
|
||||||
{ return document(Utils::FilePath::fromString(fileName)); }
|
|
||||||
|
|
||||||
const_iterator find(const Utils::FilePath &filePath) const;
|
const_iterator find(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
|
@@ -354,8 +354,8 @@ Document::Ptr LookupContext::expressionDocument() const
|
|||||||
Document::Ptr LookupContext::thisDocument() const
|
Document::Ptr LookupContext::thisDocument() const
|
||||||
{ return _thisDocument; }
|
{ return _thisDocument; }
|
||||||
|
|
||||||
Document::Ptr LookupContext::document(const QString &fileName) const
|
Document::Ptr LookupContext::document(const FilePath &filePath) const
|
||||||
{ return _snapshot.document(fileName); }
|
{ return _snapshot.document(filePath); }
|
||||||
|
|
||||||
Snapshot LookupContext::snapshot() const
|
Snapshot LookupContext::snapshot() const
|
||||||
{ return _snapshot; }
|
{ return _snapshot; }
|
||||||
|
@@ -276,7 +276,7 @@ public:
|
|||||||
|
|
||||||
Document::Ptr expressionDocument() const;
|
Document::Ptr expressionDocument() const;
|
||||||
Document::Ptr thisDocument() const;
|
Document::Ptr thisDocument() const;
|
||||||
Document::Ptr document(const QString &fileName) const;
|
Document::Ptr document(const Utils::FilePath &filePath) const;
|
||||||
Snapshot snapshot() const;
|
Snapshot snapshot() const;
|
||||||
|
|
||||||
ClassOrNamespace *globalNamespace() const;
|
ClassOrNamespace *globalNamespace() const;
|
||||||
|
@@ -725,7 +725,7 @@ bool ResolveExpression::visit(SimpleNameAST *ast)
|
|||||||
|
|
||||||
TypeOfExpression exprTyper;
|
TypeOfExpression exprTyper;
|
||||||
exprTyper.setExpandTemplates(true);
|
exprTyper.setExpandTemplates(true);
|
||||||
Document::Ptr doc = _context.snapshot().document(QString::fromLocal8Bit(decl->fileName()));
|
Document::Ptr doc = _context.snapshot().document(decl->filePath());
|
||||||
exprTyper.init(doc, _context.snapshot(), _context.bindings(),
|
exprTyper.init(doc, _context.snapshot(), _context.bindings(),
|
||||||
QSet<const Declaration* >(_autoDeclarationsBeingResolved) << decl);
|
QSet<const Declaration* >(_autoDeclarationsBeingResolved) << decl);
|
||||||
|
|
||||||
|
@@ -168,9 +168,7 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
|
|||||||
for (const CPlusPlus::LookupItem &item : std::as_const(lookupItems)) {
|
for (const CPlusPlus::LookupItem &item : std::as_const(lookupItems)) {
|
||||||
if (CPlusPlus::Symbol *symbol = item.declaration()) {
|
if (CPlusPlus::Symbol *symbol = item.declaration()) {
|
||||||
if (CPlusPlus::Class *toeClass = symbol->asClass()) {
|
if (CPlusPlus::Class *toeClass = symbol->asClass()) {
|
||||||
const QString declFileName = QLatin1String(toeClass->fileId()->chars(),
|
declaringDoc = snapshot.document(toeClass->filePath());
|
||||||
int(toeClass->fileId()->size()));
|
|
||||||
declaringDoc = snapshot.document(declFileName);
|
|
||||||
if (line)
|
if (line)
|
||||||
*line = toeClass->line();
|
*line = toeClass->line();
|
||||||
if (column)
|
if (column)
|
||||||
|
@@ -1436,7 +1436,7 @@ void CppCodeModelInspectorDialog::onDocumentSelected(const QModelIndex ¤t,
|
|||||||
if (current.isValid()) {
|
if (current.isValid()) {
|
||||||
const QModelIndex index = m_proxySnapshotModel->index(current.row(),
|
const QModelIndex index = m_proxySnapshotModel->index(current.row(),
|
||||||
SnapshotModel::FilePathColumn);
|
SnapshotModel::FilePathColumn);
|
||||||
const QString filePath = QDir::fromNativeSeparators(
|
const FilePath filePath = FilePath::fromUserInput(
|
||||||
m_proxySnapshotModel->data(index, Qt::DisplayRole).toString());
|
m_proxySnapshotModel->data(index, Qt::DisplayRole).toString());
|
||||||
const SnapshotInfo info = m_snapshotInfos->at(m_ui->snapshotSelector->currentIndex());
|
const SnapshotInfo info = m_snapshotInfos->at(m_ui->snapshotSelector->currentIndex());
|
||||||
updateDocumentData(info.snapshot.document(filePath));
|
updateDocumentData(info.snapshot.document(filePath));
|
||||||
|
@@ -1040,8 +1040,8 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper()
|
|||||||
|
|
||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
Utils::Text::convertPosition(interface()->textDocument(), startOfExpression, &line, &column);
|
Utils::Text::convertPosition(interface()->textDocument(), startOfExpression, &line, &column);
|
||||||
const QString fileName = interface()->filePath().toString();
|
return startCompletionInternal(interface()->filePath(),
|
||||||
return startCompletionInternal(fileName, line, column - 1, expression, endOfExpression);
|
line, column - 1, expression, endOfExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
||||||
@@ -1268,7 +1268,7 @@ bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const
|
|||||||
|| mt.matchesName(QLatin1String(CppEditor::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
|| mt.matchesName(QLatin1String(CppEditor::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString &fileName,
|
int InternalCppCompletionAssistProcessor::startCompletionInternal(const Utils::FilePath &filePath,
|
||||||
int line,
|
int line,
|
||||||
int positionInBlock,
|
int positionInBlock,
|
||||||
const QString &expr,
|
const QString &expr,
|
||||||
@@ -1276,7 +1276,7 @@ int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString
|
|||||||
{
|
{
|
||||||
QString expression = expr.trimmed();
|
QString expression = expr.trimmed();
|
||||||
|
|
||||||
Document::Ptr thisDocument = cppInterface()->snapshot().document(fileName);
|
Document::Ptr thisDocument = cppInterface()->snapshot().document(filePath);
|
||||||
if (!thisDocument)
|
if (!thisDocument)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@@ -86,7 +86,7 @@ private:
|
|||||||
int startCompletionHelper();
|
int startCompletionHelper();
|
||||||
bool tryObjCCompletion();
|
bool tryObjCCompletion();
|
||||||
bool objcKeywordsWanted() const;
|
bool objcKeywordsWanted() const;
|
||||||
int startCompletionInternal(const QString &fileName,
|
int startCompletionInternal(const Utils::FilePath &filePath,
|
||||||
int line, int positionInBlock,
|
int line, int positionInBlock,
|
||||||
const QString &expression,
|
const QString &expression,
|
||||||
int endOfExpression);
|
int endOfExpression);
|
||||||
|
@@ -123,7 +123,7 @@ QWidget *CppEditorOutline::widget() const
|
|||||||
return m_combo;
|
return m_combo;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<CPlusPlus::Document> getDocument(const QString &filePath)
|
QSharedPointer<CPlusPlus::Document> getDocument(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
|
const CPlusPlus::Snapshot snapshot = CppModelManager::instance()->snapshot();
|
||||||
return snapshot.document(filePath);
|
return snapshot.document(filePath);
|
||||||
|
@@ -74,7 +74,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::FilePath path;
|
FilePath path;
|
||||||
QString fileName;
|
QString fileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
const QString macroName = QString::fromUtf8(macro.name(), macro.name().size());
|
||||||
helpIdCandidates = QStringList(macroName);
|
helpIdCandidates = QStringList(macroName);
|
||||||
helpMark = macroName;
|
helpMark = macroName;
|
||||||
link = Utils::Link(macro.filePath(), macro.line());
|
link = Link(macro.filePath(), macro.line());
|
||||||
tooltip = macro.toStringWithLineBreaks();
|
tooltip = macro.toStringWithLineBreaks();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -325,9 +325,7 @@ static Symbol *followClassDeclaration(Symbol *symbol, const Snapshot &snapshot,
|
|||||||
return symbol;
|
return symbol;
|
||||||
|
|
||||||
if (context) {
|
if (context) {
|
||||||
const QString fileName = QString::fromUtf8(classDeclaration->fileName(),
|
const Document::Ptr declarationDocument = snapshot.document(classDeclaration->filePath());
|
||||||
classDeclaration->fileNameLength());
|
|
||||||
const Document::Ptr declarationDocument = snapshot.document(fileName);
|
|
||||||
if (declarationDocument != context->thisDocument())
|
if (declarationDocument != context->thisDocument())
|
||||||
(*context) = LookupContext(declarationDocument, snapshot);
|
(*context) = LookupContext(declarationDocument, snapshot);
|
||||||
}
|
}
|
||||||
@@ -503,15 +501,15 @@ static QFuture<QSharedPointer<CppElement>> asyncExec(
|
|||||||
class FromExpressionFunctor
|
class FromExpressionFunctor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FromExpressionFunctor(const QString &expression, const QString &fileName)
|
FromExpressionFunctor(const QString &expression, const FilePath &filePath)
|
||||||
: m_expression(expression)
|
: m_expression(expression)
|
||||||
, m_fileName(fileName)
|
, m_filePath(filePath)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator()(const CPlusPlus::Snapshot &snapshot, Document::Ptr &doc, Scope **scope,
|
bool operator()(const CPlusPlus::Snapshot &snapshot, Document::Ptr &doc, Scope **scope,
|
||||||
QString &expression)
|
QString &expression)
|
||||||
{
|
{
|
||||||
doc = snapshot.document(m_fileName);
|
doc = snapshot.document(m_filePath);
|
||||||
if (doc.isNull())
|
if (doc.isNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -523,13 +521,13 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
const QString m_expression;
|
const QString m_expression;
|
||||||
const QString m_fileName;
|
const FilePath m_filePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
QFuture<QSharedPointer<CppElement>> CppElementEvaluator::asyncExecute(const QString &expression,
|
QFuture<QSharedPointer<CppElement>> CppElementEvaluator::asyncExecute(const QString &expression,
|
||||||
const QString &fileName)
|
const FilePath &filePath)
|
||||||
{
|
{
|
||||||
return exec(FromExpressionFunctor(expression, fileName), asyncExec);
|
return exec(FromExpressionFunctor(expression, filePath), asyncExec);
|
||||||
}
|
}
|
||||||
|
|
||||||
class FromGuiFunctor
|
class FromGuiFunctor
|
||||||
@@ -692,10 +690,10 @@ const QString &CppElementEvaluator::diagnosis() const
|
|||||||
return d->m_functor.m_diagnosis;
|
return d->m_functor.m_diagnosis;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Link CppElementEvaluator::linkFromExpression(const QString &expression, const QString &fileName)
|
Utils::Link CppElementEvaluator::linkFromExpression(const QString &expression, const FilePath &filePath)
|
||||||
{
|
{
|
||||||
const Snapshot &snapshot = CppModelManager::instance()->snapshot();
|
const Snapshot &snapshot = CppModelManager::instance()->snapshot();
|
||||||
Document::Ptr doc = snapshot.document(fileName);
|
Document::Ptr doc = snapshot.document(filePath);
|
||||||
if (doc.isNull())
|
if (doc.isNull())
|
||||||
return Utils::Link();
|
return Utils::Link();
|
||||||
Scope *scope = doc->globalNamespace();
|
Scope *scope = doc->globalNamespace();
|
||||||
|
@@ -41,13 +41,13 @@ public:
|
|||||||
void execute();
|
void execute();
|
||||||
static QFuture<QSharedPointer<CppElement>> asyncExecute(TextEditor::TextEditorWidget *editor);
|
static QFuture<QSharedPointer<CppElement>> asyncExecute(TextEditor::TextEditorWidget *editor);
|
||||||
static QFuture<QSharedPointer<CppElement>> asyncExecute(const QString &expression,
|
static QFuture<QSharedPointer<CppElement>> asyncExecute(const QString &expression,
|
||||||
const QString &fileName);
|
const Utils::FilePath &filePath);
|
||||||
bool identifiedCppElement() const;
|
bool identifiedCppElement() const;
|
||||||
const QSharedPointer<CppElement> &cppElement() const;
|
const QSharedPointer<CppElement> &cppElement() const;
|
||||||
bool hasDiagnosis() const;
|
bool hasDiagnosis() const;
|
||||||
const QString &diagnosis() const;
|
const QString &diagnosis() const;
|
||||||
|
|
||||||
static Utils::Link linkFromExpression(const QString &expression, const QString &fileName);
|
static Utils::Link linkFromExpression(const QString &expression, const Utils::FilePath &filePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class CppElementEvaluatorPrivate *d;
|
class CppElementEvaluatorPrivate *d;
|
||||||
|
@@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
|
|
||||||
FileIterationOrder::Entry::Entry(const QString &filePath,
|
FileIterationOrder::Entry::Entry(const FilePath &filePath,
|
||||||
const QString &projectPartId,
|
const QString &projectPartId,
|
||||||
int commonPrefixLength,
|
int commonPrefixLength,
|
||||||
int commonProjectPartPrefixLength)
|
int commonProjectPartPrefixLength)
|
||||||
@@ -66,13 +68,13 @@ bool operator<(const FileIterationOrder::Entry &first, const FileIterationOrder:
|
|||||||
|
|
||||||
FileIterationOrder::FileIterationOrder() = default;
|
FileIterationOrder::FileIterationOrder() = default;
|
||||||
|
|
||||||
FileIterationOrder::FileIterationOrder(const QString &referenceFilePath,
|
FileIterationOrder::FileIterationOrder(const FilePath &referenceFilePath,
|
||||||
const QString &referenceProjectPartId)
|
const QString &referenceProjectPartId)
|
||||||
{
|
{
|
||||||
setReference(referenceFilePath, referenceProjectPartId);
|
setReference(referenceFilePath, referenceProjectPartId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileIterationOrder::setReference(const QString &filePath,
|
void FileIterationOrder::setReference(const FilePath &filePath,
|
||||||
const QString &projectPartId)
|
const QString &projectPartId)
|
||||||
{
|
{
|
||||||
m_referenceFilePath = filePath;
|
m_referenceFilePath = filePath;
|
||||||
@@ -84,7 +86,7 @@ bool FileIterationOrder::isValid() const
|
|||||||
return !m_referenceFilePath.isEmpty();
|
return !m_referenceFilePath.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int commonPrefixLength(const QString &filePath1, const QString &filePath2)
|
static int commonPrefixLength(const QStringView filePath1, const QStringView filePath2)
|
||||||
{
|
{
|
||||||
const auto mismatches = std::mismatch(filePath1.begin(), filePath1.end(),
|
const auto mismatches = std::mismatch(filePath1.begin(), filePath1.end(),
|
||||||
filePath2.begin(), filePath2.end());
|
filePath2.begin(), filePath2.end());
|
||||||
@@ -92,21 +94,21 @@ static int commonPrefixLength(const QString &filePath1, const QString &filePath2
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileIterationOrder::Entry FileIterationOrder::createEntryFromFilePath(
|
FileIterationOrder::Entry FileIterationOrder::createEntryFromFilePath(
|
||||||
const QString &filePath,
|
const FilePath &filePath,
|
||||||
const QString &projectPartId) const
|
const QString &projectPartId) const
|
||||||
{
|
{
|
||||||
const int filePrefixLength = commonPrefixLength(m_referenceFilePath, filePath);
|
const int filePrefixLength = commonPrefixLength(m_referenceFilePath.pathView(), filePath.pathView());
|
||||||
const int projectPartPrefixLength = commonPrefixLength(m_referenceProjectPartId, projectPartId);
|
const int projectPartPrefixLength = commonPrefixLength(m_referenceProjectPartId, projectPartId);
|
||||||
return Entry(filePath, projectPartId, filePrefixLength, projectPartPrefixLength);
|
return Entry(filePath, projectPartId, filePrefixLength, projectPartPrefixLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileIterationOrder::insert(const QString &filePath, const QString &projectPartId)
|
void FileIterationOrder::insert(const FilePath &filePath, const QString &projectPartId)
|
||||||
{
|
{
|
||||||
const Entry entry = createEntryFromFilePath(filePath, projectPartId);
|
const Entry entry = createEntryFromFilePath(filePath, projectPartId);
|
||||||
m_set.insert(entry);
|
m_set.insert(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileIterationOrder::remove(const QString &filePath, const QString &projectPartId)
|
void FileIterationOrder::remove(const FilePath &filePath, const QString &projectPartId)
|
||||||
{
|
{
|
||||||
const auto needleElement = createEntryFromFilePath(filePath, projectPartId);
|
const auto needleElement = createEntryFromFilePath(filePath, projectPartId);
|
||||||
const auto range = m_set.equal_range(needleElement);
|
const auto range = m_set.equal_range(needleElement);
|
||||||
@@ -122,6 +124,16 @@ QStringList FileIterationOrder::toStringList() const
|
|||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
|
for (const auto &entry : m_set)
|
||||||
|
result.append(entry.filePath.toString());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::FilePaths FileIterationOrder::toFilePaths() const
|
||||||
|
{
|
||||||
|
FilePaths result;
|
||||||
|
|
||||||
for (const auto &entry : m_set)
|
for (const auto &entry : m_set)
|
||||||
result.append(entry.filePath);
|
result.append(entry.filePath);
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
@@ -14,36 +14,37 @@ namespace CppEditor {
|
|||||||
class CPPEDITOR_EXPORT FileIterationOrder {
|
class CPPEDITOR_EXPORT FileIterationOrder {
|
||||||
public:
|
public:
|
||||||
struct Entry {
|
struct Entry {
|
||||||
Entry(const QString &filePath,
|
Entry(const Utils::FilePath &filePath,
|
||||||
const QString &projectPartId = QString(),
|
const QString &projectPartId = {},
|
||||||
int commonFilePathPrefixLength = 0,
|
int commonFilePathPrefixLength = 0,
|
||||||
int commonProjectPartPrefixLength = 0);
|
int commonProjectPartPrefixLength = 0);
|
||||||
|
|
||||||
friend CPPEDITOR_EXPORT bool operator<(const Entry &first, const Entry &second);
|
friend CPPEDITOR_EXPORT bool operator<(const Entry &first, const Entry &second);
|
||||||
|
|
||||||
const QString filePath;
|
const Utils::FilePath filePath;
|
||||||
const QString projectPartId;
|
const QString projectPartId;
|
||||||
int commonFilePathPrefixLength = 0;
|
int commonFilePathPrefixLength = 0;
|
||||||
int commonProjectPartPrefixLength = 0;
|
int commonProjectPartPrefixLength = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
FileIterationOrder();
|
FileIterationOrder();
|
||||||
FileIterationOrder(const QString &referenceFilePath,
|
FileIterationOrder(const Utils::FilePath &referenceFilePath,
|
||||||
const QString &referenceProjectPartId);
|
const QString &referenceProjectPartId);
|
||||||
|
|
||||||
void setReference(const QString &filePath, const QString &projectPartId);
|
void setReference(const Utils::FilePath &filePath, const QString &projectPartId);
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
void insert(const QString &filePath, const QString &projectPartId = QString());
|
void insert(const Utils::FilePath &filePath, const QString &projectPartId = QString());
|
||||||
void remove(const QString &filePath, const QString &projectPartId);
|
void remove(const Utils::FilePath &filePath, const QString &projectPartId);
|
||||||
QStringList toStringList() const;
|
QStringList toStringList() const;
|
||||||
|
Utils::FilePaths toFilePaths() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Entry createEntryFromFilePath(const QString &filePath,
|
Entry createEntryFromFilePath(const Utils::FilePath &filePath,
|
||||||
const QString &projectPartId) const;
|
const QString &projectPartId) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_referenceFilePath;
|
Utils::FilePath m_referenceFilePath;
|
||||||
QString m_referenceProjectPartId;
|
QString m_referenceProjectPartId;
|
||||||
std::multiset<Entry> m_set;
|
std::multiset<Entry> m_set;
|
||||||
};
|
};
|
||||||
|
@@ -393,7 +393,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
|||||||
std::bind(&CppFindReferences::searchAgain, this, search));
|
std::bind(&CppFindReferences::searchAgain, this, search));
|
||||||
CppFindReferencesParameters parameters;
|
CppFindReferencesParameters parameters;
|
||||||
parameters.symbolId = fullIdForSymbol(symbol);
|
parameters.symbolId = fullIdForSymbol(symbol);
|
||||||
parameters.symbolFileName = QByteArray(symbol->fileName());
|
parameters.symbolFilePath = symbol->filePath();
|
||||||
parameters.categorize = codeModelSettings()->categorizeFindReferences();
|
parameters.categorize = codeModelSettings()->categorizeFindReferences();
|
||||||
|
|
||||||
if (symbol->asClass() || symbol->asForwardClassDeclaration()) {
|
if (symbol->asClass() || symbol->asForwardClassDeclaration()) {
|
||||||
@@ -535,11 +535,10 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete
|
|||||||
CPlusPlus::LookupContext *context)
|
CPlusPlus::LookupContext *context)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(context, return nullptr);
|
QTC_ASSERT(context, return nullptr);
|
||||||
QString symbolFile = QLatin1String(parameters.symbolFileName);
|
if (!snapshot.contains(parameters.symbolFilePath))
|
||||||
if (!snapshot.contains(FilePath::fromString(symbolFile)))
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
|
CPlusPlus::Document::Ptr newSymbolDocument = snapshot.document(parameters.symbolFilePath);
|
||||||
// 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(newSymbolDocument->filePath(), m_modelManager->workingCopy());
|
QByteArray source = getSource(newSymbolDocument->filePath(), m_modelManager->workingCopy());
|
||||||
CPlusPlus::Document::Ptr doc =
|
CPlusPlus::Document::Ptr doc =
|
||||||
|
@@ -46,7 +46,7 @@ class CppFindReferencesParameters
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QList<QByteArray> symbolId;
|
QList<QByteArray> symbolId;
|
||||||
QByteArray symbolFileName;
|
Utils::FilePath symbolFilePath;
|
||||||
QString prettySymbolName;
|
QString prettySymbolName;
|
||||||
Utils::FilePaths filesToRename;
|
Utils::FilePaths filesToRename;
|
||||||
bool categorize = false;
|
bool categorize = false;
|
||||||
|
@@ -1372,7 +1372,7 @@ public:
|
|||||||
|
|
||||||
QList<Document::Ptr> documentsToCheck;
|
QList<Document::Ptr> documentsToCheck;
|
||||||
for (const QString &file : commonSourceFiles) {
|
for (const QString &file : commonSourceFiles) {
|
||||||
if (Document::Ptr document = snapshot.document(file))
|
if (Document::Ptr document = snapshot.document(FilePath::fromString(file)))
|
||||||
documentsToCheck << document;
|
documentsToCheck << document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -456,7 +456,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
|||||||
QFETCH(QStringList, finalProjectFiles);
|
QFETCH(QStringList, finalProjectFiles);
|
||||||
|
|
||||||
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path());
|
TemporaryCopiedDir temporaryDir(MyTestDataDir(QLatin1String("testdata_refresh2")).path());
|
||||||
fileToChange = temporaryDir.absolutePath(fileToChange.toUtf8());
|
const FilePath filePath = FilePath::fromString(temporaryDir.absolutePath(fileToChange.toUtf8()));
|
||||||
const FilePaths initialProjectFilePaths = toAbsolutePaths(initialProjectFiles, temporaryDir);
|
const FilePaths initialProjectFilePaths = toAbsolutePaths(initialProjectFiles, temporaryDir);
|
||||||
const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir);
|
const FilePaths finalProjectFilePaths = toAbsolutePaths(finalProjectFiles, temporaryDir);
|
||||||
|
|
||||||
@@ -486,14 +486,14 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
|||||||
QVERIFY(snapshot.contains(file));
|
QVERIFY(snapshot.contains(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
document = snapshot.document(fileToChange);
|
document = snapshot.document(filePath);
|
||||||
const QDateTime lastModifiedBefore = document->lastModified();
|
const QDateTime lastModifiedBefore = document->lastModified();
|
||||||
QCOMPARE(document->globalSymbolCount(), 1);
|
QCOMPARE(document->globalSymbolCount(), 1);
|
||||||
QCOMPARE(document->globalSymbolAt(0)->name()->identifier()->chars(), "someGlobal");
|
QCOMPARE(document->globalSymbolAt(0)->name()->identifier()->chars(), "someGlobal");
|
||||||
|
|
||||||
// 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(FilePath::fromString(fileToChange));
|
FileChangerAndRestorer fileChangerAndRestorer(filePath);
|
||||||
QByteArray originalContents;
|
QByteArray originalContents;
|
||||||
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
|
QVERIFY(fileChangerAndRestorer.readContents(&originalContents));
|
||||||
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
|
const QByteArray newFileContentes = originalContents + "\nint addedOtherGlobal;";
|
||||||
@@ -514,7 +514,7 @@ void ModelManagerTest::testRefreshTimeStampModifiedIfSourcefilesChange()
|
|||||||
QVERIFY(refreshedFiles.contains(file));
|
QVERIFY(refreshedFiles.contains(file));
|
||||||
QVERIFY(snapshot.contains(file));
|
QVERIFY(snapshot.contains(file));
|
||||||
}
|
}
|
||||||
document = snapshot.document(fileToChange);
|
document = snapshot.document(filePath);
|
||||||
const QDateTime lastModifiedAfter = document->lastModified();
|
const QDateTime lastModifiedAfter = document->lastModified();
|
||||||
QVERIFY(lastModifiedAfter > lastModifiedBefore);
|
QVERIFY(lastModifiedAfter > lastModifiedBefore);
|
||||||
QCOMPARE(document->globalSymbolCount(), 2);
|
QCOMPARE(document->globalSymbolCount(), 2);
|
||||||
@@ -618,7 +618,8 @@ void ModelManagerTest::testExtraeditorsupportUiFiles()
|
|||||||
|
|
||||||
// Check CppSourceProcessor / includes.
|
// Check CppSourceProcessor / includes.
|
||||||
// The CppSourceProcessor is expected to find the ui_* file in the working copy.
|
// The CppSourceProcessor is expected to find the ui_* file in the working copy.
|
||||||
const QString fileIncludingTheUiFile = temporaryDir.absolutePath("mainwindow.cpp");
|
const FilePath fileIncludingTheUiFile =
|
||||||
|
FilePath::fromString(temporaryDir.absolutePath("mainwindow.cpp"));
|
||||||
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
while (!mm->snapshot().document(fileIncludingTheUiFile))
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPo
|
|||||||
: RefactoringFile(filePath, data)
|
: RefactoringFile(filePath, data)
|
||||||
{
|
{
|
||||||
const Snapshot &snapshot = this->data()->m_snapshot;
|
const Snapshot &snapshot = this->data()->m_snapshot;
|
||||||
m_cppDocument = snapshot.document(filePath.toString());
|
m_cppDocument = snapshot.document(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const FilePath &filePath)
|
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const FilePath &filePath)
|
||||||
|
@@ -185,7 +185,7 @@ void CppTypeHierarchyWidget::perform()
|
|||||||
Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy");
|
Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const QString &fileName)
|
void CppTypeHierarchyWidget::performFromExpression(const QString &expression, const FilePath &filePath)
|
||||||
{
|
{
|
||||||
if (m_future.isRunning())
|
if (m_future.isRunning())
|
||||||
m_future.cancel();
|
m_future.cancel();
|
||||||
@@ -194,7 +194,7 @@ void CppTypeHierarchyWidget::performFromExpression(const QString &expression, co
|
|||||||
|
|
||||||
showProgress();
|
showProgress();
|
||||||
|
|
||||||
m_future = CppElementEvaluator::asyncExecute(expression, fileName);
|
m_future = CppElementEvaluator::asyncExecute(expression, filePath);
|
||||||
m_futureWatcher.setFuture(QFuture<void>(m_future));
|
m_futureWatcher.setFuture(QFuture<void>(m_future));
|
||||||
m_synchronizer.addFuture(m_future);
|
m_synchronizer.addFuture(m_future);
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ void CppTypeHierarchyWidget::onItemActivated(const QModelIndex &index)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const Link updatedLink = CppElementEvaluator::linkFromExpression(
|
const Link updatedLink = CppElementEvaluator::linkFromExpression(
|
||||||
getExpression(index), link.targetFilePath.toString());
|
getExpression(index), link.targetFilePath);
|
||||||
if (updatedLink.hasValidTarget())
|
if (updatedLink.hasValidTarget())
|
||||||
link = updatedLink;
|
link = updatedLink;
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
const auto link = index.data(LinkRole).value<Link>();
|
const auto link = index.data(LinkRole).value<Link>();
|
||||||
if (link.hasValidTarget())
|
if (link.hasValidTarget())
|
||||||
performFromExpression(getExpression(index), link.targetFilePath.toString());
|
performFromExpression(getExpression(index), link.targetFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CppTypeHierarchyFactory
|
// CppTypeHierarchyFactory
|
||||||
|
@@ -62,7 +62,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
typedef QList<CppClass> CppClass::*HierarchyMember;
|
typedef QList<CppClass> CppClass::*HierarchyMember;
|
||||||
void performFromExpression(const QString &expression, const QString &fileName);
|
void performFromExpression(const QString &expression, const Utils::FilePath &filePath);
|
||||||
QStandardItem *buildHierarchy(const CppClass &cppClass, QStandardItem *parent,
|
QStandardItem *buildHierarchy(const CppClass &cppClass, QStandardItem *parent,
|
||||||
bool isRoot, HierarchyMember member);
|
bool isRoot, HierarchyMember member);
|
||||||
void showNoTypeHierarchyLabel();
|
void showNoTypeHierarchyLabel();
|
||||||
|
@@ -593,15 +593,14 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
|
|||||||
|
|
||||||
int line, column;
|
int line, column;
|
||||||
if (suffix.isEmpty()) {
|
if (suffix.isEmpty()) {
|
||||||
Document::Ptr targetDoc = changes.snapshot().document(QString::fromUtf8(definitionFunction->fileName()));
|
Document::Ptr targetDoc = changes.snapshot().document(definitionFunction->filePath());
|
||||||
if (!targetDoc)
|
if (!targetDoc)
|
||||||
return noResult;
|
return noResult;
|
||||||
|
|
||||||
targetDoc->translationUnit()->getPosition(definitionFunction->endOffset(), &line, &column);
|
targetDoc->translationUnit()->getPosition(definitionFunction->endOffset(), &line, &column);
|
||||||
} else {
|
} else {
|
||||||
// we don't have an offset to the start of the function definition, so we need to manually find it...
|
// we don't have an offset to the start of the function definition, so we need to manually find it...
|
||||||
CppRefactoringFilePtr targetFile = changes.file(
|
CppRefactoringFilePtr targetFile = changes.file(definitionFunction->filePath());
|
||||||
Utils::FilePath::fromString(QString::fromUtf8(definitionFunction->fileName())));
|
|
||||||
if (!targetFile->isValid())
|
if (!targetFile->isValid())
|
||||||
return noResult;
|
return noResult;
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -134,7 +135,7 @@ Function *SymbolFinder::findMatchingDefinition(Symbol *declaration,
|
|||||||
if (!declaration)
|
if (!declaration)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength());
|
const FilePath declFile = declaration->filePath();
|
||||||
|
|
||||||
Document::Ptr thisDocument = snapshot.document(declFile);
|
Document::Ptr thisDocument = snapshot.document(declFile);
|
||||||
if (!thisDocument) {
|
if (!thisDocument) {
|
||||||
@@ -150,11 +151,11 @@ Function *SymbolFinder::findMatchingDefinition(Symbol *declaration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Hit best;
|
Hit best;
|
||||||
const QStringList fileNames = fileIterationOrder(declFile, snapshot);
|
const FilePaths filePaths = fileIterationOrder(declFile, snapshot);
|
||||||
for (const QString &fileName : fileNames) {
|
for (const FilePath &filePath : filePaths) {
|
||||||
Document::Ptr doc = snapshot.document(fileName);
|
Document::Ptr doc = snapshot.document(filePath);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
clearCache(declFile, fileName);
|
clearCache(declFile, filePath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +221,7 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength());
|
const FilePath declFile = declaration->filePath();
|
||||||
const Document::Ptr thisDocument = snapshot.document(declFile);
|
const Document::Ptr thisDocument = snapshot.document(declFile);
|
||||||
if (!thisDocument) {
|
if (!thisDocument) {
|
||||||
qWarning() << "undefined document:" << declaration->fileName();
|
qWarning() << "undefined document:" << declaration->fileName();
|
||||||
@@ -230,11 +231,11 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps
|
|||||||
using SymbolWithPriority = QPair<Symbol *, bool>;
|
using SymbolWithPriority = QPair<Symbol *, bool>;
|
||||||
QList<SymbolWithPriority> candidates;
|
QList<SymbolWithPriority> candidates;
|
||||||
QList<SymbolWithPriority> fallbacks;
|
QList<SymbolWithPriority> fallbacks;
|
||||||
const QStringList fileNames = fileIterationOrder(declFile, snapshot);
|
const FilePaths filePaths = fileIterationOrder(declFile, snapshot);
|
||||||
for (const QString &fileName : fileNames) {
|
for (const FilePath &filePath : filePaths) {
|
||||||
Document::Ptr doc = snapshot.document(fileName);
|
Document::Ptr doc = snapshot.document(filePath);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
clearCache(declFile, fileName);
|
clearCache(declFile, filePath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +272,7 @@ Symbol *SymbolFinder::findMatchingVarDefinition(Symbol *declaration, const Snaps
|
|||||||
for (const auto &candidate : std::as_const(candidates)) {
|
for (const auto &candidate : std::as_const(candidates)) {
|
||||||
if (candidate.first == declaration)
|
if (candidate.first == declaration)
|
||||||
continue;
|
continue;
|
||||||
if (QLatin1String(candidate.first->fileName()) == declFile
|
if (candidate.first->filePath() == declFile
|
||||||
&& candidate.first->sourceLocation() == declaration->sourceLocation())
|
&& candidate.first->sourceLocation() == declaration->sourceLocation())
|
||||||
continue;
|
continue;
|
||||||
if (!candidate.first->asDeclaration())
|
if (!candidate.first->asDeclaration())
|
||||||
@@ -298,10 +299,10 @@ Class *SymbolFinder::findMatchingClassDeclaration(Symbol *declaration, const Sna
|
|||||||
if (!declaration->identifier())
|
if (!declaration->identifier())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
QString declFile = QString::fromUtf8(declaration->fileName(), declaration->fileNameLength());
|
const FilePath declFile = declaration->filePath();
|
||||||
|
|
||||||
const QStringList fileNames = fileIterationOrder(declFile, snapshot);
|
const FilePaths filePaths = fileIterationOrder(declFile, snapshot);
|
||||||
for (const QString &file : fileNames) {
|
for (const FilePath &file : filePaths) {
|
||||||
Document::Ptr doc = snapshot.document(file);
|
Document::Ptr doc = snapshot.document(file);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
clearCache(declFile, file);
|
clearCache(declFile, file);
|
||||||
@@ -438,16 +439,16 @@ QList<Declaration *> SymbolFinder::findMatchingDeclaration(const LookupContext &
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SymbolFinder::fileIterationOrder(const QString &referenceFile, const Snapshot &snapshot)
|
FilePaths SymbolFinder::fileIterationOrder(const FilePath &referenceFile, const Snapshot &snapshot)
|
||||||
{
|
{
|
||||||
if (m_filePriorityCache.contains(referenceFile)) {
|
if (m_filePriorityCache.contains(referenceFile)) {
|
||||||
checkCacheConsistency(referenceFile, snapshot);
|
checkCacheConsistency(referenceFile, snapshot);
|
||||||
} else {
|
} else {
|
||||||
for (Document::Ptr doc : snapshot)
|
for (Document::Ptr doc : snapshot)
|
||||||
insertCache(referenceFile, doc->filePath().path());
|
insertCache(referenceFile, doc->filePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList files = m_filePriorityCache.value(referenceFile).toStringList();
|
FilePaths files = m_filePriorityCache.value(referenceFile).toFilePaths();
|
||||||
|
|
||||||
trackCacheUse(referenceFile);
|
trackCacheUse(referenceFile);
|
||||||
|
|
||||||
@@ -461,19 +462,19 @@ void SymbolFinder::clearCache()
|
|||||||
m_recent.clear();
|
m_recent.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolFinder::checkCacheConsistency(const QString &referenceFile, const Snapshot &snapshot)
|
void SymbolFinder::checkCacheConsistency(const FilePath &referenceFile, const Snapshot &snapshot)
|
||||||
{
|
{
|
||||||
// We only check for "new" files, which which are in the snapshot but not in the cache.
|
// We only check for "new" files, which which are in the snapshot but not in the cache.
|
||||||
// The counterpart validation for "old" files is done when one tries to access the
|
// The counterpart validation for "old" files is done when one tries to access the
|
||||||
// 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<FilePath> &meta = m_fileMetaCache.value(referenceFile);
|
||||||
for (const Document::Ptr &doc : snapshot) {
|
for (const Document::Ptr &doc : snapshot) {
|
||||||
if (!meta.contains(doc->filePath().path()))
|
if (!meta.contains(doc->filePath()))
|
||||||
insertCache(referenceFile, doc->filePath().path());
|
insertCache(referenceFile, doc->filePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString projectPartIdForFile(const QString &filePath)
|
const QString projectPartIdForFile(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
const QList<ProjectPart::ConstPtr> parts = CppModelManager::instance()->projectPart(filePath);
|
const QList<ProjectPart::ConstPtr> parts = CppModelManager::instance()->projectPart(filePath);
|
||||||
if (!parts.isEmpty())
|
if (!parts.isEmpty())
|
||||||
@@ -481,13 +482,13 @@ const QString projectPartIdForFile(const QString &filePath)
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolFinder::clearCache(const QString &referenceFile, const QString &comparingFile)
|
void SymbolFinder::clearCache(const FilePath &referenceFile, const FilePath &comparingFile)
|
||||||
{
|
{
|
||||||
m_filePriorityCache[referenceFile].remove(comparingFile, projectPartIdForFile(comparingFile));
|
m_filePriorityCache[referenceFile].remove(comparingFile, projectPartIdForFile(comparingFile));
|
||||||
m_fileMetaCache[referenceFile].remove(comparingFile);
|
m_fileMetaCache[referenceFile].remove(comparingFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolFinder::insertCache(const QString &referenceFile, const QString &comparingFile)
|
void SymbolFinder::insertCache(const FilePath &referenceFile, const FilePath &comparingFile)
|
||||||
{
|
{
|
||||||
FileIterationOrder &order = m_filePriorityCache[referenceFile];
|
FileIterationOrder &order = m_filePriorityCache[referenceFile];
|
||||||
if (!order.isValid()) {
|
if (!order.isValid()) {
|
||||||
@@ -499,7 +500,7 @@ void SymbolFinder::insertCache(const QString &referenceFile, const QString &comp
|
|||||||
m_fileMetaCache[referenceFile].insert(comparingFile);
|
m_fileMetaCache[referenceFile].insert(comparingFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SymbolFinder::trackCacheUse(const QString &referenceFile)
|
void SymbolFinder::trackCacheUse(const FilePath &referenceFile)
|
||||||
{
|
{
|
||||||
if (!m_recent.isEmpty()) {
|
if (!m_recent.isEmpty()) {
|
||||||
if (m_recent.last() == referenceFile)
|
if (m_recent.last() == referenceFile)
|
||||||
@@ -511,7 +512,7 @@ void SymbolFinder::trackCacheUse(const QString &referenceFile)
|
|||||||
|
|
||||||
// We don't want this to grow too much.
|
// We don't want this to grow too much.
|
||||||
if (m_recent.size() > kMaxCacheSize) {
|
if (m_recent.size() > kMaxCacheSize) {
|
||||||
const QString &oldest = m_recent.takeFirst();
|
const FilePath &oldest = m_recent.takeFirst();
|
||||||
m_filePriorityCache.remove(oldest);
|
m_filePriorityCache.remove(oldest);
|
||||||
m_fileMetaCache.remove(oldest);
|
m_fileMetaCache.remove(oldest);
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "cppfileiterationorder.h"
|
#include "cppfileiterationorder.h"
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@@ -51,17 +53,17 @@ public:
|
|||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList fileIterationOrder(const QString &referenceFile,
|
Utils::FilePaths fileIterationOrder(const Utils::FilePath &referenceFile,
|
||||||
const CPlusPlus::Snapshot &snapshot);
|
const CPlusPlus::Snapshot &snapshot);
|
||||||
void checkCacheConsistency(const QString &referenceFile, const CPlusPlus::Snapshot &snapshot);
|
void checkCacheConsistency(const Utils::FilePath &referenceFile, const CPlusPlus::Snapshot &snapshot);
|
||||||
void clearCache(const QString &referenceFile, const QString &comparingFile);
|
void clearCache(const Utils::FilePath &referenceFile, const Utils::FilePath &comparingFile);
|
||||||
void insertCache(const QString &referenceFile, const QString &comparingFile);
|
void insertCache(const Utils::FilePath &referenceFile, const Utils::FilePath &comparingFile);
|
||||||
|
|
||||||
void trackCacheUse(const QString &referenceFile);
|
void trackCacheUse(const Utils::FilePath &referenceFile);
|
||||||
|
|
||||||
QHash<QString, FileIterationOrder> m_filePriorityCache;
|
QHash<Utils::FilePath, FileIterationOrder> m_filePriorityCache;
|
||||||
QHash<QString, QSet<QString> > m_fileMetaCache;
|
QHash<Utils::FilePath, QSet<Utils::FilePath> > m_fileMetaCache;
|
||||||
QStringList m_recent;
|
Utils::FilePaths m_recent;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -611,7 +611,7 @@ public:
|
|||||||
//: Message tracepoint: %1 file, %2 line %3 function hit.
|
//: Message tracepoint: %1 file, %2 line %3 function hit.
|
||||||
message = Tr::tr("%1:%2 %3() hit").arg(data.fileName.fileName()).
|
message = Tr::tr("%1:%2 %3() hit").arg(data.fileName.fileName()).
|
||||||
arg(data.lineNumber).
|
arg(data.lineNumber).
|
||||||
arg(cppFunctionAt(data.fileName.toString(), data.lineNumber));
|
arg(cppFunctionAt(data.fileName, data.lineNumber));
|
||||||
}
|
}
|
||||||
QInputDialog dialog; // Create wide input dialog.
|
QInputDialog dialog; // Create wide input dialog.
|
||||||
dialog.setWindowFlags(dialog.windowFlags() & ~(Qt::MSWindowsFixedSizeDialogHint));
|
dialog.setWindowFlags(dialog.windowFlags() & ~(Qt::MSWindowsFixedSizeDialogHint));
|
||||||
@@ -1917,7 +1917,7 @@ void DebuggerPluginPrivate::requestContextMenu(TextEditorWidget *widget,
|
|||||||
// Disassemble current function in stopped state.
|
// Disassemble current function in stopped state.
|
||||||
if (engine->hasCapability(DisassemblerCapability)) {
|
if (engine->hasCapability(DisassemblerCapability)) {
|
||||||
StackFrame frame;
|
StackFrame frame;
|
||||||
frame.function = cppFunctionAt(args.fileName.toString(), lineNumber, 1);
|
frame.function = cppFunctionAt(args.fileName, lineNumber, 1);
|
||||||
frame.line = 42; // trick gdb into mixed mode.
|
frame.line = 42; // trick gdb into mixed mode.
|
||||||
if (!frame.function.isEmpty()) {
|
if (!frame.function.isEmpty()) {
|
||||||
const QString text = Tr::tr("Disassemble Function \"%1\"")
|
const QString text = Tr::tr("Disassemble Function \"%1\"")
|
||||||
|
@@ -220,10 +220,10 @@ QStringList getUninitializedVariables(const Snapshot &snapshot,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString cppFunctionAt(const QString &fileName, int line, int column)
|
QString cppFunctionAt(const FilePath &filePath, int line, int column)
|
||||||
{
|
{
|
||||||
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
||||||
if (const Document::Ptr document = snapshot.document(fileName))
|
if (const Document::Ptr document = snapshot.document(filePath))
|
||||||
return document->functionAt(line, column);
|
return document->functionAt(line, column);
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
@@ -238,9 +238,9 @@ QString cppExpressionAt(TextEditorWidget *editorWidget, int pos,
|
|||||||
if (function)
|
if (function)
|
||||||
function->clear();
|
function->clear();
|
||||||
|
|
||||||
const QString fileName = editorWidget->textDocument()->filePath().toString();
|
const FilePath filePath = editorWidget->textDocument()->filePath();
|
||||||
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
||||||
const Document::Ptr document = snapshot.document(fileName);
|
const Document::Ptr document = snapshot.document(filePath);
|
||||||
QTextCursor tc = editorWidget->textCursor();
|
QTextCursor tc = editorWidget->textCursor();
|
||||||
QString expr;
|
QString expr;
|
||||||
if (tc.hasSelection() && pos >= tc.selectionStart() && pos <= tc.selectionEnd()) {
|
if (tc.hasSelection() && pos >= tc.selectionStart() && pos <= tc.selectionEnd()) {
|
||||||
@@ -374,7 +374,7 @@ static void setValueAnnotationsHelper(BaseTextEditor *textEditor,
|
|||||||
TextDocument *textDocument = widget->textDocument();
|
TextDocument *textDocument = widget->textDocument();
|
||||||
const FilePath filePath = loc.fileName();
|
const FilePath filePath = loc.fileName();
|
||||||
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
const Snapshot snapshot = CppModelManager::instance()->snapshot();
|
||||||
const Document::Ptr cppDocument = snapshot.document(filePath.toString());
|
const Document::Ptr cppDocument = snapshot.document(filePath);
|
||||||
if (!cppDocument) // For non-C++ documents.
|
if (!cppDocument) // For non-C++ documents.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ QString cppExpressionAt(TextEditor::TextEditorWidget *editorWidget, int pos,
|
|||||||
int *line, int *column, QString *function = nullptr,
|
int *line, int *column, QString *function = nullptr,
|
||||||
int *scopeFromLine = nullptr, int *scopeToLine = nullptr);
|
int *scopeFromLine = nullptr, int *scopeToLine = nullptr);
|
||||||
QString fixCppExpression(const QString &exp);
|
QString fixCppExpression(const QString &exp);
|
||||||
QString cppFunctionAt(const QString &fileName, int line, int column = 0);
|
QString cppFunctionAt(const Utils::FilePath &filePath, int line, int column = 0);
|
||||||
|
|
||||||
// Get variables that are not initialized at a certain line
|
// Get variables that are not initialized at a certain line
|
||||||
// of a function from the code model. Shadowed variables will
|
// of a function from the code model. Shadowed variables will
|
||||||
|
@@ -24,7 +24,7 @@ QSet<QString> ClassViewController::findClassDeclarations(const QString &fileName
|
|||||||
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
|
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
|
||||||
|
|
||||||
// scan original file
|
// scan original file
|
||||||
CPlusPlus::Document::Ptr document = snapshot.document(fileName);
|
CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(fileName));
|
||||||
if (!document.isNull())
|
if (!document.isNull())
|
||||||
appendClassDeclarationsFromDocument(document, line, column, &classNames);
|
appendClassDeclarationsFromDocument(document, line, column, &classNames);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ QSet<QString> ClassViewController::findClassDeclarations(const QString &fileName
|
|||||||
QString otherFileName = CppEditor::correspondingHeaderOrSource(fileName);
|
QString otherFileName = CppEditor::correspondingHeaderOrSource(fileName);
|
||||||
|
|
||||||
// scan other file
|
// scan other file
|
||||||
document = snapshot.document(otherFileName);
|
document = snapshot.document(Utils::FilePath::fromString(otherFileName));
|
||||||
if (!document.isNull())
|
if (!document.isNull())
|
||||||
appendClassDeclarationsFromDocument(document, -1, -1, &classNames);
|
appendClassDeclarationsFromDocument(document, -1, -1, &classNames);
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@
|
|||||||
// TODO implement removing include dependencies that are not longer used
|
// TODO implement removing include dependencies that are not longer used
|
||||||
// TODO refactor add/remove relations between ancestor packages into extra controller class
|
// TODO refactor add/remove relations between ancestor packages into extra controller class
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ModelEditor {
|
namespace ModelEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -148,7 +150,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
|
|||||||
|
|
||||||
const QStringList filePaths = findFilePathOfComponent(component);
|
const QStringList filePaths = findFilePathOfComponent(component);
|
||||||
for (const QString &filePath : filePaths) {
|
for (const QString &filePath : filePaths) {
|
||||||
CPlusPlus::Document::Ptr document = snapshot.document(filePath);
|
CPlusPlus::Document::Ptr document = snapshot.document(FilePath::fromString(filePath));
|
||||||
if (document) {
|
if (document) {
|
||||||
const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
|
const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
|
||||||
for (const CPlusPlus::Document::Include &include : includes) {
|
for (const CPlusPlus::Document::Include &include : includes) {
|
||||||
|
@@ -219,7 +219,7 @@ bool PxNodeUtilities::isProxyHeader(const QString &file) const
|
|||||||
CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance();
|
CppEditor::CppModelManager *cppModelManager = CppEditor::CppModelManager::instance();
|
||||||
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
|
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
|
||||||
|
|
||||||
CPlusPlus::Document::Ptr document = snapshot.document(file);
|
CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(file));
|
||||||
if (document) {
|
if (document) {
|
||||||
QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
|
QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
|
||||||
if (includes.count() != 1)
|
if (includes.count() != 1)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
add_qtc_test(tst_cplusplus_fileiterationorder
|
add_qtc_test(tst_cplusplus_fileiterationorder
|
||||||
DEPENDS CppEditor
|
DEPENDS CppEditor Utils
|
||||||
SOURCES tst_fileiterationorder.cpp
|
SOURCES tst_fileiterationorder.cpp
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user