summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/cppcompleteswitch.cpp8
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp103
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.h2
-rw-r--r--src/plugins/cppeditor/cppinsertdecldef.cpp52
-rw-r--r--src/plugins/cppeditor/cppinsertqtpropertymembers.cpp23
-rw-r--r--src/plugins/cppeditor/cppinsertqtpropertymembers.h7
-rw-r--r--src/plugins/cppeditor/cppquickfix.cpp4
-rw-r--r--src/plugins/cppeditor/cppquickfix.h5
-rw-r--r--src/plugins/cppeditor/cppquickfixassistant.cpp11
-rw-r--r--src/plugins/cppeditor/cppquickfixassistant.h4
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp152
11 files changed, 193 insertions, 178 deletions
diff --git a/src/plugins/cppeditor/cppcompleteswitch.cpp b/src/plugins/cppeditor/cppcompleteswitch.cpp
index 05ec2c440e..dd287f3987 100644
--- a/src/plugins/cppeditor/cppcompleteswitch.cpp
+++ b/src/plugins/cppeditor/cppcompleteswitch.cpp
@@ -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;
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 0a5a49777c..9f33c62ffd 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -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
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.h b/src/plugins/cppeditor/cppfunctiondecldeflink.h
index 5de47afb91..a75e71f3ef 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.h
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.h
@@ -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;
diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp
index 7382b5abd7..a5676d2a10 100644
--- a/src/plugins/cppeditor/cppinsertdecldef.cpp
+++ b/src/plugins/cppeditor/cppinsertdecldef.cpp
@@ -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())
diff --git a/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp b/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
index ed1d99276b..108164da93 100644
--- a/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
+++ b/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
@@ -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));
}
diff --git a/src/plugins/cppeditor/cppinsertqtpropertymembers.h b/src/plugins/cppeditor/cppinsertqtpropertymembers.h
index 785ac87ba1..6e90d14a69 100644
--- a/src/plugins/cppeditor/cppinsertqtpropertymembers.h
+++ b/src/plugins/cppeditor/cppinsertqtpropertymembers.h
@@ -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;
diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp
index ae63fb43ed..96e4d2178a 100644
--- a/src/plugins/cppeditor/cppquickfix.cpp
+++ b/src/plugins/cppeditor/cppquickfix.cpp
@@ -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
diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h
index 3d93b41f28..af5ec93101 100644
--- a/src/plugins/cppeditor/cppquickfix.h
+++ b/src/plugins/cppeditor/cppquickfix.h
@@ -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;
diff --git a/src/plugins/cppeditor/cppquickfixassistant.cpp b/src/plugins/cppeditor/cppquickfixassistant.cpp
index dccf0af809..9f02ddb066 100644
--- a/src/plugins/cppeditor/cppquickfixassistant.cpp
+++ b/src/plugins/cppeditor/cppquickfixassistant.cpp
@@ -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
{
- CppRefactoringFile file(m_editor);
- file.setCppDocument(m_semanticInfo.doc);
- return file;
+ return m_currentFile;
}
bool CppQuickFixAssistInterface::isCursorOn(unsigned tokenIndex) const
{
- return currentFile().isCursorOn(tokenIndex);
+ return currentFile()->isCursorOn(tokenIndex);
}
bool CppQuickFixAssistInterface::isCursorOn(const CPlusPlus::AST *ast) const
{
- return currentFile().isCursorOn(ast);
+ return currentFile()->isCursorOn(ast);
}
diff --git a/src/plugins/cppeditor/cppquickfixassistant.h b/src/plugins/cppeditor/cppquickfixassistant.h
index f08a9ea610..44dd5add8e 100644
--- a/src/plugins/cppeditor/cppquickfixassistant.h
+++ b/src/plugins/cppeditor/cppquickfixassistant.h
@@ -44,6 +44,7 @@
namespace CppTools {
class CppRefactoringFile;
+typedef QSharedPointer<CppRefactoringFile> CppRefactoringFilePtr;
}
namespace CppEditor {
@@ -62,7 +63,7 @@ public:
const CPlusPlus::LookupContext &context() const;
CPPEditorWidget *editor() const;
- const CppTools::CppRefactoringFile currentFile() const;
+ CppTools::CppRefactoringFilePtr currentFile() const;
bool isCursorOn(unsigned tokenIndex) const;
bool isCursorOn(const CPlusPlus::AST *ast) const;
@@ -71,6 +72,7 @@ private:
CPPEditorWidget *m_editor;
CppEditor::Internal::SemanticInfo m_semanticInfo;
CPlusPlus::Snapshot m_snapshot;
+ CppTools::CppRefactoringFilePtr m_currentFile;
CPlusPlus::LookupContext m_context;
QList<CPlusPlus::AST *> m_path;
};
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index f5f5b82d5e..c169e32489 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -89,7 +89,7 @@ public:
virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
{
QList<CppQuickFixOperation::Ptr> result;
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
const QList<AST *> &path = interface->path();
int index = path.size() - 1;
@@ -100,7 +100,7 @@ public:
return result;
Kind invertToken;
- switch (file.tokenAt(binary->binary_op_token).kind()) {
+ switch (file->tokenAt(binary->binary_op_token).kind()) {
case T_LESS_EQUAL:
invertToken = T_GREATER;
break;
@@ -153,7 +153,7 @@ private:
// check for ! before parentheses
if (nested && priority - 2 >= 0) {
negation = interface->path()[priority - 2]->asUnaryExpression();
- if (negation && ! interface->currentFile().tokenAt(negation->unary_op_token).is(T_EXCLAIM))
+ if (negation && ! interface->currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM))
negation = 0;
}
}
@@ -163,7 +163,7 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
if (negation) {
@@ -176,7 +176,8 @@ private:
changes.insert(currentFile->endOf(binary), ")");
}
changes.replace(currentFile->range(binary->binary_op_token), replacement);
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
};
};
@@ -197,7 +198,7 @@ public:
{
QList<QuickFixOperation::Ptr> result;
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
@@ -207,7 +208,7 @@ public:
return result;
Kind flipToken;
- switch (file.tokenAt(binary->binary_op_token).kind()) {
+ switch (file->tokenAt(binary->binary_op_token).kind()) {
case T_LESS_EQUAL:
flipToken = T_GREATER_EQUAL;
break;
@@ -262,7 +263,7 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -270,7 +271,8 @@ private:
if (! replacement.isEmpty())
changes.replace(currentFile->range(binary->binary_op_token), replacement);
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
private:
@@ -296,7 +298,7 @@ public:
QList<QuickFixOperation::Ptr> result;
BinaryExpressionAST *expression = 0;
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
int index = path.size() - 1;
for (; index != -1; --index) {
@@ -314,9 +316,9 @@ public:
QSharedPointer<Operation> op(new Operation(interface));
if (expression->match(op->pattern, &matcher) &&
- file.tokenAt(op->pattern->binary_op_token).is(T_AMPER_AMPER) &&
- file.tokenAt(op->left->unary_op_token).is(T_EXCLAIM) &&
- file.tokenAt(op->right->unary_op_token).is(T_EXCLAIM)) {
+ file->tokenAt(op->pattern->binary_op_token).is(T_AMPER_AMPER) &&
+ file->tokenAt(op->left->unary_op_token).is(T_EXCLAIM) &&
+ file->tokenAt(op->right->unary_op_token).is(T_EXCLAIM)) {
op->setDescription(QApplication::translate("CppTools::QuickFix", "Rewrite Condition Using ||"));
op->setPriority(index);
result.append(op);
@@ -343,7 +345,7 @@ private:
pattern = mk->BinaryExpression(left, right);
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
changes.replace(currentFile->range(pattern->binary_op_token), QLatin1String("||"));
@@ -354,8 +356,9 @@ private:
changes.insert(start, QLatin1String("!("));
changes.insert(end, QLatin1String(")"));
- currentFile->change(changes);
- currentFile->indent(currentFile->range(pattern));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(pattern));
+ currentFile->apply();
}
};
@@ -408,7 +411,7 @@ public:
QList<CppQuickFixOperation::Ptr> result;
CoreDeclaratorAST *core_declarator = 0;
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
for (int index = path.size() - 1; index != -1; --index) {
AST *node = path.at(index);
@@ -420,10 +423,10 @@ public:
if (checkDeclaration(simpleDecl)) {
SimpleDeclarationAST *declaration = simpleDecl;
- const int cursorPosition = file.cursor().selectionStart();
+ const int cursorPosition = file->cursor().selectionStart();
- const int startOfDeclSpecifier = file.startOf(declaration->decl_specifier_list->firstToken());
- const int endOfDeclSpecifier = file.endOf(declaration->decl_specifier_list->lastToken() - 1);
+ const int startOfDeclSpecifier = file->startOf(declaration->decl_specifier_list->firstToken());
+ const int endOfDeclSpecifier = file->endOf(declaration->decl_specifier_list->lastToken() - 1);
if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) {
// the AST node under cursor is a specifier.
@@ -455,7 +458,7 @@ private:
"Split Declaration"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -481,8 +484,9 @@ private:
prevDeclarator = declarator;
}
- currentFile->change(changes);
- currentFile->indent(currentFile->range(declaration));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(declaration));
+ currentFile->apply();
}
private:
@@ -547,7 +551,7 @@ private:
"Add Curly Braces"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -557,8 +561,9 @@ private:
const int end = currentFile->endOf(_statement->lastToken() - 1);
changes.insert(end, "\n}");
- currentFile->change(changes);
- currentFile->indent(Utils::ChangeSet::Range(start, end));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(Utils::ChangeSet::Range(start, end));
+ currentFile->apply();
}
private:
@@ -620,7 +625,7 @@ private:
pattern = mk.IfStatement(condition);
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -630,8 +635,9 @@ private:
changes.move(currentFile->range(condition), insertPos);
changes.insert(insertPos, QLatin1String(";\n"));
- currentFile->change(changes);
- currentFile->indent(currentFile->range(pattern));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(pattern));
+ currentFile->apply();
}
ASTMatcher matcher;
@@ -704,7 +710,7 @@ private:
pattern = mk.WhileStatement(condition);
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -717,8 +723,9 @@ private:
changes.copy(currentFile->range(core), insertPos);
changes.insert(insertPos, QLatin1String(";\n"));
- currentFile->change(changes);
- currentFile->indent(currentFile->range(pattern));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(pattern));
+ currentFile->apply();
}
ASTMatcher matcher;
@@ -780,7 +787,7 @@ public:
if (! condition)
return noResult();
- Token binaryToken = interface->currentFile().tokenAt(condition->binary_op_token);
+ Token binaryToken = interface->currentFile()->tokenAt(condition->binary_op_token);
// only accept a chain of ||s or &&s - no mixing
if (! splitKind) {
@@ -815,7 +822,7 @@ private:
"Split if Statement"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
const Token binaryToken = currentFile->tokenAt(condition->binary_op_token);
@@ -825,7 +832,7 @@ private:
splitOrCondition(currentFile);
}
- void splitAndCondition(CppRefactoringFile *currentFile)
+ void splitAndCondition(CppRefactoringFilePtr currentFile)
{
ChangeSet changes;
@@ -838,11 +845,12 @@ private:
changes.remove(lExprEnd, currentFile->startOf(condition->right_expression));
changes.insert(currentFile->endOf(pattern), QLatin1String("\n}"));
- currentFile->change(changes);
- currentFile->indent(currentFile->range(pattern));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(pattern));
+ currentFile->apply();
}
- void splitOrCondition(CppRefactoringFile *currentFile)
+ void splitOrCondition(CppRefactoringFilePtr currentFile)
{
ChangeSet changes;
@@ -866,8 +874,9 @@ private:
const int lExprEnd = currentFile->endOf(condition->left_expression);
changes.remove(lExprEnd, currentFile->startOf(condition->right_expression));
- currentFile->change(changes);
- currentFile->indent(currentFile->range(pattern));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(currentFile->range(pattern));
+ currentFile->apply();
}
private:
@@ -897,7 +906,7 @@ public:
ExpressionAST *literal = 0;
Type type = TypeNone;
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
if (path.isEmpty())
return noResult(); // nothing to do
@@ -906,7 +915,7 @@ public:
if (! literal) {
literal = path.last()->asNumericLiteral();
- if (!literal || !file.tokenAt(literal->asNumericLiteral()->literal_token).is(T_CHAR_LITERAL))
+ if (!literal || !file->tokenAt(literal->asNumericLiteral()->literal_token).is(T_CHAR_LITERAL))
return noResult();
else
type = TypeChar;
@@ -919,7 +928,7 @@ public:
if (call->base_expression) {
if (IdExpressionAST *idExpr = call->base_expression->asIdExpression()) {
if (SimpleNameAST *functionName = idExpr->name->asSimpleName()) {
- const QByteArray id(file.tokenAt(functionName->identifier_token).identifier->chars());
+ const QByteArray id(file->tokenAt(functionName->identifier_token).identifier->chars());
if (id == "QT_TRANSLATE_NOOP" || id == "tr" || id == "trUtf8"
|| (type == TypeString && (id == "QLatin1String" || id == "QLatin1Literal"))
@@ -932,7 +941,7 @@ public:
}
if (type == TypeString) {
- if (file.charAt(file.startOf(literal)) == QLatin1Char('@'))
+ if (file->charAt(file->startOf(literal)) == QLatin1Char('@'))
type = TypeObjCString;
}
return singleResult(new Operation(interface,
@@ -959,7 +968,7 @@ private:
"Enclose in QLatin1String(...)"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -974,7 +983,8 @@ private:
changes.insert(currentFile->endOf(literal), ")");
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
private:
@@ -1019,7 +1029,7 @@ public:
if (call->base_expression) {
if (IdExpressionAST *idExpr = call->base_expression->asIdExpression()) {
if (SimpleNameAST *functionName = idExpr->name->asSimpleName()) {
- const QByteArray id(interface->currentFile().tokenAt(functionName->identifier_token).identifier->chars());
+ const QByteArray id(interface->currentFile()->tokenAt(functionName->identifier_token).identifier->chars());
if (id == "tr" || id == "trUtf8"
|| id == "translate"
@@ -1083,7 +1093,7 @@ private:
setDescription(QApplication::translate("CppTools::QuickFix", "Mark as Translatable"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -1100,7 +1110,8 @@ private:
changes.insert(startPos, replacement);
changes.insert(currentFile->endOf(m_literal), QLatin1String(")"));
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
private:
@@ -1125,7 +1136,7 @@ class CStringToNSString: public CppQuickFixFactory
public:
virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
{
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
if (interface->editor()->mimeType() != CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
return noResult();
@@ -1142,7 +1153,7 @@ public:
if (! stringLiteral)
return noResult();
- else if (file.charAt(file.startOf(stringLiteral)) == QLatin1Char('@'))
+ else if (file->charAt(file->startOf(stringLiteral)) == QLatin1Char('@'))
return noResult(); // it's already an objc string literal.
else if (path.size() > 1) {
@@ -1150,7 +1161,7 @@ public:
if (call->base_expression) {
if (IdExpressionAST *idExpr = call->base_expression->asIdExpression()) {
if (SimpleNameAST *functionName = idExpr->name->asSimpleName()) {
- const QByteArray id(interface->currentFile().tokenAt(functionName->identifier_token).identifier->chars());
+ const QByteArray id(interface->currentFile()->tokenAt(functionName->identifier_token).identifier->chars());
if (id == "QLatin1String" || id == "QLatin1Literal")
qlatin1Call = call;
@@ -1176,7 +1187,7 @@ private:
"Convert to Objective-C String Literal"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
@@ -1187,7 +1198,8 @@ private:
changes.insert(currentFile->startOf(stringLiteral), "@");
}
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
private:
@@ -1222,7 +1234,7 @@ public:
QList<QuickFixOperation::Ptr> result;
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
if (path.isEmpty())
return result; // nothing to do
@@ -1232,7 +1244,7 @@ public:
if (! literal)
return result;
- Token token = file.tokenAt(literal->asNumericLiteral()->literal_token);
+ Token token = file->tokenAt(literal->asNumericLiteral()->literal_token);
if (!token.is(T_NUMERIC_LITERAL))
return result;
const NumericLiteral *numeric = token.number;
@@ -1254,7 +1266,7 @@ public:
return result;
const int priority = path.size() - 1; // very high priority
- const int start = file.startOf(literal);
+ const int start = file->startOf(literal);
const char * const str = numeric->chars();
if (!numeric->isHex()) {
@@ -1328,11 +1340,12 @@ private:
, replacement(replacement)
{}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
{
ChangeSet changes;
changes.replace(start, end, replacement);
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
protected:
@@ -1407,7 +1420,8 @@ private:
"#include Header File"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile,
+ const CppRefactoringChanges &)
{
Q_ASSERT(fwdClass != 0);
@@ -1464,7 +1478,8 @@ private:
Utils::ChangeSet changes;
changes.insert(pos, QString("#include <%1>\n").arg(QFileInfo(best).fileName()));
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
}
@@ -1488,15 +1503,15 @@ public:
virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
{
const QList<AST *> &path = interface->path();
- const CppRefactoringFile &file = interface->currentFile();
+ CppRefactoringFilePtr file = interface->currentFile();
for (int index = path.size() - 1; index != -1; --index) {
if (BinaryExpressionAST *binary = path.at(index)->asBinaryExpression()) {
- if (binary->left_expression && binary->right_expression && file.tokenAt(binary->binary_op_token).is(T_EQUAL)) {
+ if (binary->left_expression && binary->right_expression && file->tokenAt(binary->binary_op_token).is(T_EQUAL)) {
IdExpressionAST *idExpr = binary->left_expression->asIdExpression();
if (interface->isCursorOn(binary->left_expression) && idExpr && idExpr->name->asSimpleName() != 0) {
SimpleNameAST *nameAST = idExpr->name->asSimpleName();
- const QList<LookupItem> results = interface->context().lookup(nameAST->name, file.scopeAt(nameAST->firstToken()));
+ const QList<LookupItem> results = interface->context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken()));
Declaration *decl = 0;
foreach (const LookupItem &r, results) {
if (! r.declaration())
@@ -1531,7 +1546,8 @@ private:
setDescription(QApplication::translate("CppTools::QuickFix", "Add Local Declaration"));
}
- virtual void performChanges(CppRefactoringFile *currentFile, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &currentFile,
+ const CppRefactoringChanges &)
{
TypeOfExpression typeOfExpression;
typeOfExpression.init(assistInterface()->semanticInfo().doc,
@@ -1565,7 +1581,8 @@ private:
Utils::ChangeSet changes;
changes.insert(currentFile->startOf(binaryAST), ty);
- currentFile->change(changes);
+ currentFile->setChangeSet(changes);
+ currentFile->apply();
}
}
}
@@ -1626,7 +1643,8 @@ private:
"Convert to Camel Case"));
}
- virtual void performChanges(CppRefactoringFile *, CppRefactoringChanges *)
+ virtual void performChanges(const CppRefactoringFilePtr &,
+ const CppRefactoringChanges &)
{
for (int i = 1; i < m_name.length(); ++i) {
QCharRef c = m_name[i];