use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.
the class RenameRefactoringTest method testApplyLinkedRename.
@Test
public void testApplyLinkedRename() 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"), true);
assertThat(refactoring).isNotNull();
assertThat(refactoring.getSessionId()).isNotNull().isNotEmpty();
LinkedRenameRefactoringApply apply = new DtoServerImpls.LinkedRenameRefactoringApplyImpl();
apply.setSessionId(refactoring.getSessionId());
apply.setNewName("Test");
RefactoringStatus status = manager.applyLinkedRename(apply);
assertThat(status).isNotNull();
assertThat(status.getSeverity()).isEqualTo(RefactoringStatus.OK);
assertThat(unit.exists()).isFalse();
ICompilationUnit newUnit = getPackageP().getCompilationUnit("Test.java");
assertThat(newUnit.exists()).isTrue();
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.
the class JavaRefactoringRename method createLinkedRenameRefactoringApplyDto.
@NotNull
private LinkedRenameRefactoringApply createLinkedRenameRefactoringApplyDto(String newName, String sessionId) {
LinkedRenameRefactoringApply dto = dtoFactory.createDto(LinkedRenameRefactoringApply.class);
dto.setNewName(newName);
dto.setSessionId(sessionId);
return dto;
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.LinkedRenameRefactoringApply in project che by eclipse.
the class JavaRefactoringRename method performRename.
private void performRename(RenameRefactoringSession session) {
final LinkedRenameRefactoringApply dto = createLinkedRenameRefactoringApplyDto(newName, session.getSessionId());
Promise<RefactoringResult> applyModelPromise = refactoringServiceClient.applyLinkedModeRename(dto);
applyModelPromise.then(new Operation<RefactoringResult>() {
@Override
public void apply(RefactoringResult result) throws OperationException {
switch(result.getSeverity()) {
case OK:
case INFO:
final VirtualFile file = textEditor.getDocument().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
refactoringServiceClient.reindexProject(project.get().getLocation().toString());
}
refactoringUpdater.updateAfterRefactoring(result.getChanges());
break;
case WARNING:
case ERROR:
enableAutoSave();
undoChanges();
showWarningDialog();
break;
case FATAL:
undoChanges();
notificationManager.notify(locale.failedToRename(), result.getEntries().get(0).getMessage(), FAIL, FLOAT_MODE);
break;
default:
break;
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
enableAutoSave();
undoChanges();
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
Aggregations