From ca5076e5ae84931a5cc7bd157171ace7c0a2ff7c Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Thu, 12 Aug 2010 11:41:15 +0200
Subject: [PATCH] QuickFix: Don't separate createChanges from perform.

This will allow a more efficient and direct implementation.
---
 src/plugins/cppeditor/cppdeclfromdef.cpp      |  3 +-
 src/plugins/cppeditor/cppquickfixes.cpp       | 48 ++++++++++++-------
 .../qmljscomponentfromobjectdef.cpp           |  3 +-
 src/plugins/qmljseditor/qmljsquickfixes.cpp   |  3 +-
 src/plugins/texteditor/quickfix.cpp           |  6 ---
 src/plugins/texteditor/quickfix.h             |  7 +--
 6 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/plugins/cppeditor/cppdeclfromdef.cpp b/src/plugins/cppeditor/cppdeclfromdef.cpp
index d0ce92ce03e..73e1628d5c7 100644
--- a/src/plugins/cppeditor/cppdeclfromdef.cpp
+++ b/src/plugins/cppeditor/cppdeclfromdef.cpp
@@ -82,7 +82,7 @@ public:
                                             "CppEditor::DeclFromDef").arg(type));
     }
 
-    void createChanges()
+    void perform()
     {
         CppRefactoringChanges *changes = refactoringChanges();
 
@@ -101,6 +101,7 @@ public:
         targetFile.indent(Utils::ChangeSet::Range(targetPosition2, targetPosition1));
 
         changes->setActiveEditor(m_targetFileName, targetPosition1);
+        changes->apply();
     }
 
 private:
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index c2c33eaa173..cc19c04ab26 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -148,7 +148,7 @@ private:
             return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
             if (negation) {
@@ -162,6 +162,7 @@ private:
             }
             changes.replace(range(binary->binary_op_token), replacement);
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
     };
 };
@@ -243,7 +244,7 @@ private:
                 return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -252,6 +253,7 @@ private:
                 changes.replace(range(binary->binary_op_token), replacement);
 
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
 
     private:
@@ -321,7 +323,7 @@ private:
             pattern = mk->BinaryExpression(left, right);
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
             changes.replace(range(pattern->binary_op_token), QLatin1String("||"));
@@ -334,6 +336,7 @@ private:
 
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(pattern));
+            refactoringChanges()->apply();
         }
     };
 
@@ -422,7 +425,7 @@ private:
                                                    "Split Declaration"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -450,6 +453,7 @@ private:
 
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(declaration));
+            refactoringChanges()->apply();
         }
 
     private:
@@ -505,7 +509,7 @@ private:
                                                    "Add Curly Braces"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -517,6 +521,7 @@ private:
 
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(start, end));
+            refactoringChanges()->apply();
         }
 
     private:
@@ -576,7 +581,7 @@ private:
             pattern = mk.IfStatement(condition);
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -588,6 +593,7 @@ private:
 
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(pattern));
+            refactoringChanges()->apply();
         }
 
         ASTMatcher matcher;
@@ -658,7 +664,7 @@ private:
             pattern = mk.WhileStatement(condition);
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -673,6 +679,7 @@ private:
 
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(pattern));
+            refactoringChanges()->apply();
         }
 
         ASTMatcher matcher;
@@ -767,7 +774,7 @@ private:
                                                    "Split if Statement"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             const Token binaryToken = state().tokenAt(condition->binary_op_token);
 
@@ -775,6 +782,7 @@ private:
                 splitAndCondition();
             else
                 splitOrCondition();
+            refactoringChanges()->apply();
         }
 
         void splitAndCondition()
@@ -905,7 +913,7 @@ private:
                                                        "Enclose in QLatin1String(...)"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -921,6 +929,7 @@ private:
             changes.insert(endOf(literal), ")");
 
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
 
     private:
@@ -1026,7 +1035,7 @@ private:
             setDescription(QApplication::translate("CppTools::QuickFix", "Mark as translateable"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -1044,6 +1053,7 @@ private:
             changes.insert(endOf(m_literal), QLatin1String(")"));
 
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
 
     private:
@@ -1107,7 +1117,7 @@ private:
                                                    "Convert to Objective-C String Literal"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
 
@@ -1119,6 +1129,7 @@ private:
             }
 
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
 
     private:
@@ -1255,11 +1266,12 @@ private:
             , replacement(replacement)
         {}
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
             changes.replace(start, end, replacement);
             refactoringChanges()->changeFile(fileName(), changes);
+            refactoringChanges()->apply();
         }
 
     protected:
