Commit ca5076e5 authored by Christian Kamm's avatar Christian Kamm
Browse files

QuickFix: Don't separate createChanges from perform.

This will allow a more efficient and direct implementation.
parent 235f4d1d
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
"CppEditor::DeclFromDef").arg(type)); "CppEditor::DeclFromDef").arg(type));
} }
void createChanges() void perform()
{ {
CppRefactoringChanges *changes = refactoringChanges(); CppRefactoringChanges *changes = refactoringChanges();
...@@ -101,6 +101,7 @@ public: ...@@ -101,6 +101,7 @@ public:
targetFile.indent(Utils::ChangeSet::Range(targetPosition2, targetPosition1)); targetFile.indent(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
changes->setActiveEditor(m_targetFileName, targetPosition1); changes->setActiveEditor(m_targetFileName, targetPosition1);
changes->apply();
} }
private: private:
......
...@@ -148,7 +148,7 @@ private: ...@@ -148,7 +148,7 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement); return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
if (negation) { if (negation) {
...@@ -162,6 +162,7 @@ private: ...@@ -162,6 +162,7 @@ private:
} }
changes.replace(range(binary->binary_op_token), replacement); changes.replace(range(binary->binary_op_token), replacement);
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
}; };
}; };
...@@ -243,7 +244,7 @@ private: ...@@ -243,7 +244,7 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement); return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -252,6 +253,7 @@ private: ...@@ -252,6 +253,7 @@ private:
changes.replace(range(binary->binary_op_token), replacement); changes.replace(range(binary->binary_op_token), replacement);
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
private: private:
...@@ -321,7 +323,7 @@ private: ...@@ -321,7 +323,7 @@ private:
pattern = mk->BinaryExpression(left, right); pattern = mk->BinaryExpression(left, right);
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
changes.replace(range(pattern->binary_op_token), QLatin1String("||")); changes.replace(range(pattern->binary_op_token), QLatin1String("||"));
...@@ -334,6 +336,7 @@ private: ...@@ -334,6 +336,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(pattern)); refactoringChanges()->reindent(fileName(), range(pattern));
refactoringChanges()->apply();
} }
}; };
...@@ -422,7 +425,7 @@ private: ...@@ -422,7 +425,7 @@ private:
"Split Declaration")); "Split Declaration"));
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -450,6 +453,7 @@ private: ...@@ -450,6 +453,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(declaration)); refactoringChanges()->reindent(fileName(), range(declaration));
refactoringChanges()->apply();
} }
private: private:
...@@ -505,7 +509,7 @@ private: ...@@ -505,7 +509,7 @@ private:
"Add Curly Braces")); "Add Curly Braces"));
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -517,6 +521,7 @@ private: ...@@ -517,6 +521,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(start, end)); refactoringChanges()->reindent(fileName(), range(start, end));
refactoringChanges()->apply();
} }
private: private:
...@@ -576,7 +581,7 @@ private: ...@@ -576,7 +581,7 @@ private:
pattern = mk.IfStatement(condition); pattern = mk.IfStatement(condition);
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -588,6 +593,7 @@ private: ...@@ -588,6 +593,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(pattern)); refactoringChanges()->reindent(fileName(), range(pattern));
refactoringChanges()->apply();
} }
ASTMatcher matcher; ASTMatcher matcher;
...@@ -658,7 +664,7 @@ private: ...@@ -658,7 +664,7 @@ private:
pattern = mk.WhileStatement(condition); pattern = mk.WhileStatement(condition);
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -673,6 +679,7 @@ private: ...@@ -673,6 +679,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(pattern)); refactoringChanges()->reindent(fileName(), range(pattern));
refactoringChanges()->apply();
} }
ASTMatcher matcher; ASTMatcher matcher;
...@@ -767,7 +774,7 @@ private: ...@@ -767,7 +774,7 @@ private:
"Split if Statement")); "Split if Statement"));
} }
virtual void createChanges() virtual void perform()
{ {
const Token binaryToken = state().tokenAt(condition->binary_op_token); const Token binaryToken = state().tokenAt(condition->binary_op_token);
...@@ -775,6 +782,7 @@ private: ...@@ -775,6 +782,7 @@ private:
splitAndCondition(); splitAndCondition();
else else
splitOrCondition(); splitOrCondition();
refactoringChanges()->apply();
} }
void splitAndCondition() void splitAndCondition()
...@@ -905,7 +913,7 @@ private: ...@@ -905,7 +913,7 @@ private:
"Enclose in QLatin1String(...)")); "Enclose in QLatin1String(...)"));
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -921,6 +929,7 @@ private: ...@@ -921,6 +929,7 @@ private:
changes.insert(endOf(literal), ")"); changes.insert(endOf(literal), ")");
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
private: private:
...@@ -1026,7 +1035,7 @@ private: ...@@ -1026,7 +1035,7 @@ private:
setDescription(QApplication::translate("CppTools::QuickFix", "Mark as translateable")); setDescription(QApplication::translate("CppTools::QuickFix", "Mark as translateable"));
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -1044,6 +1053,7 @@ private: ...@@ -1044,6 +1053,7 @@ private:
changes.insert(endOf(m_literal), QLatin1String(")")); changes.insert(endOf(m_literal), QLatin1String(")"));
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
private: private:
...@@ -1107,7 +1117,7 @@ private: ...@@ -1107,7 +1117,7 @@ private:
"Convert to Objective-C String Literal")); "Convert to Objective-C String Literal"));
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
...@@ -1119,6 +1129,7 @@ private: ...@@ -1119,6 +1129,7 @@ private:
} }
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
private: private:
...@@ -1255,11 +1266,12 @@ private: ...@@ -1255,11 +1266,12 @@ private:
, replacement(replacement) , replacement(replacement)
{} {}
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
changes.replace(start, end, replacement); changes.replace(start, end, replacement);
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->apply();
} }
protected: protected:
...@@ -1409,7 +1421,7 @@ private: ...@@ -1409,7 +1421,7 @@ private:
} }
virtual void createChanges() virtual void perform()
{ {
ChangeSet changes; ChangeSet changes;
int start = endOf(compoundStatement->lbrace_token); int start = endOf(compoundStatement->lbrace_token);
...@@ -1418,6 +1430,7 @@ private: ...@@ -1418,6 +1430,7 @@ private:
+ QLatin1String(":\nbreak;")); + QLatin1String(":\nbreak;"));
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
refactoringChanges()->reindent(fileName(), range(compoundStatement)); refactoringChanges()->reindent(fileName(), range(compoundStatement));
refactoringChanges()->apply();
} }
CompoundStatementAST *compoundStatement; CompoundStatementAST *compoundStatement;
...@@ -1485,7 +1498,7 @@ private: ...@@ -1485,7 +1498,7 @@ private:
"#include header file")); "#include header file"));
} }
virtual void createChanges() virtual void perform()
{ {
Q_ASSERT(fwdClass != 0); Q_ASSERT(fwdClass != 0);
...@@ -1544,6 +1557,7 @@ private: ...@@ -1544,6 +1557,7 @@ private:
changes.insert(pos, QString("#include <%1>\n").arg(QFileInfo(best).fileName())); changes.insert(pos, QString("#include <%1>\n").arg(QFileInfo(best).fileName()));
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
} }
refactoringChanges()->apply();
} }
private: private:
...@@ -1599,7 +1613,7 @@ private: ...@@ -1599,7 +1613,7 @@ private:
setDescription(QApplication::translate("CppTools::QuickFix", "Add local declaration")); setDescription(QApplication::translate("CppTools::QuickFix", "Add local declaration"));
} }
virtual void createChanges() virtual void perform()
{ {
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(state().document(), state().snapshot(), state().context().bindings()); typeOfExpression.init(state().document(), state().snapshot(), state().context().bindings());
...@@ -1631,6 +1645,7 @@ private: ...@@ -1631,6 +1645,7 @@ private:
refactoringChanges()->changeFile(fileName(), changes); refactoringChanges()->changeFile(fileName(), changes);
} }
} }
refactoringChanges()->apply();
} }
private: private:
...@@ -1687,7 +1702,7 @@ private: ...@@ -1687,7 +1702,7 @@ private:
"Convert to Camel Case ...")); "Convert to Camel Case ..."));
} }
virtual void createChanges() virtual void perform()
{ {
for (int i = 1; i < m_name.length(); ++i) { for (int i = 1; i < m_name.length(); ++i) {
QCharRef c = m_name[i]; QCharRef c = m_name[i];
...@@ -1700,6 +1715,7 @@ private: ...@@ -1700,6 +1715,7 @@ private:
} }
} }
static_cast<CppEditor::Internal::CPPEditor*>(state().editor())->renameUsagesNow(m_name); static_cast<CppEditor::Internal::CPPEditor*>(state().editor())->renameUsagesNow(m_name);
refactoringChanges()->apply();
} }
static bool isConvertibleUnderscore(const QString &name, int pos) static bool isConvertibleUnderscore(const QString &name, int pos)
......
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
"Move Component into '%1.qml'").arg(m_componentName)); "Move Component into '%1.qml'").arg(m_componentName));
} }
virtual void createChanges() virtual void perform()
{ {
const QString newFileName = QFileInfo(fileName()).path() const QString newFileName = QFileInfo(fileName()).path()
+ QDir::separator() + m_componentName + QLatin1String(".qml"); + QDir::separator() + m_componentName + QLatin1String(".qml");
...@@ -117,6 +117,7 @@ public: ...@@ -117,6 +117,7 @@ public:
refactoringChanges()->createFile(newFileName, txt); refactoringChanges()->createFile(newFileName, txt);
refactoringChanges()->reindent(newFileName, range(0, txt.length() - 1)); refactoringChanges()->reindent(newFileName, range(0, txt.length() - 1));
refactoringChanges()->apply();
} }
}; };
......
...@@ -88,7 +88,7 @@ private: ...@@ -88,7 +88,7 @@ private:
"Split initializer")); "Split initializer"));
} }
virtual void createChanges() virtual void perform()
{ {
Q_ASSERT(_objectInitializer != 0); Q_ASSERT(_objectInitializer != 0);
...@@ -112,6 +112,7 @@ private: ...@@ -112,6 +112,7 @@ private:
file.indent(range(startPosition(_objectInitializer->lbraceToken), file.indent(range(startPosition(_objectInitializer->lbraceToken),
startPosition(_objectInitializer->rbraceToken))); startPosition(_objectInitializer->rbraceToken)));
refactoringChanges()->apply();
} }
}; };
}; };
......
...@@ -123,12 +123,6 @@ void QuickFixOperation::setDescription(const QString &description) ...@@ -123,12 +123,6 @@ void QuickFixOperation::setDescription(const QString &description)
_description = description; _description = description;
} }
void QuickFixOperation::perform()
{
createChanges();
refactoringChanges()->apply();
}
QuickFixFactory::QuickFixFactory(QObject *parent) QuickFixFactory::QuickFixFactory(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
......
...@@ -136,15 +136,10 @@ public: ...@@ -136,15 +136,10 @@ public:
/*! /*!
Perform this quick-fix's operation. Perform this quick-fix's operation.
This implementation will call perform and then RefactoringChanges::apply() .
*/
virtual void perform();
/*!
Subclasses should implement this method to do the actual changes by using the Subclasses should implement this method to do the actual changes by using the
RefactoringChanges. RefactoringChanges.
*/ */
virtual void createChanges() = 0; virtual void perform() = 0;
protected: protected:
virtual TextEditor::RefactoringChanges *refactoringChanges() const = 0; virtual TextEditor::RefactoringChanges *refactoringChanges() const = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment