Search in sources :

Example 1 with CheckConditionsOperation

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

the class RefactoringSession method createChange.

public ChangeCreationResult createChange() throws RefactoringException {
    Change change = createChange(new CreateChangeOperation(new CheckConditionsOperation(refactoring, CheckConditionsOperation.FINAL_CONDITIONS), RefactoringStatus.FATAL), true);
    // Status has been updated since we have passed true
    RefactoringStatus status = conditionCheckingStatus;
    // Creating the change has been canceled
    if (change == null && status == null) {
        internalSetChange(change);
        throw new RefactoringException("Creating the change has been canceled");
    }
    // Set change if we don't have fatal errors.
    if (!status.hasFatalError()) {
        internalSetChange(change);
    }
    ChangeCreationResult result = DtoFactory.newDto(ChangeCreationResult.class);
    result.setStatus(DtoConverter.toRefactoringStatusDto(status));
    result.setCanShowPreviewPage(status.isOK());
    return result;
}
Also used : CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange) UndoTextFileChange(org.eclipse.ltk.core.refactoring.UndoTextFileChange) Change(org.eclipse.ltk.core.refactoring.Change) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) RenameCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) RefactoringException(org.eclipse.che.plugin.java.server.refactoring.RefactoringException)

Example 2 with CheckConditionsOperation

use of org.eclipse.ltk.core.refactoring.CheckConditionsOperation 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 CheckConditionsOperation

use of org.eclipse.ltk.core.refactoring.CheckConditionsOperation 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)

Aggregations

CheckConditionsOperation (org.eclipse.ltk.core.refactoring.CheckConditionsOperation)3 CreateChangeOperation (org.eclipse.ltk.core.refactoring.CreateChangeOperation)3 Change (org.eclipse.ltk.core.refactoring.Change)2 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1 RefactoringException (org.eclipse.che.plugin.java.server.refactoring.RefactoringException)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 JavaRefactoringDescriptor (org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)1 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)1 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)1 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)1 RenamePackageChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange)1 ChangeDescriptor (org.eclipse.ltk.core.refactoring.ChangeDescriptor)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1 IUndoManager (org.eclipse.ltk.core.refactoring.IUndoManager)1