60 "ApplyChanges": self.__applyChanges, |
60 "ApplyChanges": self.__applyChanges, |
61 "ClearChanges": self.__clearChanges, |
61 "ClearChanges": self.__clearChanges, |
62 "CalculateRenameChanges": self.__calculateRenameChanges, |
62 "CalculateRenameChanges": self.__calculateRenameChanges, |
63 "CalculateChangeOccurrencesChanges": |
63 "CalculateChangeOccurrencesChanges": |
64 self.__calculateChangeOccurrencesChanges, |
64 self.__calculateChangeOccurrencesChanges, |
|
65 "CalculateExtractChanges": self.__calculateExtractChanges, |
65 } |
66 } |
66 |
67 |
67 from FileSystemCommands import RefactoringClientFileSystemCommands |
68 from FileSystemCommands import RefactoringClientFileSystemCommands |
68 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
69 self.__fsCommands = RefactoringClientFileSystemCommands(self) |
69 |
70 |
644 |
645 |
645 result["Subcommand"] = "ChangesCalculated" |
646 result["Subcommand"] = "ChangesCalculated" |
646 result.update(errorDict) |
647 result.update(errorDict) |
647 |
648 |
648 self.sendJson("Changes", result) |
649 self.sendJson("Changes", result) |
|
650 |
|
651 def __calculateExtractChanges(self, params): |
|
652 """ |
|
653 Private method to calculate the 'Extract' changes based on the |
|
654 parameters sent by the server. |
|
655 |
|
656 @param params dictionary containing the method parameters sent by |
|
657 the server |
|
658 @type dict |
|
659 """ |
|
660 changeGroup = params["ChangeGroup"] |
|
661 title = params["Title"] |
|
662 filename = params["FileName"] |
|
663 startOffset = params["StartOffset"] |
|
664 endOffset = params["EndOffset"] |
|
665 kind = params["Kind"] |
|
666 newName = params["NewName"] |
|
667 similar = params["Similar"] |
|
668 global_ = params["Global"] |
|
669 |
|
670 errorDict = {} |
|
671 changes = [] |
|
672 result = { |
|
673 "ChangeGroup": changeGroup, |
|
674 "Title": title, |
|
675 } |
|
676 |
|
677 import rope.refactor.extract |
|
678 resource = rope.base.libutils.path_to_resource( |
|
679 self.__project, filename) |
|
680 try: |
|
681 if kind == "variable": |
|
682 extractor = rope.refactor.extract.ExtractVariable( |
|
683 self.__project, resource, startOffset, endOffset) |
|
684 elif kind == "method": |
|
685 extractor = rope.refactor.extract.ExtractMethod( |
|
686 self.__project, resource, startOffset, endOffset) |
|
687 else: |
|
688 raise Exception("Invalid extraction kind <{0}>.".format(kind)) |
|
689 except Exception as err: |
|
690 errorDict = self.__handleRopeError(err) |
|
691 result.update(errorDict) |
|
692 self.sendJson("Changes", result) |
|
693 return |
|
694 |
|
695 try: |
|
696 changes = extractor.get_changes( |
|
697 newName, similar=similar, global_=global_) |
|
698 except Exception as err: |
|
699 errorDict = self.__handleRopeError(err) |
|
700 |
|
701 self.__changes[changeGroup] = changes |
|
702 |
|
703 result["Subcommand"] = "ChangesCalculated" |
|
704 result.update(errorDict) |
|
705 |
|
706 self.sendJson("Changes", result) |
649 |
707 |
650 if __name__ == '__main__': |
708 if __name__ == '__main__': |
651 if len(sys.argv) != 4: |
709 if len(sys.argv) != 4: |
652 print('Host, port and project path parameters are missing. Abort.') |
710 print('Host, port and project path parameters are missing. Abort.') |
653 sys.exit(1) |
711 sys.exit(1) |