Search in sources :

Example 1 with IPyRefactoringRequest

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;
}
Also used : MultiModuleMoveRefactoringRequest(org.python.pydev.ast.refactoring.MultiModuleMoveRefactoringRequest) RefactoringRequest(org.python.pydev.ast.refactoring.RefactoringRequest) MultiModuleMoveRefactoringRequest(org.python.pydev.ast.refactoring.MultiModuleMoveRefactoringRequest) ModuleRenameRefactoringRequest(org.python.pydev.ast.refactoring.ModuleRenameRefactoringRequest) PyRefactoringRequest(org.python.pydev.ast.refactoring.PyRefactoringRequest) IPyRefactoringRequest(org.python.pydev.ast.refactoring.IPyRefactoringRequest) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) Definition(org.python.pydev.ast.codecompletion.revisited.visitors.Definition) IPyRefactoring(org.python.pydev.ast.refactoring.IPyRefactoring) IOException(java.io.IOException) IOException(java.io.IOException) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) ModuleRenameRefactoringRequest(org.python.pydev.ast.refactoring.ModuleRenameRefactoringRequest) PyRenameEntryPoint(com.python.pydev.analysis.refactoring.wizards.rename.PyRenameEntryPoint) PyRefactoringRequest(org.python.pydev.ast.refactoring.PyRefactoringRequest) IPyRefactoringRequest(org.python.pydev.ast.refactoring.IPyRefactoringRequest) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Aggregations

PyRenameEntryPoint (com.python.pydev.analysis.refactoring.wizards.rename.PyRenameEntryPoint)1 IOException (java.io.IOException)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)1 Definition (org.python.pydev.ast.codecompletion.revisited.visitors.Definition)1 ItemPointer (org.python.pydev.ast.item_pointer.ItemPointer)1 IPyRefactoring (org.python.pydev.ast.refactoring.IPyRefactoring)1 IPyRefactoringRequest (org.python.pydev.ast.refactoring.IPyRefactoringRequest)1 ModuleRenameRefactoringRequest (org.python.pydev.ast.refactoring.ModuleRenameRefactoringRequest)1 MultiModuleMoveRefactoringRequest (org.python.pydev.ast.refactoring.MultiModuleMoveRefactoringRequest)1 PyRefactoringRequest (org.python.pydev.ast.refactoring.PyRefactoringRequest)1 RefactoringRequest (org.python.pydev.ast.refactoring.RefactoringRequest)1