RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 180
a33ef7ab8c54
parent 179
8ae4e95f5fa6
child 181
3e3d6de2f0ca
--- a/RefactoringRope/RefactoringClient.py	Sat Sep 23 12:01:48 2017 +0200
+++ b/RefactoringRope/RefactoringClient.py	Sat Sep 23 12:16:59 2017 +0200
@@ -70,6 +70,8 @@
             "CalculateMoveChanges": self.__calculateMoveChanges,
             "RequestUseFunction": self.__requestUseFunction,
             "CalculateUseFunctionChanges": self.__calculateUseFunctionChanges,
+            "CalculateIntroduceFactoryChanges":
+                self.__calculateIntroduceFactoryChanges,
         }
         
         from FileSystemCommands import RefactoringClientFileSystemCommands
@@ -953,6 +955,53 @@
         result.update(errorDict)
         
         self.sendJson("Changes", result)
+    
+    def __calculateIntroduceFactoryChanges(self, params):
+        """
+        Private method to calculate the 'Introduce Factory' changes based on
+        the parameters sent by the server.
+        
+        @param params dictionary containing the method parameters sent by
+            the server
+        @type dict
+        """
+        changeGroup = params["ChangeGroup"]
+        title = params["Title"]
+        filename = params["FileName"]
+        offset = params["Offset"]
+        factoryName = params["Name"]
+        globalFactory = params["GlobalFactory"]
+        
+        errorDict = {}
+        changes = []
+        result = {
+            "ChangeGroup": changeGroup,
+            "Title": title,
+        }
+        
+        import rope.refactor.introduce_factory
+        resource = rope.base.libutils.path_to_resource(
+            self.__project, filename)
+        self.__progressHandle = ProgressHandle(self, title, True)
+        try:
+            introducer = \
+                rope.refactor.introduce_factory.IntroduceFactoryRefactoring(
+                    self.__project, resource, offset)
+            changes = introducer.get_changes(
+                factoryName, global_factory=globalFactory,
+                task_handle=self.__progressHandle)
+        except Exception as err:
+            errorDict = self.__handleRopeError(err)
+        self.__progressHandle.reset()
+        self.__progressHandle = None
+        
+        self.__changes[changeGroup] = changes
+        
+        result["Subcommand"] = "ChangesCalculated"
+        result.update(errorDict)
+        
+        self.sendJson("Changes", result)
+
 
 if __name__ == '__main__':
     if len(sys.argv) != 4:

eric ide

mercurial