forked from qt-creator/qt-creator
TextEditor: Make RefactoringChanges::file() virtual
More preparation for de-virtualization of RefactoringChangesData. Change-Id: Ib5f7782a8dcaa2ae093b62aebedbd7bae9d4c3f1 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -199,7 +199,7 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
|
|||||||
|
|
||||||
// find the start/end offsets
|
// find the start/end offsets
|
||||||
CppRefactoringChanges refactoringChanges(snapshot);
|
CppRefactoringChanges refactoringChanges(snapshot);
|
||||||
CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->filePath());
|
CppRefactoringFilePtr sourceFile = refactoringChanges.cppFile(doc->filePath());
|
||||||
sourceFile->setCppDocument(doc);
|
sourceFile->setCppDocument(doc);
|
||||||
int start, end;
|
int start, end;
|
||||||
declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end);
|
declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end);
|
||||||
@@ -259,7 +259,7 @@ void FunctionDeclDefLink::apply(CppEditorWidget *editor, bool jumpToMatch)
|
|||||||
|
|
||||||
// first verify the interesting region of the target file is unchanged
|
// first verify the interesting region of the target file is unchanged
|
||||||
CppRefactoringChanges refactoringChanges(snapshot);
|
CppRefactoringChanges refactoringChanges(snapshot);
|
||||||
CppRefactoringFilePtr newTargetFile = refactoringChanges.file(targetFile->filePath());
|
CppRefactoringFilePtr newTargetFile = refactoringChanges.cppFile(targetFile->filePath());
|
||||||
if (!newTargetFile->isValid())
|
if (!newTargetFile->isValid())
|
||||||
return;
|
return;
|
||||||
const int targetStart = newTargetFile->position(targetLine, targetColumn);
|
const int targetStart = newTargetFile->position(targetLine, targetColumn);
|
||||||
|
|||||||
@@ -763,7 +763,7 @@ public:
|
|||||||
Utils::ChangeSet headerChangeSet;
|
Utils::ChangeSet headerChangeSet;
|
||||||
const CppRefactoringChanges refactoring(snapshot());
|
const CppRefactoringChanges refactoring(snapshot());
|
||||||
const Utils::FilePath filePath = currentFile()->filePath();
|
const Utils::FilePath filePath = currentFile()->filePath();
|
||||||
const CppRefactoringFilePtr headerFile = refactoring.file(filePath);
|
const CppRefactoringFilePtr headerFile = refactoring.cppFile(filePath);
|
||||||
const LookupContext targetContext(headerFile->cppDocument(), snapshot());
|
const LookupContext targetContext(headerFile->cppDocument(), snapshot());
|
||||||
|
|
||||||
const Class *targetClass = m_classAST->symbol;
|
const Class *targetClass = m_classAST->symbol;
|
||||||
@@ -881,7 +881,7 @@ public:
|
|||||||
if (!clazz)
|
if (!clazz)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CppRefactoringFilePtr implementationFile = refactoring.file(m_cppFilePath);
|
CppRefactoringFilePtr implementationFile = refactoring.cppFile(m_cppFilePath);
|
||||||
Utils::ChangeSet implementationChangeSet;
|
Utils::ChangeSet implementationChangeSet;
|
||||||
const int insertPos = qMax(0, implementationFile->document()->characterCount() - 1);
|
const int insertPos = qMax(0, implementationFile->document()->characterCount() - 1);
|
||||||
|
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
if (negation) {
|
if (negation) {
|
||||||
@@ -498,7 +498,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
changes.flip(currentFile->range(binary->left_expression),
|
changes.flip(currentFile->range(binary->left_expression),
|
||||||
@@ -587,7 +587,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
changes.replace(currentFile->range(pattern->binary_op_token), QLatin1String("||"));
|
changes.replace(currentFile->range(pattern->binary_op_token), QLatin1String("||"));
|
||||||
@@ -672,7 +672,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -763,7 +763,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -837,7 +837,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -910,7 +910,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -988,7 +988,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
const Token binaryToken = currentFile->tokenAt(condition->binary_op_token);
|
const Token binaryToken = currentFile->tokenAt(condition->binary_op_token);
|
||||||
|
|
||||||
@@ -1227,7 +1227,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -1430,7 +1430,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
|
|
||||||
@@ -1492,7 +1492,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
changes.replace(start, end, replacement);
|
changes.replace(start, end, replacement);
|
||||||
@@ -1651,7 +1651,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
QString declaration = getDeclaration();
|
QString declaration = getDeclaration();
|
||||||
|
|
||||||
if (!declaration.isEmpty()) {
|
if (!declaration.isEmpty()) {
|
||||||
@@ -1668,7 +1668,7 @@ private:
|
|||||||
QString getDeclaration()
|
QString getDeclaration()
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
|
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
|
||||||
const auto settings = CppQuickFixProjectsSettings::getQuickFixSettings(
|
const auto settings = CppQuickFixProjectsSettings::getQuickFixSettings(
|
||||||
ProjectExplorer::ProjectTree::currentProject());
|
ProjectExplorer::ProjectTree::currentProject());
|
||||||
@@ -1704,7 +1704,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
QString newName = m_isAllUpper ? m_name.toLower() : m_name;
|
QString newName = m_isAllUpper ? m_name.toLower() : m_name;
|
||||||
for (int i = 1; i < newName.length(); ++i) {
|
for (int i = 1; i < newName.length(); ++i) {
|
||||||
@@ -1786,7 +1786,7 @@ AddIncludeForUndefinedIdentifierOp::AddIncludeForUndefinedIdentifierOp(
|
|||||||
void AddIncludeForUndefinedIdentifierOp::perform()
|
void AddIncludeForUndefinedIdentifierOp::perform()
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr file = refactoring.file(filePath());
|
CppRefactoringFilePtr file = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
insertNewIncludeDirective(m_include, file, semanticInfo().doc);
|
insertNewIncludeDirective(m_include, file, semanticInfo().doc);
|
||||||
}
|
}
|
||||||
@@ -1808,7 +1808,7 @@ void AddForwardDeclForUndefinedIdentifierOp::perform()
|
|||||||
const QStringList namespaces = parts.mid(0, parts.length() - 1);
|
const QStringList namespaces = parts.mid(0, parts.length() - 1);
|
||||||
|
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr file = refactoring.file(filePath());
|
CppRefactoringFilePtr file = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
NSVisitor visitor(file.data(), namespaces, m_symbolPos);
|
NSVisitor visitor(file.data(), namespaces, m_symbolPos);
|
||||||
visitor.accept(file->cppDocument()->translationUnit()->ast());
|
visitor.accept(file->cppDocument()->translationUnit()->ast());
|
||||||
@@ -2157,7 +2157,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
int targetEndPos = currentFile->endOf(m_targetParam);
|
int targetEndPos = currentFile->endOf(m_targetParam);
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
@@ -2236,7 +2236,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
currentFile->setChangeSet(m_change);
|
currentFile->setChangeSet(m_change);
|
||||||
currentFile->apply();
|
currentFile->apply();
|
||||||
}
|
}
|
||||||
@@ -2397,7 +2397,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
int start = currentFile->endOf(compoundStatement->lbrace_token);
|
int start = currentFile->endOf(compoundStatement->lbrace_token);
|
||||||
@@ -2541,7 +2541,7 @@ public:
|
|||||||
m_targetFilePath, m_targetSymbol, m_xsSpec);
|
m_targetFilePath, m_targetSymbol, m_xsSpec);
|
||||||
QTC_ASSERT(loc.isValid(), return);
|
QTC_ASSERT(loc.isValid(), return);
|
||||||
|
|
||||||
CppRefactoringFilePtr targetFile = refactoring.file(m_targetFilePath);
|
CppRefactoringFilePtr targetFile = refactoring.cppFile(m_targetFilePath);
|
||||||
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);
|
||||||
|
|
||||||
@@ -2717,7 +2717,7 @@ public:
|
|||||||
refactoring, targetFilePath);
|
refactoring, targetFilePath);
|
||||||
QTC_ASSERT(loc.isValid(), return);
|
QTC_ASSERT(loc.isValid(), return);
|
||||||
|
|
||||||
CppRefactoringFilePtr targetFile = refactoring.file(loc.filePath());
|
CppRefactoringFilePtr targetFile = refactoring.cppFile(loc.filePath());
|
||||||
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
|
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
|
||||||
oo.showFunctionSignatures = true;
|
oo.showFunctionSignatures = true;
|
||||||
oo.showReturnTypes = true;
|
oo.showReturnTypes = true;
|
||||||
@@ -2784,7 +2784,7 @@ public:
|
|||||||
|
|
||||||
// rewrite the function name
|
// rewrite the function name
|
||||||
if (nameIncludesOperatorName(decl->name())) {
|
if (nameIncludesOperatorName(decl->name())) {
|
||||||
CppRefactoringFilePtr file = refactoring.file(op->filePath());
|
CppRefactoringFilePtr file = refactoring.cppFile(op->filePath());
|
||||||
const QString operatorNameText = file->textOf(declAST->core_declarator);
|
const QString operatorNameText = file->textOf(declAST->core_declarator);
|
||||||
oo.includeWhiteSpaceInOperatorName = operatorNameText.contains(QLatin1Char(' '));
|
oo.includeWhiteSpaceInOperatorName = operatorNameText.contains(QLatin1Char(' '));
|
||||||
}
|
}
|
||||||
@@ -2994,7 +2994,7 @@ private:
|
|||||||
filePath, m_class, m_accessSpec);
|
filePath, m_class, m_accessSpec);
|
||||||
QTC_ASSERT(loc.isValid(), return);
|
QTC_ASSERT(loc.isValid(), return);
|
||||||
|
|
||||||
CppRefactoringFilePtr targetFile = refactoring.file(filePath);
|
CppRefactoringFilePtr targetFile = refactoring.cppFile(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;
|
||||||
@@ -3579,7 +3579,7 @@ private:
|
|||||||
&changeSet.first, &changeSet.second);
|
&changeSet.first, &changeSet.second);
|
||||||
}
|
}
|
||||||
for (auto it = changeSets.cbegin(); it != changeSets.cend(); ++it) {
|
for (auto it = changeSets.cbegin(); it != changeSets.cend(); ++it) {
|
||||||
const CppRefactoringFilePtr file = refactoring.file(it.key());
|
const CppRefactoringFilePtr file = refactoring.cppFile(it.key());
|
||||||
for (const ChangeSet::Range &r : it.value().second)
|
for (const ChangeSet::Range &r : it.value().second)
|
||||||
file->appendIndentRange(r);
|
file->appendIndentRange(r);
|
||||||
file->setChangeSet(it.value().first);
|
file->setChangeSet(it.value().first);
|
||||||
@@ -3705,14 +3705,14 @@ public:
|
|||||||
: m_operation(operation)
|
: m_operation(operation)
|
||||||
, m_changes(m_operation->snapshot())
|
, m_changes(m_operation->snapshot())
|
||||||
, m_locator(m_changes)
|
, m_locator(m_changes)
|
||||||
, m_headerFile(m_changes.file(filePath))
|
, m_headerFile(m_changes.cppFile(filePath))
|
||||||
, m_sourceFile([&] {
|
, m_sourceFile([&] {
|
||||||
FilePath cppFilePath = correspondingHeaderOrSource(filePath, &m_isHeaderHeaderFile);
|
FilePath cppFilePath = correspondingHeaderOrSource(filePath, &m_isHeaderHeaderFile);
|
||||||
if (!m_isHeaderHeaderFile || !cppFilePath.exists()) {
|
if (!m_isHeaderHeaderFile || !cppFilePath.exists()) {
|
||||||
// there is no "source" file
|
// there is no "source" file
|
||||||
return m_headerFile;
|
return m_headerFile;
|
||||||
} else {
|
} else {
|
||||||
return m_changes.file(cppFilePath);
|
return m_changes.cppFile(cppFilePath);
|
||||||
}
|
}
|
||||||
}())
|
}())
|
||||||
, m_class(clazz)
|
, m_class(clazz)
|
||||||
@@ -5052,7 +5052,7 @@ public:
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(!m_funcReturn || !m_relevantDecls.isEmpty(), return);
|
QTC_ASSERT(!m_funcReturn || !m_relevantDecls.isEmpty(), return);
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
ExtractFunctionOptions options;
|
ExtractFunctionOptions options;
|
||||||
if (m_functionNameGetter)
|
if (m_functionNameGetter)
|
||||||
@@ -5208,7 +5208,7 @@ public:
|
|||||||
const FilePath filePath = FilePath::fromUtf8(matchingClass->fileName());
|
const FilePath filePath = FilePath::fromUtf8(matchingClass->fileName());
|
||||||
const InsertionLocation &location =
|
const InsertionLocation &location =
|
||||||
locator.methodDeclarationInClass(filePath, matchingClass, options.access);
|
locator.methodDeclarationInClass(filePath, matchingClass, options.access);
|
||||||
CppRefactoringFilePtr declFile = refactoring.file(filePath);
|
CppRefactoringFilePtr declFile = refactoring.cppFile(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());
|
||||||
@@ -5717,7 +5717,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FilePath declFilePath = matchingClass->filePath();
|
const FilePath declFilePath = matchingClass->filePath();
|
||||||
result.file = refactoring.file(declFilePath);
|
result.file = refactoring.cppFile(declFilePath);
|
||||||
ASTPath astPath(result.file->cppDocument());
|
ASTPath astPath(result.file->cppDocument());
|
||||||
const QList<AST *> path = astPath(s->line(), s->column());
|
const QList<AST *> path = astPath(s->line(), s->column());
|
||||||
SimpleDeclarationAST *simpleDecl = nullptr;
|
SimpleDeclarationAST *simpleDecl = nullptr;
|
||||||
@@ -5740,7 +5740,7 @@ public:
|
|||||||
FilePath declFilePath = correspondingHeaderOrSource(filePath(), &isHeaderFile);
|
FilePath declFilePath = correspondingHeaderOrSource(filePath(), &isHeaderFile);
|
||||||
if (!declFilePath.exists())
|
if (!declFilePath.exists())
|
||||||
return FoundDeclaration();
|
return FoundDeclaration();
|
||||||
result.file = refactoring.file(declFilePath);
|
result.file = refactoring.cppFile(declFilePath);
|
||||||
if (!result.file)
|
if (!result.file)
|
||||||
return FoundDeclaration();
|
return FoundDeclaration();
|
||||||
const LookupContext lc(result.file->cppDocument(), snapshot());
|
const LookupContext lc(result.file->cppDocument(), snapshot());
|
||||||
@@ -5769,7 +5769,7 @@ public:
|
|||||||
FunctionDeclaratorAST *functionDeclaratorOfDefinition
|
FunctionDeclaratorAST *functionDeclaratorOfDefinition
|
||||||
= functionDeclarator(m_functionDefinition);
|
= functionDeclarator(m_functionDefinition);
|
||||||
const CppRefactoringChanges refactoring(snapshot());
|
const CppRefactoringChanges refactoring(snapshot());
|
||||||
const CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
const CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
deduceTypeNameOfLiteral(currentFile->cppDocument());
|
deduceTypeNameOfLiteral(currentFile->cppDocument());
|
||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
@@ -5951,7 +5951,7 @@ public:
|
|||||||
, m_identifierAST(identifierAST)
|
, m_identifierAST(identifierAST)
|
||||||
, m_symbol(symbol)
|
, m_symbol(symbol)
|
||||||
, m_refactoring(snapshot())
|
, m_refactoring(snapshot())
|
||||||
, m_file(m_refactoring.file(filePath()))
|
, m_file(m_refactoring.cppFile(filePath()))
|
||||||
, m_document(interface.semanticInfo().doc)
|
, m_document(interface.semanticInfo().doc)
|
||||||
{
|
{
|
||||||
setDescription(
|
setDescription(
|
||||||
@@ -6552,8 +6552,8 @@ public:
|
|||||||
const FilePath &fromFile, const FilePath &toFile)
|
const FilePath &fromFile, const FilePath &toFile)
|
||||||
: m_operation(operation), m_type(type), m_changes(m_operation->snapshot())
|
: m_operation(operation), m_type(type), m_changes(m_operation->snapshot())
|
||||||
{
|
{
|
||||||
m_fromFile = m_changes.file(fromFile);
|
m_fromFile = m_changes.cppFile(fromFile);
|
||||||
m_toFile = (m_type == MoveOutside) ? m_fromFile : m_changes.file(toFile);
|
m_toFile = (m_type == MoveOutside) ? m_fromFile : m_changes.cppFile(toFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void performMove(FunctionDefinitionAST *funcAST)
|
void performMove(FunctionDefinitionAST *funcAST)
|
||||||
@@ -6819,8 +6819,8 @@ private:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr fromFile = refactoring.file(m_fromFilePath);
|
CppRefactoringFilePtr fromFile = refactoring.cppFile(m_fromFilePath);
|
||||||
CppRefactoringFilePtr toFile = refactoring.file(m_toFilePath);
|
CppRefactoringFilePtr toFile = refactoring.cppFile(m_toFilePath);
|
||||||
|
|
||||||
ensureFuncDefAstAndRange(*fromFile);
|
ensureFuncDefAstAndRange(*fromFile);
|
||||||
if (!m_funcAST)
|
if (!m_funcAST)
|
||||||
@@ -6912,7 +6912,7 @@ void MoveFuncDefToDeclPush::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const CppRefactoringChanges refactoring(interface.snapshot());
|
const CppRefactoringChanges refactoring(interface.snapshot());
|
||||||
const CppRefactoringFilePtr defFile = refactoring.file(interface.filePath());
|
const CppRefactoringFilePtr defFile = refactoring.cppFile(interface.filePath());
|
||||||
const ChangeSet::Range defRange = defFile->range(completeDefAST);
|
const ChangeSet::Range defRange = defFile->range(completeDefAST);
|
||||||
|
|
||||||
// Determine declaration (file, range, text);
|
// Determine declaration (file, range, text);
|
||||||
@@ -6944,7 +6944,7 @@ void MoveFuncDefToDeclPush::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
}
|
}
|
||||||
|
|
||||||
declFilePath = matchingClass->filePath();
|
declFilePath = matchingClass->filePath();
|
||||||
const CppRefactoringFilePtr declFile = refactoring.file(declFilePath);
|
const CppRefactoringFilePtr declFile = refactoring.cppFile(declFilePath);
|
||||||
ASTPath astPath(declFile->cppDocument());
|
ASTPath astPath(declFile->cppDocument());
|
||||||
const QList<AST *> path = astPath(s->line(), s->column());
|
const QList<AST *> path = astPath(s->line(), s->column());
|
||||||
for (int idx = path.size() - 1; idx > 0; --idx) {
|
for (int idx = path.size() - 1; idx > 0; --idx) {
|
||||||
@@ -6969,7 +6969,7 @@ void MoveFuncDefToDeclPush::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
if (isHeaderFile)
|
if (isHeaderFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CppRefactoringFilePtr declFile = refactoring.file(declFilePath);
|
const CppRefactoringFilePtr declFile = refactoring.cppFile(declFilePath);
|
||||||
const LookupContext lc(declFile->cppDocument(), interface.snapshot());
|
const LookupContext lc(declFile->cppDocument(), interface.snapshot());
|
||||||
const QList<LookupItem> candidates = lc.lookup(func->name(), matchingNamespace);
|
const QList<LookupItem> candidates = lc.lookup(func->name(), matchingNamespace);
|
||||||
for (const LookupItem &candidate : candidates) {
|
for (const LookupItem &candidate : candidates) {
|
||||||
@@ -7059,7 +7059,7 @@ public:
|
|||||||
, m_name(name)
|
, m_name(name)
|
||||||
, m_oo(CppCodeStyleSettings::currentProjectCodeStyleOverview())
|
, m_oo(CppCodeStyleSettings::currentProjectCodeStyleOverview())
|
||||||
, m_originalName(m_oo.prettyName(m_name))
|
, m_originalName(m_oo.prettyName(m_name))
|
||||||
, m_file(CppRefactoringChanges(snapshot()).file(filePath()))
|
, m_file(CppRefactoringChanges(snapshot()).cppFile(filePath()))
|
||||||
{
|
{
|
||||||
setDescription(Tr::tr("Assign to Local Variable"));
|
setDescription(Tr::tr("Assign to Local Variable"));
|
||||||
}
|
}
|
||||||
@@ -7289,7 +7289,7 @@ public:
|
|||||||
|
|
||||||
const Utils::FilePath filePath = currentFile()->filePath();
|
const Utils::FilePath filePath = currentFile()->filePath();
|
||||||
const CppRefactoringChanges refactoring(snapshot());
|
const CppRefactoringChanges refactoring(snapshot());
|
||||||
const CppRefactoringFilePtr file = refactoring.file(filePath);
|
const CppRefactoringFilePtr file = refactoring.cppFile(filePath);
|
||||||
ChangeSet change;
|
ChangeSet change;
|
||||||
|
|
||||||
// Optimize post (in|de)crement operator to pre (in|de)crement operator
|
// Optimize post (in|de)crement operator to pre (in|de)crement operator
|
||||||
@@ -7549,7 +7549,7 @@ public:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
|
|
||||||
const int startPos = currentFile->startOf(m_literal);
|
const int startPos = currentFile->startOf(m_literal);
|
||||||
const int endPos = currentFile->endOf(m_literal);
|
const int endPos = currentFile->endOf(m_literal);
|
||||||
@@ -7647,7 +7647,7 @@ private:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
currentFile->setChangeSet(m_changes);
|
currentFile->setChangeSet(m_changes);
|
||||||
currentFile->apply();
|
currentFile->apply();
|
||||||
}
|
}
|
||||||
@@ -8397,7 +8397,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(node.document->filePath());
|
CppRefactoringFilePtr file = refactoring.cppFile(node.document->filePath());
|
||||||
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
|
||||||
@@ -8416,7 +8416,7 @@ private:
|
|||||||
void perform() override
|
void perform() override
|
||||||
{
|
{
|
||||||
CppRefactoringChanges refactoring(snapshot());
|
CppRefactoringChanges refactoring(snapshot());
|
||||||
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
|
CppRefactoringFilePtr currentFile = refactoring.cppFile(filePath());
|
||||||
if (m_removeAllAtGlobalScope) {
|
if (m_removeAllAtGlobalScope) {
|
||||||
removeAllUsingsAtGlobalScope(refactoring);
|
removeAllUsingsAtGlobalScope(refactoring);
|
||||||
} else if (refactorFile(currentFile,
|
} else if (refactorFile(currentFile,
|
||||||
@@ -8469,7 +8469,7 @@ private:
|
|||||||
if (!Utils::insert(m_processed, loc.first))
|
if (!Utils::insert(m_processed, loc.first))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CppRefactoringFilePtr file = refactoring.file(loc.first->filePath());
|
CppRefactoringFilePtr file = refactoring.cppFile(loc.first->filePath());
|
||||||
const bool noGlobalUsing = refactorFile(file,
|
const bool noGlobalUsing = refactorFile(file,
|
||||||
refactoring.snapshot(),
|
refactoring.snapshot(),
|
||||||
file->position(loc.second, 1));
|
file->position(loc.second, 1));
|
||||||
@@ -9686,11 +9686,11 @@ private:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CppRefactoringChanges changes(CppModelManager::snapshot());
|
CppRefactoringChanges changes(CppModelManager::snapshot());
|
||||||
const CppRefactoringFilePtr sourceFile = changes.file(symbolLoc.targetFilePath);
|
const CppRefactoringFilePtr sourceFile = changes.cppFile(symbolLoc.targetFilePath);
|
||||||
const CppRefactoringFilePtr targetFile
|
const CppRefactoringFilePtr targetFile
|
||||||
= targetLoc.targetFilePath == symbolLoc.targetFilePath
|
= targetLoc.targetFilePath == symbolLoc.targetFilePath
|
||||||
? sourceFile
|
? sourceFile
|
||||||
: changes.file(targetLoc.targetFilePath);
|
: changes.cppFile(targetLoc.targetFilePath);
|
||||||
const Document::Ptr &targetCppDoc = targetFile->cppDocument();
|
const Document::Ptr &targetCppDoc = targetFile->cppDocument();
|
||||||
const QList<AST *> targetAstPath = ASTPath(targetCppDoc)(
|
const QList<AST *> targetAstPath = ASTPath(targetCppDoc)(
|
||||||
targetLoc.targetLine, targetLoc.targetColumn + 1);
|
targetLoc.targetLine, targetLoc.targetColumn + 1);
|
||||||
|
|||||||
@@ -50,12 +50,17 @@ CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const
|
TextEditor::RefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data));
|
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CppRefactoringFilePtr CppRefactoringChanges::cppFile(const Utils::FilePath &filePath) const
|
||||||
|
{
|
||||||
|
return file(filePath).staticCast<CppRefactoringFile>();
|
||||||
|
}
|
||||||
|
|
||||||
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &filePath) const
|
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
QTextDocument *document = nullptr;
|
QTextDocument *document = nullptr;
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ public:
|
|||||||
|
|
||||||
static CppRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
static CppRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
||||||
const CPlusPlus::Document::Ptr &document);
|
const CPlusPlus::Document::Ptr &document);
|
||||||
CppRefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
TextEditor::RefactoringFilePtr file(const Utils::FilePath &filePath) const override;
|
||||||
|
|
||||||
|
CppRefactoringFilePtr cppFile(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
// safe to use from non-gui threads
|
// safe to use from non-gui threads
|
||||||
CppRefactoringFileConstPtr fileNoEditor(const Utils::FilePath &filePath) const;
|
CppRefactoringFileConstPtr fileNoEditor(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ InsertionLocation InsertionPointLocator::methodDeclarationInClass(
|
|||||||
AccessSpec xsSpec,
|
AccessSpec xsSpec,
|
||||||
ForceAccessSpec forceAccessSpec) const
|
ForceAccessSpec forceAccessSpec) const
|
||||||
{
|
{
|
||||||
const Document::Ptr doc = m_refactoringChanges.file(filePath)->cppDocument();
|
const Document::Ptr doc = m_refactoringChanges.cppFile(filePath)->cppDocument();
|
||||||
if (doc) {
|
if (doc) {
|
||||||
FindInClass find(doc->translationUnit(), clazz);
|
FindInClass find(doc->translationUnit(), clazz);
|
||||||
ClassSpecifierAST *classAST = find();
|
ClassSpecifierAST *classAST = find();
|
||||||
@@ -599,7 +599,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
|
|||||||
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(definitionFunction->filePath());
|
CppRefactoringFilePtr targetFile = changes.cppFile(definitionFunction->filePath());
|
||||||
if (!targetFile->isValid())
|
if (!targetFile->isValid())
|
||||||
return noResult;
|
return noResult;
|
||||||
|
|
||||||
@@ -653,7 +653,7 @@ const QList<InsertionLocation> InsertionPointLocator::methodDefinition(
|
|||||||
target = candidate;
|
target = candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFilePtr targetFile = m_refactoringChanges.file(target);
|
CppRefactoringFilePtr targetFile = m_refactoringChanges.cppFile(target);
|
||||||
Document::Ptr doc = targetFile->cppDocument();
|
Document::Ptr doc = targetFile->cppDocument();
|
||||||
if (doc.isNull())
|
if (doc.isNull())
|
||||||
return result;
|
return result;
|
||||||
@@ -761,7 +761,7 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
|
|||||||
{
|
{
|
||||||
QTC_ASSERT(symbol, return InsertionLocation());
|
QTC_ASSERT(symbol, return InsertionLocation());
|
||||||
|
|
||||||
CppRefactoringFilePtr file = refactoring.file(filePath);
|
CppRefactoringFilePtr file = refactoring.cppFile(filePath);
|
||||||
QStringList requiredNamespaces;
|
QStringList requiredNamespaces;
|
||||||
if (namespaceHandling == NamespaceHandling::CreateMissing) {
|
if (namespaceHandling == NamespaceHandling::CreateMissing) {
|
||||||
requiredNamespaces = getNamespaceNames(symbol);
|
requiredNamespaces = getNamespaceNames(symbol);
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ void performComponentFromObjectDef(QmlJSEditorWidget *editor,
|
|||||||
{
|
{
|
||||||
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
|
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
|
||||||
QmlJS::ModelManagerInterface::instance()->snapshot());
|
QmlJS::ModelManagerInterface::instance()->snapshot());
|
||||||
QmlJSRefactoringFilePtr current = refactoring.file(Utils::FilePath::fromString(fileName));
|
QmlJSRefactoringFilePtr current = refactoring.qmlJSFile(Utils::FilePath::fromString(fileName));
|
||||||
|
|
||||||
QmlJSQuickFixAssistInterface interface(editor, TextEditor::AssistReason::ExplicitlyInvoked);
|
QmlJSQuickFixAssistInterface interface(editor, TextEditor::AssistReason::ExplicitlyInvoked);
|
||||||
Operation operation(&interface, objDef);
|
Operation operation(&interface, objDef);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ QmlJSQuickFixOperation::QmlJSQuickFixOperation(const QmlJSQuickFixAssistInterfac
|
|||||||
void QmlJSQuickFixOperation::perform()
|
void QmlJSQuickFixOperation::perform()
|
||||||
{
|
{
|
||||||
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), semanticInfo().snapshot);
|
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), semanticInfo().snapshot);
|
||||||
QmlJSRefactoringFilePtr current = refactoring.file(fileName());
|
QmlJSRefactoringFilePtr current = refactoring.qmlJSFile(fileName());
|
||||||
|
|
||||||
performChanges(current, refactoring);
|
performChanges(current, refactoring);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,11 +81,16 @@ QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelMan
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::file(const Utils::FilePath &filePath) const
|
TextEditor::RefactoringFilePtr QmlJSRefactoringChanges::file(const Utils::FilePath &filePath) const
|
||||||
{
|
{
|
||||||
return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data));
|
return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::qmlJSFile(const Utils::FilePath &filePath) const
|
||||||
|
{
|
||||||
|
return file(filePath).staticCast<QmlJSRefactoringFile>();
|
||||||
|
}
|
||||||
|
|
||||||
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::file(
|
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::file(
|
||||||
TextEditor::TextEditorWidget *editor, const Document::Ptr &document)
|
TextEditor::TextEditorWidget *editor, const Document::Ptr &document)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ public:
|
|||||||
|
|
||||||
static QmlJSRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
static QmlJSRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
||||||
const QmlJS::Document::Ptr &document);
|
const QmlJS::Document::Ptr &document);
|
||||||
QmlJSRefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
TextEditor::RefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
|
QmlJSRefactoringFilePtr qmlJSFile(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
const QmlJS::Snapshot &snapshot() const;
|
const QmlJS::Snapshot &snapshot() const;
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,10 @@ public:
|
|||||||
explicit RefactoringChanges(RefactoringChangesData *data = nullptr);
|
explicit RefactoringChanges(RefactoringChangesData *data = nullptr);
|
||||||
virtual ~RefactoringChanges();
|
virtual ~RefactoringChanges();
|
||||||
|
|
||||||
RefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
// TODO: Make pure virtual and introduce dedicated subclass for generic refactoring,
|
||||||
|
// so no one instantiates this one by mistake.
|
||||||
|
virtual RefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
||||||
|
|
||||||
bool createFile(const Utils::FilePath &filePath,
|
bool createFile(const Utils::FilePath &filePath,
|
||||||
const QString &contents,
|
const QString &contents,
|
||||||
bool reindent = true,
|
bool reindent = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user