RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 178
70b4fb448811
parent 176
117d86025a5c
child 179
8ae4e95f5fa6
equal deleted inserted replaced
177:963fc1b0ba6e 178:70b4fb448811
63 "CalculateChangeOccurrencesChanges": 63 "CalculateChangeOccurrencesChanges":
64 self.__calculateChangeOccurrencesChanges, 64 self.__calculateChangeOccurrencesChanges,
65 "CalculateExtractChanges": self.__calculateExtractChanges, 65 "CalculateExtractChanges": self.__calculateExtractChanges,
66 "RequestInlineType": self.__requestInlineType, 66 "RequestInlineType": self.__requestInlineType,
67 "CalculateInlineChanges": self.__calculateInlineChanges, 67 "CalculateInlineChanges": self.__calculateInlineChanges,
68 "RequestMoveType": self.__requestMoveType,
69 "CalculateMoveChanges": self.__calculateMoveChanges,
68 } 70 }
69 71
70 from FileSystemCommands import RefactoringClientFileSystemCommands 72 from FileSystemCommands import RefactoringClientFileSystemCommands
71 self.__fsCommands = RefactoringClientFileSystemCommands(self) 73 self.__fsCommands = RefactoringClientFileSystemCommands(self)
72 74
724 726
725 self.sendJson("Changes", result) 727 self.sendJson("Changes", result)
726 728
727 def __calculateInlineChanges(self, params): 729 def __calculateInlineChanges(self, params):
728 """ 730 """
729 Private method to calculate the 'Extract' changes based on the 731 Private method to calculate the 'Inline' changes based on the
730 parameters sent by the server. 732 parameters sent by the server.
731 733
732 @param params dictionary containing the method parameters sent by 734 @param params dictionary containing the method parameters sent by
733 the server 735 the server
734 @type dict 736 @type dict
774 776
775 result["Subcommand"] = "ChangesCalculated" 777 result["Subcommand"] = "ChangesCalculated"
776 result.update(errorDict) 778 result.update(errorDict)
777 779
778 self.sendJson("Changes", result) 780 self.sendJson("Changes", result)
781
782 def __requestMoveType(self, params):
783 """
784 Private method to determine the 'Move Method' changes type based on the
785 parameters sent by the server.
786
787 @param params dictionary containing the method parameters sent by
788 the server
789 @type dict
790 """
791 changeGroup = params["ChangeGroup"]
792 title = params["Title"]
793 filename = params["FileName"]
794 offset = params["Offset"]
795
796 errorDict = {}
797 result = {
798 "Subcommand": "MoveType",
799 "ChangeGroup": changeGroup,
800 "Title": title,
801 }
802
803 import rope.refactor.move
804 resource = rope.base.libutils.path_to_resource(
805 self.__project, filename)
806 try:
807 mover = rope.refactor.move.create_move(
808 self.__project, resource, offset)
809 if isinstance(mover, rope.refactor.move.MoveGlobal):
810 result.update({
811 "Kind": "move_global_method",
812 "Method": "",
813 })
814 else:
815 result.update({
816 "Kind": "move_method",
817 "Method": mover.get_method_name(),
818 })
819 except Exception as err:
820 errorDict = self.__handleRopeError(err)
821
822 result.update(errorDict)
823
824 self.sendJson("Changes", result)
825
826 def __calculateMoveChanges(self, params):
827 """
828 Private method to calculate the 'Move ...' changes based on the
829 parameters sent by the server.
830
831 @param params dictionary containing the method parameters sent by
832 the server
833 @type dict
834 """
835 changeGroup = params["ChangeGroup"]
836 title = params["Title"]
837 filename = params["FileName"]
838 offset = params["Offset"]
839 kind = params["Kind"]
840 newName = params["NewName"]
841 attribute = params["Attribute"]
842 destination = params["DestinationModule"]
843
844 errorDict = {}
845 changes = []
846 result = {
847 "ChangeGroup": changeGroup,
848 "Title": title,
849 }
850
851 import rope.refactor.move
852 resource = rope.base.libutils.path_to_resource(
853 self.__project, filename)
854 from ProgressHandle import ProgressHandle
855 self.__progressHandle = ProgressHandle(self, title, True)
856 try:
857 mover = rope.refactor.move.create_move(
858 self.__project, resource, offset)
859 if kind == "move_method":
860 changes = mover.get_changes(
861 attribute, newName, task_handle=self.__progressHandle)
862 else:
863 if kind == "move_global_method":
864 dest = self.__project.get_pycore().find_module(
865 os.path.splitext(destination)[0])
866 else:
867 # move_module
868 if destination.endswith(os.sep):
869 destination = destination[:-1]
870 dest = self.__project.get_pycore().find_module(
871 destination)
872 changes = mover.get_changes(
873 dest, task_handle=self.__progressHandle)
874 except Exception as err:
875 errorDict = self.__handleRopeError(err)
876 self.__progressHandle.reset()
877 self.__progressHandle = None
878
879 self.__changes[changeGroup] = changes
880
881 result["Subcommand"] = "ChangesCalculated"
882 result.update(errorDict)
883
884 self.sendJson("Changes", result)
779 885
780 if __name__ == '__main__': 886 if __name__ == '__main__':
781 if len(sys.argv) != 4: 887 if len(sys.argv) != 4:
782 print('Host, port and project path parameters are missing. Abort.') 888 print('Host, port and project path parameters are missing. Abort.')
783 sys.exit(1) 889 sys.exit(1)

eric ide

mercurial