Search in sources :

Example 6 with RefactoringStatus

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

the class RenamePresenter method validateName.

/** {@inheritDoc} */
@Override
public void validateName() {
    ValidateNewName validateNewName = dtoFactory.createDto(ValidateNewName.class);
    validateNewName.setSessionId(renameRefactoringSession.getSessionId());
    validateNewName.setNewName(view.getNewName());
    refactorService.validateNewName(validateNewName).then(new Operation<RefactoringStatus>() {

        @Override
        public void apply(RefactoringStatus arg) throws OperationException {
            switch(arg.getSeverity()) {
                case OK:
                    view.setEnableAcceptButton(true);
                    view.setEnablePreviewButton(true);
                    view.clearErrorLabel();
                    break;
                case INFO:
                    view.setEnableAcceptButton(true);
                    view.setEnablePreviewButton(true);
                    view.showStatusMessage(arg);
                    break;
                default:
                    view.setEnableAcceptButton(false);
                    view.setEnablePreviewButton(false);
                    view.showErrorMessage(arg);
                    break;
            }
        }
    }).catchError(new Operation<PromiseError>() {

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

Example 7 with RefactoringStatus

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

the class DtoConverter method toRefactoringStatusDto.

/**
     * Converts {@link org.eclipse.ltk.core.refactoring.RefactoringStatus} to {@link RefactoringStatus}.
     */
public static RefactoringStatus toRefactoringStatusDto(org.eclipse.ltk.core.refactoring.RefactoringStatus refactoringStatus) {
    RefactoringStatus status = DtoFactory.newDto(RefactoringStatus.class);
    convertRefactoringStatus(status, refactoringStatus);
    return status;
}
Also used : RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)

Example 8 with RefactoringStatus

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

the class RenameRefactoringTest method testRenamePreviewChanges.

@Test
public void testRenamePreviewChanges() throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("package p;\n");
    b.append("public class A{\n private A a; \n}\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");
    RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    manager.createChange(refactoring.getSessionId());
    RefactoringPreview preview = manager.getRefactoringPreview(refactoring.getSessionId());
    RefactoringChange change1 = new DtoServerImpls.ChangeEnabledStateImpl();
    change1.setSessionId(refactoring.getSessionId());
    change1.setChangeId(preview.getChildrens().get(0).getId());
    ChangePreview changePreview = manager.getChangePreview(change1);
    assertThat(changePreview).isNotNull();
    assertThat(changePreview.getFileName()).isNotNull().isNotEmpty();
    assertThat(changePreview.getOldContent()).isNotNull().isNotEmpty();
    assertThat(changePreview.getNewContent()).isNotNull().isNotEmpty();
    assertThat(changePreview.getNewContent()).isNotEqualTo(changePreview.getOldContent());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringChange(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 9 with RefactoringStatus

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

the class RenameRefactoringTest method testRenamePackage.

@Test
public void testRenamePackage() throws Exception {
    final IPackageFragment packageFragment = getRoot().createPackageFragment("p.a.b.c", true, null);
    RenameRefactoringSession refactoring = manager.createRenameRefactoring(packageFragment, null, -1, false);
    assertThat(refactoring).isNotNull();
    assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
    final ValidateNewName validateNewName = new DtoServerImpls.ValidateNewNameImpl().withNewName("p.x.s.z");
    validateNewName.setSessionId(refactoring.getSessionId());
    final RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ValidateNewName(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName) DtoServerImpls(org.eclipse.che.plugin.java.server.dto.DtoServerImpls) RefactoringStatus(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) Test(org.junit.Test)

Example 10 with RefactoringStatus

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

the class RenameRefactoringTest method testRenameValidateInvalidName.

@Test
public void testRenameValidateInvalidName() 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("My#Class");
    RefactoringStatus status = manager.renameValidateNewName(validateNewName);
    assertThat(status).isNotNull();
    assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.FATAL);
}
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) RenameRefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Aggregations

RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)12 Test (org.junit.Test)9 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 IType (org.eclipse.jdt.core.IType)7 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)6 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)5 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 ValidateNewName (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ValidateNewName)2 Operation (org.eclipse.che.api.promises.client.Operation)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 ChangeCreationResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult)1 ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)1 LinkedRenameRefactoringApply (org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply)1 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)1 RefactoringChange (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange)1 RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)1 RenameSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameSettings)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1