Search in sources :

Example 1 with PyCompositeChange

use of com.python.pydev.analysis.refactoring.changes.PyCompositeChange in project Pydev by fabioz.

the class PyRenameEntryPoint method createChange.

/**
 * Change is actually already created in this stage.
 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (this.fRequest.isModuleRenameRefactoringRequest() && this.fRequest.getSimpleResourceRename() && this.fRequest.getIFileResource() != null) {
        IFile targetFile = this.fRequest.getIFileResource();
        return new RenameResourceChange(targetFile.getFullPath(), fRequest.getInputName());
    }
    PyCompositeChange finalChange;
    List<RefactoringRequest> requests = fRequest.getRequests();
    if (requests.size() == 1) {
        RefactoringRequest request = requests.get(0);
        boolean makeUndo = !(request.isModuleRenameRefactoringRequest());
        finalChange = new PyCompositeChange("RenameChange: '" + request.qualifier + "' to '" + request.inputName + "'", makeUndo);
    } else {
        boolean makeUndo = false;
        finalChange = new PyCompositeChange("Move: " + requests.size() + " resources to '" + fRequest.getInputName() + "'", makeUndo);
    }
    Collections.sort(allChanges, new Comparator<Change>() {

        @Override
        public int compare(Change o1, Change o2) {
            if (o1.getClass() != o2.getClass()) {
                if (o1 instanceof PyRenameResourceChange) {
                    // The rename changes must be the last ones (all the text-related changes must be done already).
                    return 1;
                }
                if (o2 instanceof PyRenameResourceChange) {
                    return -1;
                }
            }
            return o1.getName().compareTo(o2.getName());
        }
    });
    finalChange.addAll(allChanges.toArray(new Change[allChanges.size()]));
    return finalChange;
}
Also used : IFile(org.eclipse.core.resources.IFile) PyRenameResourceChange(com.python.pydev.analysis.refactoring.changes.PyRenameResourceChange) RefactoringRequest(org.python.pydev.ast.refactoring.RefactoringRequest) ModuleRenameRefactoringRequest(org.python.pydev.ast.refactoring.ModuleRenameRefactoringRequest) PyRefactoringRequest(org.python.pydev.ast.refactoring.PyRefactoringRequest) IPyRefactoringRequest(org.python.pydev.ast.refactoring.IPyRefactoringRequest) PyRenameResourceChange(com.python.pydev.analysis.refactoring.changes.PyRenameResourceChange) RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) PyDocumentChange(org.python.pydev.refactoring.core.base.PyDocumentChange) PyRenameResourceChange(com.python.pydev.analysis.refactoring.changes.PyRenameResourceChange) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Change(org.eclipse.ltk.core.refactoring.Change) RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SynchronizedTextFileChange(org.python.pydev.refactoring.core.base.SynchronizedTextFileChange) PyCompositeChange(com.python.pydev.analysis.refactoring.changes.PyCompositeChange) PyCompositeChange(com.python.pydev.analysis.refactoring.changes.PyCompositeChange)

Aggregations

PyCompositeChange (com.python.pydev.analysis.refactoring.changes.PyCompositeChange)1 PyRenameResourceChange (com.python.pydev.analysis.refactoring.changes.PyRenameResourceChange)1 IFile (org.eclipse.core.resources.IFile)1 Change (org.eclipse.ltk.core.refactoring.Change)1 TextChange (org.eclipse.ltk.core.refactoring.TextChange)1 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)1 RenameResourceChange (org.eclipse.ltk.core.refactoring.resource.RenameResourceChange)1 IPyRefactoringRequest (org.python.pydev.ast.refactoring.IPyRefactoringRequest)1 ModuleRenameRefactoringRequest (org.python.pydev.ast.refactoring.ModuleRenameRefactoringRequest)1 PyRefactoringRequest (org.python.pydev.ast.refactoring.PyRefactoringRequest)1 RefactoringRequest (org.python.pydev.ast.refactoring.RefactoringRequest)1 PyDocumentChange (org.python.pydev.refactoring.core.base.PyDocumentChange)1 SynchronizedTextFileChange (org.python.pydev.refactoring.core.base.SynchronizedTextFileChange)1