Search in sources :

Example 1 with ChangeCreationResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.

the class RenamePresenter method showPreview.

private void showPreview() {
    RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
    session.setSessionId(renameRefactoringSession.getSessionId());
    prepareRenameChanges(session).then(new Operation<ChangeCreationResult>() {

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            if (arg.isCanShowPreviewPage() || arg.getStatus().getSeverity() <= 3) {
                previewPresenter.show(renameRefactoringSession.getSessionId(), refactorInfo);
                previewPresenter.setTitle(locale.renameItemTitle());
                view.hide();
            } else {
                view.showErrorMessage(arg.getStatus());
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with ChangeCreationResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult 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 3 with ChangeCreationResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.

the class MoveRefactoringSessionTest method testCtrateMoveChanges.

@Test
public void testCtrateMoveChanges() throws Exception {
    IType type = fProject.findType("p.A");
    ICompilationUnit unit = type.getCompilationUnit();
    String sessionId = manager.createMoveRefactoringSession(new IJavaElement[] { unit });
    ReorgDestination destination = new DtoServerImpls.ReorgDestinationImpl();
    destination.setSessionId(sessionId);
    destination.setProjectPath(RefactoringTestSetup.getProject().getPath().toOSString());
    destination.setDestination(p1.getPath().toOSString());
    destination.setType(ReorgDestination.DestinationType.PACKAGE);
    manager.setRefactoringDestination(destination);
    MoveSettings settings = new DtoServerImpls.MoveSettingsImpl();
    settings.setUpdateReferences(true);
    settings.setSessionId(sessionId);
    manager.setMoveSettings(settings);
    ChangeCreationResult change = manager.createChange(sessionId);
    assertThat(change).isNotNull();
    assertThat(change.isCanShowPreviewPage()).isTrue();
    assertThat(change.getStatus().getSeverity()).isEqualTo(RefactoringStatus.OK);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 4 with ChangeCreationResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.

the class MovePresenter method onPreviewButtonClicked.

/** {@inheritDoc} */
@Override
public void onPreviewButtonClicked() {
    RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
    session.setSessionId(refactoringSessionId);
    prepareMovingChanges(session).then(new Operation<ChangeCreationResult>() {

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            if (arg.isCanShowPreviewPage()) {
                previewPresenter.show(refactoringSessionId, refactorInfo);
                view.hide();
            } else {
                view.showStatusMessage(arg.getStatus());
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(locale.showPreviewError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with ChangeCreationResult

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult in project che by eclipse.

the class RenameRefactoringTest method testDoRename.

@Test
public void testDoRename() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{}\n");
    ICompilationUnit unit = getPackageP().createCompilationUnit("A.java", b.toString(), false, null);
    IType type = unit.getAllTypes()[0];
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(type, unit, b.indexOf("A"), false);
    DtoServerImpls.ValidateNewNameImpl validateNewName = new DtoServerImpls.ValidateNewNameImpl();
    validateNewName.setSessionId(refactoring.getSessionId());
    validateNewName.setNewName("MyClass");
    manager.renameValidateNewName(validateNewName);
    RenameSettings settings = new DtoServerImpls.RenameSettingsImpl();
    settings.setSessionId(refactoring.getSessionId());
    settings.setDeprecateDelegates(true);
    settings.setUpdateReferences(true);
    manager.setRenameSettings(settings);
    ChangeCreationResult change = manager.createChange(refactoring.getSessionId());
    assertThat(change).isNotNull();
    RefactoringStatus applyRefactoring = manager.applyRefactoring(refactoring.getSessionId());
    assertThat(applyRefactoring).isNotNull();
    assertThat(applyRefactoring.getSeverity()).isEqualTo(RefactoringStatus.OK);
    assertThat(unit.exists()).isFalse();
    ICompilationUnit newUnit = getPackageP().getCompilationUnit("MyClass.java");
    assertThat(newUnit.exists()).isTrue();
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)7 Operation (org.eclipse.che.api.promises.client.Operation)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 RefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession)4 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 Test (org.junit.Test)2 ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)1 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)1 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)1 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)1 RenameSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings)1 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)1 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)1 RefactoringException (org.eclipse.che.plugin.java.server.refactoring.RefactoringException)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