RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 184
4a806271f0b9
parent 183
bac69c80d5f4
child 185
3336637a673b
equal deleted inserted replaced
183:bac69c80d5f4 184:4a806271f0b9
74 self.__calculateIntroduceFactoryChanges, 74 self.__calculateIntroduceFactoryChanges,
75 "CalculateIntroduceParameterChanges": 75 "CalculateIntroduceParameterChanges":
76 self.__calculateIntroduceParameterChanges, 76 self.__calculateIntroduceParameterChanges,
77 "CalculateImportsChanges": self.__calculateImportsChanges, 77 "CalculateImportsChanges": self.__calculateImportsChanges,
78 "CalculateRestructureChanges": self.__calculateRestructureChanges, 78 "CalculateRestructureChanges": self.__calculateRestructureChanges,
79 "RequestSignature": self.__requestSignature,
80 "CalculateSignatureChanges": self.__calculateSignatureChanges,
79 } 81 }
80 82
81 from FileSystemCommands import RefactoringClientFileSystemCommands 83 from FileSystemCommands import RefactoringClientFileSystemCommands
82 self.__fsCommands = RefactoringClientFileSystemCommands(self) 84 self.__fsCommands = RefactoringClientFileSystemCommands(self)
83 85
1142 1144
1143 result["Subcommand"] = "ChangesCalculated" 1145 result["Subcommand"] = "ChangesCalculated"
1144 result.update(errorDict) 1146 result.update(errorDict)
1145 1147
1146 self.sendJson("Changes", result) 1148 self.sendJson("Changes", result)
1149
1150 def __requestSignature(self, params):
1151 """
1152 Private method to calculate the 'Signature' based on the parameters
1153 sent by the server.
1154
1155 @param params dictionary containing the method parameters sent by
1156 the server
1157 @type dict
1158 """
1159 changeGroup = params["ChangeGroup"]
1160 title = params["Title"]
1161 filename = params["FileName"]
1162 offset = params["Offset"]
1163
1164 errorDict = {}
1165 result = {
1166 "Subcommand": "Signature",
1167 "ChangeGroup": changeGroup,
1168 "Title": title,
1169 }
1170
1171 import rope.refactor.change_signature
1172 resource = rope.base.libutils.path_to_resource(
1173 self.__project, filename)
1174 try:
1175 changer = rope.refactor.change_signature.ChangeSignature(
1176 self.__project, resource, offset)
1177 result["DefinitionInfo"] = changer.get_args()
1178 except Exception as err:
1179 errorDict = self.__handleRopeError(err)
1180
1181 result.update(errorDict)
1182
1183 self.sendJson("Changes", result)
1184
1185 def __calculateSignatureChanges(self, params):
1186 """
1187 Private method to calculate the 'Signature' changes based on the
1188 parameters sent by the server.
1189
1190 @param params dictionary containing the method parameters sent by
1191 the server
1192 @type dict
1193 """
1194 changeGroup = params["ChangeGroup"]
1195 title = params["Title"]
1196 filename = params["FileName"]
1197 offset = params["Offset"]
1198 removals = params["Removals"]
1199 additions = params["Additions"]
1200 newOrdering = params["Ordering"]
1201 autodef = params["AutoDef"]
1202 doHierarchy = params["Hierarchy"]
1203
1204 errorDict = {}
1205 result = {
1206 "Subcommand": "Signature",
1207 "ChangeGroup": changeGroup,
1208 "Title": title,
1209 }
1210
1211 changers = []
1212 import rope.refactor.change_signature
1213 # removals
1214 for index in removals:
1215 remover = rope.refactor.change_signature.ArgumentRemover(index)
1216 changers.append(remover)
1217 # additions
1218 for index, name, default, value in additions:
1219 adder = rope.refactor.change_signature.ArgumentAdder(
1220 index, name, default, value)
1221 changers.append(adder)
1222 # new ordering
1223 changers.append(rope.refactor.change_signature.ArgumentReorderer(
1224 newOrdering, autodef=autodef))
1225
1226 resource = rope.base.libutils.path_to_resource(
1227 self.__project, filename)
1228 self.__progressHandle = ProgressHandle(self, title, True)
1229 try:
1230 changer = rope.refactor.change_signature.ChangeSignature(
1231 self.__project, resource, offset)
1232 changes = changer.get_changes(
1233 changers, in_hierarchy=doHierarchy,
1234 task_handle=self.__progressHandle)
1235 except Exception as err:
1236 errorDict = self.__handleRopeError(err)
1237 self.__progressHandle.reset()
1238 self.__progressHandle = None
1239
1240 self.__changes[changeGroup] = changes
1241
1242 result["Subcommand"] = "ChangesCalculated"
1243 result.update(errorDict)
1244
1245 self.sendJson("Changes", result)
1147 1246
1148 1247
1149 if __name__ == '__main__': 1248 if __name__ == '__main__':
1150 if len(sys.argv) != 4: 1249 if len(sys.argv) != 4:
1151 print('Host, port and project path parameters are missing. Abort.') 1250 print('Host, port and project path parameters are missing. Abort.')

eric ide

mercurial