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);
}
});
}
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;
}
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());
}
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);
}
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);
}
Aggregations