Search in sources :

Example 1 with PerformChangeOperation

use of org.eclipse.ltk.core.refactoring.PerformChangeOperation in project che by eclipse.

the class RenameLinkedModeRefactoringSession method doRename.

/**
     * Make rename operation.
     * @param newName the name which will be applied
     * @return result of the rename operation
     * @throws CoreException if an error occurs while creating the refactoring instance
     * @throws InvocationTargetException if an error occurred while executing the
     * operation.
     * @throws InterruptedException if the operation has been canceled by the
     * user.
     */
public RefactoringResult doRename(String newName) throws CoreException, InvocationTargetException, InterruptedException {
    if (fOriginalName.equals(newName)) {
        return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
    }
    RenameSupport renameSupport = undoAndCreateRenameSupport(newName);
    if (renameSupport == null)
        return DtoConverter.toRefactoringResultDto(RefactoringStatus.createFatalErrorStatus("Can't create rename refactoring"));
    RefactoringResult refactoringResult = DtoConverter.toRefactoringResultDto(renameSupport.perform());
    PerformChangeOperation operation = renameSupport.getfPerformChangeOperation();
    if (operation == null) {
        return refactoringResult;
    }
    CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
    Change[] changes = operationChange.getChildren();
    List<ChangeInfo> changesInfo = new ArrayList<>();
    prepareChangesInfo(changes, changesInfo);
    refactoringResult.setChanges(changesInfo);
    return refactoringResult;
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) Change(org.eclipse.ltk.core.refactoring.Change) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport)

Example 2 with PerformChangeOperation

use of org.eclipse.ltk.core.refactoring.PerformChangeOperation in project che by eclipse.

the class RefactoringTest method performRefactoring.

protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
    performDummySearch();
    IUndoManager undoManager = getUndoManager();
    if (DESCRIPTOR_TEST) {
        final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
        create.run(new NullProgressMonitor());
        RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
        if (!checkingStatus.isOK())
            return checkingStatus;
        Change change = create.getChange();
        ChangeDescriptor descriptor = change.getDescriptor();
        if (descriptor instanceof RefactoringChangeDescriptor) {
            RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
            RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
            if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
                JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
                RefactoringStatus validation = jrd.validateDescriptor();
                if (!validation.isOK())
                    return validation;
                RefactoringStatus refactoringStatus = new RefactoringStatus();
                Class expected = jrd.getClass();
                RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
                jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
                assertEquals(expected, jrd.getClass());
                ref = jrd.createRefactoring(refactoringStatus);
                if (!refactoringStatus.isOK())
                    return refactoringStatus;
                TestRenameParticipantSingle.reset();
                TestCreateParticipantSingle.reset();
                TestMoveParticipantSingle.reset();
                TestDeleteParticipantSingle.reset();
            }
        }
    }
    final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
    final PerformChangeOperation perform = new PerformChangeOperation(create);
    perform.setUndoManager(undoManager, ref.getName());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (fIsPreDeltaTest) {
        IResourceChangeListener listener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
                    TestModelProvider.assertTrue(event.getDelta());
                }
            }
        };
        try {
            TestModelProvider.clearDelta();
            workspace.checkpoint(false);
            workspace.addResourceChangeListener(listener);
            executePerformOperation(perform, workspace);
        } finally {
            workspace.removeResourceChangeListener(listener);
        }
    } else {
        executePerformOperation(perform, workspace);
    }
    RefactoringStatus status = create.getConditionCheckingStatus();
    if (!status.isOK())
        return status;
    assertTrue("Change wasn't executed", perform.changeExecuted());
    Change undo = perform.getUndoChange();
    if (providesUndo) {
        assertNotNull("Undo doesn't exist", undo);
        assertTrue("Undo manager is empty", undoManager.anythingToUndo());
    } else {
        assertNull("Undo manager contains undo but shouldn't", undo);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 3 with PerformChangeOperation

use of org.eclipse.ltk.core.refactoring.PerformChangeOperation in project tdi-studio-se by Talend.

the class ChangeProjectTechinicalNameMigrationTask method renameProject.

/**
     * 
     * DOC ggu Comment method "renameProject".
     * 
     * @param localProject
     * @param newProjectName
     * @return
     */
@SuppressWarnings("restriction")
protected boolean renameProject(IProject localProject, String newProjectName) {
    RenameResourceProcessor renameProcessor = new RenameResourceProcessor(localProject);
    renameProcessor.setNewResourceName(newProjectName);
    CheckConditionsOperation condictionOperation = new CheckConditionsOperation(new RenameRefactoring(renameProcessor), CheckConditionsOperation.FINAL_CONDITIONS);
    CreateChangeOperation operation = new CreateChangeOperation(condictionOperation, RefactoringCore.getConditionCheckingFailedSeverity());
    PerformChangeOperation performChangeOp = new PerformChangeOperation(operation);
    try {
        performChangeOp.run(null);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
        return false;
    }
    return true;
}
Also used : CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) RenameResourceProcessor(org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor) CoreException(org.eclipse.core.runtime.CoreException) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation)

Example 4 with PerformChangeOperation

use of org.eclipse.ltk.core.refactoring.PerformChangeOperation in project che by eclipse.

the class RefactoringTest method performChange.

protected final Change performChange(final Change change) throws Exception {
    PerformChangeOperation perform = new PerformChangeOperation(change);
    ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
    assertTrue("Change wasn't executed", perform.changeExecuted());
    return perform.getUndoChange();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation)

Example 5 with PerformChangeOperation

use of org.eclipse.ltk.core.refactoring.PerformChangeOperation in project che by eclipse.

the class RefactoringTest method performChange.

protected final Change performChange(Refactoring refactoring, boolean storeUndo) throws Exception {
    CreateChangeOperation create = new CreateChangeOperation(refactoring);
    PerformChangeOperation perform = new PerformChangeOperation(create);
    if (storeUndo) {
        perform.setUndoManager(getUndoManager(), refactoring.getName());
    }
    ResourcesPlugin.getWorkspace().run(perform, new NullProgressMonitor());
    assertTrue("Change wasn't executed", perform.changeExecuted());
    return perform.getUndoChange();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation)

Aggregations

PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Change (org.eclipse.ltk.core.refactoring.Change)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 CreateChangeOperation (org.eclipse.ltk.core.refactoring.CreateChangeOperation)3 ArrayList (java.util.ArrayList)2 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)2 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 CheckConditionsOperation (org.eclipse.ltk.core.refactoring.CheckConditionsOperation)2 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProject (org.eclipse.core.resources.IProject)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IJobManager (org.eclipse.core.runtime.jobs.IJobManager)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1