Commit 8a6d767a authored by Christian Kamm's avatar Christian Kamm
Browse files

Refactoring changes: Cleanup and improvements.

Previously RefactoringFiles were usually passed around by value.
However, since a RefactoringFile may sometimes own a QTextDocument
(when it was read from a file), that's not great and caused the
file to be reread after every copy.

With this change RefactoringFile becomes noncopyable and is always
owned by a shared pointer.

This change also allowed having const RefactoringFiles which is
useful because they can be safely used from other threads. See
CppRefactoringChanges::fileNoEditor.

Change-Id: I9045921d6d0f6349f9558ff2a3d8317ea172193b
Reviewed-on: http://codereview.qt.nokia.com/3084

Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent a07acad5
......@@ -45,8 +45,8 @@ using namespace CPlusPlus;
QList<AST *> ASTPath::operator()(int line, int column)
{
_nodes.clear();
_line = line + 1;
_column = column + 1;
_line = line;
_column = column;
if (_doc) {
if (TranslationUnit *unit = _doc->translationUnit())
......
......@@ -54,9 +54,9 @@ public:
{}
QList<AST *> operator()(const QTextCursor &cursor)
{ return this->operator()(cursor.blockNumber(), cursor.positionInBlock()); }
{ return this->operator()(cursor.blockNumber() + 1, cursor.positionInBlock() + 1); }
/// line and column are 0-based!
/// line and column are 1-based!
QList<AST *> operator()(int line, int column);
#ifdef DEBUG_AST_PATH
......
......@@ -116,15 +116,17 @@ public:
}
virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
virtual void performChanges(const CppRefactoringFilePtr &currentFile,
const CppRefactoringChanges &)
{
ChangeSet changes;
int start = currentFile->endOf(compoundStatement->lbrace_token);
changes.insert(start, QLatin1String("\ncase ")
+ values.join(QLatin1String(":\nbreak;\ncase "))
+ QLatin1String(":\nbreak;"));
currentFile->change(changes);
currentFile->indent(currentFile->range(compoundStatement));
currentFile->setChangeSet(changes);
currentFile->appendIndentRange(currentFile->range(compoundStatement));
currentFile->apply();
}
CompoundStatementAST *compoundStatement;
......
......@@ -42,6 +42,7 @@
#include <cplusplus/TranslationUnit.h>
#include <cplusplus/LookupContext.h>
#include <cplusplus/Overview.h>
#include <cpptools/cpprefactoringchanges.h>
#include <texteditor/refactoroverlay.h>
#include <texteditor/tooltip/tooltip.h>
#include <texteditor/tooltip/tipcontents.h>
......@@ -76,10 +77,11 @@ QTextCursor FunctionDeclDefLinkFinder::scannedSelection() const
}
// parent is either a FunctionDefinitionAST or a SimpleDeclarationAST
static bool findDeclOrDef(const Document::Ptr &doc, const QTextCursor &cursor,
// line and column are 1-based
static bool findDeclOrDef(const Document::Ptr &doc, int line, int column,
DeclarationAST **parent, FunctionDeclaratorAST **funcDecl)
{
QList<AST *> path = ASTPath(doc)(cursor);
QList<AST *> path = ASTPath(doc)(line, column);
// for function definitions, simply scan for FunctionDefinitionAST not preceded
// by CompoundStatement/CtorInitializer
......@@ -113,19 +115,19 @@ static bool findDeclOrDef(const Document::Ptr &doc, const QTextCursor &cursor,
return *funcDecl;
}
static void declDefLinkStartEnd(const CppTools::CppRefactoringFile &file,
static void declDefLinkStartEnd(const CppTools::CppRefactoringFileConstPtr &file,
DeclarationAST *parent, FunctionDeclaratorAST *funcDecl,
int *start, int *end)
{
*start = file.startOf(parent);
*start = file->startOf(parent);
if (funcDecl->trailing_return_type)
*end = file.endOf(funcDecl->trailing_return_type);
*end = file->endOf(funcDecl->trailing_return_type);
else if (funcDecl->exception_specification)
*end = file.endOf(funcDecl->exception_specification);
*end = file->endOf(funcDecl->exception_specification);
else if (funcDecl->cv_qualifier_list)
*end = file.endOf(funcDecl->cv_qualifier_list->lastValue());
*end = file->endOf(funcDecl->cv_qualifier_list->lastValue());
else
*end = file.endOf(funcDecl->rparen_token);
*end = file->endOf(funcDecl->rparen_token);
}
static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<FunctionDeclDefLink> link, CppTools::CppRefactoringChanges changes)
......@@ -152,15 +154,14 @@ static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<Functio
// parse the target file to get the linked decl/def
const QString targetFileName = QString::fromUtf8(
target->fileName(), target->fileNameLength());
CppTools::CppRefactoringFile targetFile = changes.file(targetFileName);
if (!targetFile.isValid())
CppTools::CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(targetFileName);
if (!targetFile->isValid())
return noResult;
QTextCursor tc(targetFile.cursor());
tc.setPosition(targetFile.position(target->line(), target->column()));
DeclarationAST *targetParent = 0;
FunctionDeclaratorAST *targetFuncDecl = 0;
if (!findDeclOrDef(targetFile.cppDocument(), tc, &targetParent, &targetFuncDecl))
if (!findDeclOrDef(targetFile->cppDocument(), target->line(), target->column(),
&targetParent, &targetFuncDecl))
return noResult;
// the parens are necessary for finding good places for changes
......@@ -169,16 +170,14 @@ static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<Functio
int targetStart, targetEnd;
declDefLinkStartEnd(targetFile, targetParent, targetFuncDecl, &targetStart, &targetEnd);
QString targetInitial = targetFile.textOf(
targetFile.startOf(targetParent),
QString targetInitial = targetFile->textOf(
targetFile->startOf(targetParent),
targetEnd);
link->targetOffset = targetStart;
link->targetInitial = targetInitial;
link->targetFile = QSharedPointer<CppTools::CppRefactoringFile>(
new CppTools::CppRefactoringFile(targetFile.document()->clone(), targetFile.fileName()));
link->targetFile->setCppDocument(targetFile.cppDocument());
link->targetFile = targetFile;
link->targetFunction = targetFuncDecl->symbol;
link->targetFunctionDeclarator = targetFuncDecl;
link->targetDeclaration = targetParent;
......@@ -192,13 +191,13 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
// check if cursor is on function decl/def
DeclarationAST *parent = 0;
FunctionDeclaratorAST *funcDecl = 0;
if (!findDeclOrDef(doc, cursor, &parent, &funcDecl))
if (!findDeclOrDef(doc, cursor.blockNumber() + 1, cursor.columnNumber() + 1, &parent, &funcDecl))
return;
// find the start/end offsets
CppTools::CppRefactoringChanges refactoringChanges(snapshot);
CppTools::CppRefactoringFile sourceFile = refactoringChanges.file(doc->fileName());
sourceFile.setCppDocument(doc);
CppTools::CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->fileName());
sourceFile->setCppDocument(doc);
int start, end;
declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end);
......@@ -242,7 +241,7 @@ FunctionDeclDefLink::~FunctionDeclDefLink()
bool FunctionDeclDefLink::isValid() const
{
return targetFile;
return !linkSelection.isNull();
}
bool FunctionDeclDefLink::isMarkerVisible() const
......@@ -274,18 +273,16 @@ void FunctionDeclDefLink::apply(CPPEditorWidget *editor, bool jumpToMatch)
// first verify the interesting region of the target file is unchanged
CppTools::CppRefactoringChanges refactoringChanges(snapshot);
CppTools::CppRefactoringFile newTargetFile = refactoringChanges.file(targetFile->fileName());
if (!newTargetFile.isValid())
CppTools::CppRefactoringFilePtr newTargetFile = refactoringChanges.file(targetFile->fileName());
if (!newTargetFile->isValid())
return;
const int targetEnd = targetOffset + targetInitial.size();
if (targetInitial == newTargetFile.textOf(targetOffset, targetEnd)) {
if (targetInitial == newTargetFile->textOf(targetOffset, targetEnd)) {
const Utils::ChangeSet changeset = changes(snapshot);
newTargetFile.change(changeset, jumpToMatch);
if (jumpToMatch) {
QTextCursor tc = newTargetFile.cursor();
tc.setPosition(targetOffset + targetInitial.size());
refactoringChanges.activateEditor(newTargetFile.fileName(), tc.blockNumber(), tc.columnNumber());
}
newTargetFile->setChangeSet(changeset);
if (jumpToMatch)
newTargetFile->setOpenEditor(true, targetOffset);
newTargetFile->apply();
} else {
TextEditor::ToolTip::instance()->show(
editor->toolTipPosition(linkSelection),
......@@ -361,8 +358,6 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
{
Utils::ChangeSet changes;
QSharedPointer<CppTools::CppRefactoringFile> matchFile = targetFile;
// parse the current source declaration
TypeOfExpression typeOfExpression; // ### just need to preprocess...
typeOfExpression.init(sourceDocument, snapshot);
......@@ -412,15 +407,15 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
if (SimpleDeclarationAST *simple = targetDeclaration->asSimpleDeclaration()) {
declarator = simple->declarator_list->value;
if (simple->decl_specifier_list)
returnTypeStart = matchFile->startOf(simple->decl_specifier_list->value);
returnTypeStart = targetFile->startOf(simple->decl_specifier_list->value);
else
returnTypeStart = matchFile->startOf(declarator);
returnTypeStart = targetFile->startOf(declarator);
} else if (FunctionDefinitionAST *def = targetDeclaration->asFunctionDefinition()) {
declarator = def->declarator;
if (def->decl_specifier_list)
returnTypeStart = matchFile->startOf(def->decl_specifier_list->value);
returnTypeStart = targetFile->startOf(def->decl_specifier_list->value);
else
returnTypeStart = matchFile->startOf(declarator);
returnTypeStart = targetFile->startOf(declarator);
}
if (!newFunction->returnType().isEqualTo(sourceFunction->returnType())
......@@ -428,7 +423,7 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
FullySpecifiedType type = rewriteType(newFunction->returnType(), &env, control);
const QString replacement = overview(type, targetFunction->name());
changes.replace(returnTypeStart,
matchFile->startOf(targetFunctionDeclarator->lparen_token),
targetFile->startOf(targetFunctionDeclarator->lparen_token),
replacement);
}
}
......@@ -478,35 +473,35 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
ParameterDeclarationAST *targetParamAst = targetParameterDeclIt->value;
int parameterNameEnd = 0;
if (targetParamAst->declarator)
parameterNameEnd = matchFile->endOf(targetParamAst->declarator);
parameterNameEnd = targetFile->endOf(targetParamAst->declarator);
else if (targetParamAst->type_specifier_list)
parameterNameEnd = matchFile->endOf(targetParamAst->type_specifier_list->lastToken() - 1);
parameterNameEnd = targetFile->endOf(targetParamAst->type_specifier_list->lastToken() - 1);
else
parameterNameEnd = matchFile->startOf(targetParamAst);
parameterNameEnd = targetFile->startOf(targetParamAst);
if (allowChangeType
&& !targetParam->type().isEqualTo(newParam->type())) {
FullySpecifiedType replacementType = rewriteType(newParam->type(), &env, control);
const QString replacement = overview(replacementType, replacementName);
changes.replace(matchFile->startOf(targetParamAst),
changes.replace(targetFile->startOf(targetParamAst),
parameterNameEnd,
replacement);
} else if (!namesEqual(targetParam->name(), replacementName)) {
DeclaratorIdAST *id = getDeclaratorId(targetParamAst->declarator);
QString replacementNameStr = overview(replacementName);
if (id) {
changes.replace(matchFile->range(id), replacementNameStr);
changes.replace(targetFile->range(id), replacementNameStr);
} else {
// add name to unnamed parameter
replacementNameStr.prepend(QLatin1Char(' '));
int end;
if (targetParamAst->equal_token) {
end = matchFile->startOf(targetParamAst->equal_token);
end = targetFile->startOf(targetParamAst->equal_token);
replacementNameStr.append(QLatin1Char(' '));
} else {
// one past end on purpose
end = matchFile->startOf(targetParamAst->lastToken());
end = targetFile->startOf(targetParamAst->lastToken());
}
changes.replace(parameterNameEnd, end, replacementNameStr);
}
......@@ -516,15 +511,15 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
targetParameterDeclIt = firstTargetParameterDeclIt;
if (targetParameterDeclIt) {
if (newArgCount == 0) {
changes.remove(matchFile->startOf(targetParameterDeclIt->firstToken()),
matchFile->endOf(targetParameterDeclIt->lastToken() - 1));
changes.remove(targetFile->startOf(targetParameterDeclIt->firstToken()),
targetFile->endOf(targetParameterDeclIt->lastToken() - 1));
} else {
// get the last valid argument
for (unsigned i = 0; i < newArgCount - 1 && targetParameterDeclIt; ++i)
targetParameterDeclIt = targetParameterDeclIt->next;
if (targetParameterDeclIt) {
const int start = matchFile->endOf(targetParameterDeclIt->value);
const int end = matchFile->endOf(targetParameterDecl->lastToken() - 1);
const int start = targetFile->endOf(targetParameterDeclIt->value);
const int end = targetFile->endOf(targetParameterDecl->lastToken() - 1);
changes.remove(start, end);
}
}
......@@ -542,9 +537,9 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
if (targetParameterDeclIt) {
while (targetParameterDeclIt->next)
targetParameterDeclIt = targetParameterDeclIt->next;
changes.insert(matchFile->endOf(targetParameterDeclIt->value), newParams);
changes.insert(targetFile->endOf(targetParameterDeclIt->value), newParams);
} else {
changes.insert(matchFile->endOf(targetFunctionDeclarator->lparen_token), newParams);
changes.insert(targetFile->endOf(targetFunctionDeclarator->lparen_token), newParams);
}
}
}
......@@ -560,12 +555,12 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot)
cvString += QLatin1Char(' ');
cvString += QLatin1String("volatile");
}
const int rparenEnd = matchFile->endOf(targetFunctionDeclarator->rparen_token);
const int rparenEnd = targetFile->endOf(targetFunctionDeclarator->rparen_token);
if (targetFunctionDeclarator->cv_qualifier_list) {
const int cvEnd = matchFile->endOf(targetFunctionDeclarator->cv_qualifier_list->lastToken() - 1);
const int cvEnd = targetFile->endOf(targetFunctionDeclarator->cv_qualifier_list->lastToken() - 1);
// if the qualifies changed, replace
if (!cvString.isEmpty()) {
changes.replace(matchFile->startOf(targetFunctionDeclarator->cv_qualifier_list->firstToken()),
changes.replace(targetFile->startOf(targetFunctionDeclarator->cv_qualifier_list->firstToken()),
cvEnd, cvString);
} else {
// remove
......
......@@ -100,7 +100,7 @@ public:
CPlusPlus::DeclarationAST *sourceDeclaration;
CPlusPlus::FunctionDeclaratorAST *sourceFunctionDeclarator;
QSharedPointer<CppTools::CppRefactoringFile> targetFile;
CppTools::CppRefactoringFileConstPtr targetFile;
CPlusPlus::Function *targetFunction;
CPlusPlus::DeclarationAST *targetDeclaration;
CPlusPlus::FunctionDeclaratorAST *targetFunctionDeclarator;
......
......@@ -80,25 +80,24 @@ public:
"Add %1 Declaration").arg(type));
}
void performChanges(CppRefactoringFile *, CppRefactoringChanges *refactoring)
void performChanges(const CppRefactoringFilePtr &,
const CppRefactoringChanges &refactoring)
{
InsertionPointLocator locator(refactoring);
const InsertionLocation loc = locator.methodDeclarationInClass(
m_targetFileName, m_targetSymbol, m_xsSpec);
Q_ASSERT(loc.isValid());
CppRefactoringFile targetFile = refactoring->file(m_targetFileName);
int targetPosition1 = targetFile.position(loc.line(), loc.column());
int targetPosition2 = qMax(0, targetFile.position(loc.line(), 1) - 1);
CppRefactoringFilePtr targetFile = refactoring.file(m_targetFileName);
int targetPosition1 = targetFile->position(loc.line(), loc.column());
int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1);
Utils::ChangeSet target;
target.insert(targetPosition1, loc.prefix() + m_decl);
targetFile.change(target);
targetFile.indent(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
const int prefixLineCount = loc.prefix().count(QLatin1Char('\n'));
refactoring->activateEditor(m_targetFileName, loc.line() + prefixLineCount,
qMax(((int) loc.column()) - 1, 0));
targetFile->setChangeSet(target);
targetFile->appendIndentRange(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
targetFile->setOpenEditor(true, targetPosition1);
targetFile->apply();
}
private:
......@@ -114,7 +113,7 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface)
{
const QList<AST *> &path = interface->path();
const CppRefactoringFile &file = interface->currentFile();
CppRefactoringFilePtr file = interface->currentFile();
FunctionDefinitionAST *funDef = 0;
int idx = 0;
......@@ -122,7 +121,7 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
AST *node = path.at(idx);
if (idx > 1) {
if (DeclaratorIdAST *declId = node->asDeclaratorId()) {
if (file.isCursorOn(declId)) {
if (file->isCursorOn(declId)) {
if (FunctionDefinitionAST *candidate = path.at(idx - 2)->asFunctionDefinition()) {
if (funDef) {
return noResult();
......@@ -230,12 +229,12 @@ public:
.arg(dir.relativeFilePath(m_loc.fileName())));
}
void performChanges(CppRefactoringFile *,
CppRefactoringChanges *refactoring)
void performChanges(const CppRefactoringFilePtr &,
const CppRefactoringChanges &refactoring)
{
Q_ASSERT(m_loc.isValid());
CppRefactoringFile targetFile = refactoring->file(m_loc.fileName());
CppRefactoringFilePtr targetFile = refactoring.file(m_loc.fileName());
Overview oo;
oo.setShowFunctionSignatures(true);
......@@ -243,7 +242,7 @@ public:
oo.setShowArgumentNames(true);
// make target lookup context
Document::Ptr targetDoc = targetFile.cppDocument();
Document::Ptr targetDoc = targetFile->cppDocument();
Scope *targetScope = targetDoc->scopeAt(m_loc.line(), m_loc.column());
LookupContext targetContext(targetDoc, assistInterface()->snapshot());
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
......@@ -272,18 +271,15 @@ public:
QString defText = oo.prettyType(tn, name) + "\n{\n}";
int targetPos = targetFile.position(m_loc.line(), m_loc.column());
int targetPos2 = qMax(0, targetFile.position(m_loc.line(), 1) - 1);
int targetPos = targetFile->position(m_loc.line(), m_loc.column());
int targetPos2 = qMax(0, targetFile->position(m_loc.line(), 1) - 1);
Utils::ChangeSet target;
target.insert(targetPos, m_loc.prefix() + defText + m_loc.suffix());
targetFile.change(target);
targetFile.indent(Utils::ChangeSet::Range(targetPos2, targetPos));
const int prefixLineCount = m_loc.prefix().count(QLatin1Char('\n'));
refactoring->activateEditor(m_loc.fileName(),
m_loc.line() + prefixLineCount,
0);
targetFile->setChangeSet(target);
targetFile->appendIndentRange(Utils::ChangeSet::Range(targetPos2, targetPos));
targetFile->setOpenEditor(true, targetPos);
targetFile->apply();
}
private:
......@@ -297,7 +293,7 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(
const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface)
{
const QList<AST *> &path = interface->path();
const CppRefactoringFile &file = interface->currentFile();
CppRefactoringFilePtr file = interface->currentFile();
int idx = path.size() - 1;
for (; idx >= 0; --idx) {
......@@ -311,9 +307,9 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(
&& decl->enclosingScope()
&& decl->enclosingScope()->isClass()) {
DeclaratorAST *declarator = simpleDecl->declarator_list->value;
if (file.isCursorOn(declarator->core_declarator)) {
if (file->isCursorOn(declarator->core_declarator)) {
CppRefactoringChanges refactoring(interface->snapshot());
InsertionPointLocator locator(&refactoring);
InsertionPointLocator locator(refactoring);
QList<CppQuickFixOperation::Ptr> results;
foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) {
if (loc.isValid())
......
......@@ -71,24 +71,23 @@ QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(
if (!klass)
return noResult();
CppRefactoringChanges refactoring(interface->snapshot());
const CppRefactoringFile &file = refactoring.file(interface->file()->fileName());
const QString propertyName = file.textOf(qtPropertyDeclaration->property_name);
CppRefactoringFilePtr file = interface->currentFile();
const QString propertyName = file->textOf(qtPropertyDeclaration->property_name);
QString getterName;
QString setterName;
QString signalName;
int generateFlags = 0;
for (QtPropertyDeclarationItemListAST *it = qtPropertyDeclaration->property_declaration_item_list;
it; it = it->next) {
const QString tokenString = file.tokenAt(it->value->item_name_token).spell();
const QString tokenString = file->tokenAt(it->value->item_name_token).spell();
if (tokenString == QLatin1String("READ")) {
getterName = file.textOf(it->value->expression);
getterName = file->textOf(it->value->expression);
generateFlags |= GenerateGetter;
} else if (tokenString == QLatin1String("WRITE")) {
setterName = file.textOf(it->value->expression);
setterName = file->textOf(it->value->expression);
generateFlags |= GenerateSetter;
} else if (tokenString == QLatin1String("NOTIFY")) {
signalName = file.textOf(it->value->expression);
signalName = file->textOf(it->value->expression);
generateFlags |= GenerateSignal;
}
}
......@@ -143,7 +142,8 @@ InsertQtPropertyMembers::Operation::Operation(
setDescription(desc);
}
void InsertQtPropertyMembers::Operation::performChanges(CppRefactoringFile *file, CppRefactoringChanges *refactoring)
void InsertQtPropertyMembers::Operation::performChanges(const CppRefactoringFilePtr &file,
const CppRefactoringChanges &refactoring)
{
InsertionPointLocator locator(refactoring);
Utils::ChangeSet declarations;
......@@ -190,13 +190,14 @@ void InsertQtPropertyMembers::Operation::performChanges(CppRefactoringFile *file
insertAndIndent(file, &declarations, storageLoc, storageDeclaration);
}
file->change(declarations);
file->setChangeSet(declarations);
file->apply();
}
void InsertQtPropertyMembers::Operation::insertAndIndent(RefactoringFile *file, ChangeSet *changeSet, const InsertionLocation &loc, const QString &text)
void InsertQtPropertyMembers::Operation::insertAndIndent(const RefactoringFilePtr &file, ChangeSet *changeSet, const InsertionLocation &loc, const QString &text)
{
int targetPosition1 = file->position(loc.line(), loc.column());
int targetPosition2 = qMax(0, file->position(loc.line(), 1) - 1);
changeSet->insert(targetPosition1, loc.prefix() + text + loc.suffix());
file->indent(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
file->appendIndentRange(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
}
......@@ -44,6 +44,7 @@ class Class;
namespace TextEditor {
class RefactoringFile;
typedef QSharedPointer<RefactoringFile> RefactoringFilePtr;
}
namespace Utils {
......@@ -83,11 +84,11 @@ private:
const QString &getterName, const QString &setterName, const QString &signalName,
const QString &storageName);
virtual void performChanges(CppTools::CppRefactoringFile *file,
CppTools::CppRefactoringChanges *refactoring);
virtual void performChanges(const CppTools::CppRefactoringFilePtr &file,
const CppTools::CppRefactoringChanges &refactoring);
private:
void insertAndIndent(TextEditor::RefactoringFile *file, Utils::ChangeSet *changeSet,
void insertAndIndent(const TextEditor::RefactoringFilePtr &file, Utils::ChangeSet *changeSet,
const CppTools::InsertionLocation &loc, const QString &text);
CPlusPlus::QtPropertyDeclarationAST *m_declaration;
......
......@@ -70,9 +70,9 @@ CppQuickFixOperation::~CppQuickFixOperation()
void CppQuickFixOperation::perform()
{
CppRefactoringChanges refactoring(m_interface->snapshot());
CppRefactoringFile current = refactoring.file(fileName());
CppRefactoringFilePtr current = refactoring.file(fileName());
performChanges(&current, &refactoring);
performChanges(current, refactoring);
}
const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
......
......@@ -40,6 +40,7 @@ namespace CppTools {
class CppModelManagerInterface;
class CppRefactoringFile;
class CppRefactoringChanges;
typedef QSharedPointer<CppRefactoringFile> CppRefactoringFilePtr;
} // namespace CppTools
namespace ExtensionSystem {
......@@ -63,8 +64,8 @@ public:
virtual void perform();
protected:
virtual void performChanges(CppTools::CppRefactoringFile *currentFile,
CppTools::CppRefactoringChanges *refactoring) = 0;
virtual void performChanges(const CppTools::CppRefactoringFilePtr &currentFile,
const CppTools::CppRefactoringChanges &refactoring) = 0;
QString fileName() const;
......
......@@ -105,6 +105,7 @@ CppQuickFixAssistInterface::CppQuickFixAssistInterface(CPPEditorWidget *editor,
, m_editor(editor)
, m_semanticInfo(editor->semanticInfo())
, m_snapshot(CPlusPlus::CppModelManagerInterface::instance()->snapshot())
, m_currentFile(CppRefactoringChanges::file(editor, m_semanticInfo.doc))
, m_context(m_semanticInfo.doc, m_snapshot)
{
CPlusPlus::ASTPath astPath(m_semanticInfo.doc);
......@@ -136,19 +137,17 @@ CPPEditorWidget *CppQuickFixAssistInterface::editor() const
return m_editor;
}
const CppRefactoringFile CppQuickFixAssistInterface::currentFile() const
CppRefactoringFilePtr CppQuickFixAssistInterface::currentFile() const
{