use of org.python.pydev.ast.refactoring.IPyRefactoringRequest in project Pydev by fabioz.
the class PyRenameRefactoring method rename.
public static String rename(IPyRefactoringRequest request) {
try {
List<RefactoringRequest> actualRequests = request.getRequests();
if (actualRequests.size() == 1) {
RefactoringRequest req = actualRequests.get(0);
// Note: if it's already a ModuleRenameRefactoringRequest, no need to change anything.
if (!(req.isModuleRenameRefactoringRequest())) {
// Note: if we're renaming an import, we must change to the appropriate req
IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
ItemPointer[] pointers = pyRefactoring.findDefinition(req);
for (ItemPointer pointer : pointers) {
Definition definition = pointer.definition;
if (RefactorProcessFactory.isModuleRename(definition)) {
try {
request = new PyRefactoringRequest(new ModuleRenameRefactoringRequest(definition.module.getFile(), req.nature, null));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}
PyRenameEntryPoint entryPoint = new PyRenameEntryPoint(request);
RenameRefactoring renameRefactoring = new RenameRefactoring(entryPoint);
request.fillActivationTokenAndQualifier();
String title = "Rename";
if (request instanceof MultiModuleMoveRefactoringRequest) {
MultiModuleMoveRefactoringRequest multiModuleMoveRefactoringRequest = (MultiModuleMoveRefactoringRequest) request;
title = "Move To package (project: " + multiModuleMoveRefactoringRequest.getTarget().getProject().getName() + ")";
}
final PyRenameRefactoringWizard wizard = new PyRenameRefactoringWizard(renameRefactoring, title, "inputPageDescription", request);
try {
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
op.run(EditorUtils.getShell(), "Rename Refactor Action");
} catch (InterruptedException e) {
// do nothing. User action got cancelled
}
} catch (Exception e) {
Log.log(e);
}
return null;
}
Aggregations