@@ -1409,7 +1421,7 @@ private:
         }
 
 
-        virtual void createChanges()
+        virtual void perform()
         {
             ChangeSet changes;
             int start = endOf(compoundStatement->lbrace_token);
@@ -1418,6 +1430,7 @@ private:
                            + QLatin1String(":\nbreak;"));
             refactoringChanges()->changeFile(fileName(), changes);
             refactoringChanges()->reindent(fileName(), range(compoundStatement));
+            refactoringChanges()->apply();
         }
 
         CompoundStatementAST *compoundStatement;
@@ -1485,7 +1498,7 @@ private:
                                                    "#include header file"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             Q_ASSERT(fwdClass != 0);
 
@@ -1544,6 +1557,7 @@ private:
                 changes.insert(pos, QString("#include <%1>\n").arg(QFileInfo(best).fileName()));
                 refactoringChanges()->changeFile(fileName(), changes);
             }
+            refactoringChanges()->apply();
         }
 
     private:
@@ -1599,7 +1613,7 @@ private:
             setDescription(QApplication::translate("CppTools::QuickFix", "Add local declaration"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             TypeOfExpression typeOfExpression;
             typeOfExpression.init(state().document(), state().snapshot(), state().context().bindings());
@@ -1631,6 +1645,7 @@ private:
                     refactoringChanges()->changeFile(fileName(), changes);
                 }
             }
+            refactoringChanges()->apply();
         }
 
     private:
@@ -1687,7 +1702,7 @@ private:
                                                    "Convert to Camel Case ..."));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             for (int i = 1; i < m_name.length(); ++i) {
                 QCharRef c = m_name[i];
@@ -1700,6 +1715,7 @@ private:
                 }
             }
             static_cast<CppEditor::Internal::CPPEditor*>(state().editor())->renameUsagesNow(m_name);
+            refactoringChanges()->apply();
         }
 
         static bool isConvertibleUnderscore(const QString &name, int pos)
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index 053e6ac8a66..f6ba8a2b1f3 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -92,7 +92,7 @@ public:
                                                    "Move Component into '%1.qml'").arg(m_componentName));
     }
 
-    virtual void createChanges()
+    virtual void perform()
     {
         const QString newFileName = QFileInfo(fileName()).path()
                 + QDir::separator() + m_componentName + QLatin1String(".qml");
@@ -117,6 +117,7 @@ public:
 
         refactoringChanges()->createFile(newFileName, txt);
         refactoringChanges()->reindent(newFileName, range(0, txt.length() - 1));
+        refactoringChanges()->apply();
     }
 };
 
diff --git a/src/plugins/qmljseditor/qmljsquickfixes.cpp b/src/plugins/qmljseditor/qmljsquickfixes.cpp
index ef272dc4515..9aaf194eead 100644
--- a/src/plugins/qmljseditor/qmljsquickfixes.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfixes.cpp
@@ -88,7 +88,7 @@ private:
                                                    "Split initializer"));
         }
 
-        virtual void createChanges()
+        virtual void perform()
         {
             Q_ASSERT(_objectInitializer != 0);
 
@@ -112,6 +112,7 @@ private:
             file.indent(range(startPosition(_objectInitializer->lbraceToken),
                               startPosition(_objectInitializer->rbraceToken)));
 
+            refactoringChanges()->apply();
         }
     };
 };
diff --git a/src/plugins/texteditor/quickfix.cpp b/src/plugins/texteditor/quickfix.cpp
index a9d18f141c3..31baf34519b 100644
--- a/src/plugins/texteditor/quickfix.cpp
+++ b/src/plugins/texteditor/quickfix.cpp
@@ -123,12 +123,6 @@ void QuickFixOperation::setDescription(const QString &description)
     _description = description;
 }
 
-void QuickFixOperation::perform()
-{
-    createChanges();
-    refactoringChanges()->apply();
-}
-
 QuickFixFactory::QuickFixFactory(QObject *parent)
     : QObject(parent)
 {
diff --git a/src/plugins/texteditor/quickfix.h b/src/plugins/texteditor/quickfix.h
index 51b604ffe39..b3bdd540f4a 100644
--- a/src/plugins/texteditor/quickfix.h
+++ b/src/plugins/texteditor/quickfix.h
@@ -136,15 +136,10 @@ public:
     /*!
         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
         RefactoringChanges.
      */
-    virtual void createChanges() = 0;
+    virtual void perform() = 0;
 
 protected:
     virtual TextEditor::RefactoringChanges *refactoringChanges() const = 0;
-- 
GitLab