use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class PreviewPresenterTest method acceptButtonActionShouldBePerformed.
@Test
public void acceptButtonActionShouldBePerformed() throws Exception {
List<ChangeInfo> changes = new ArrayList<>();
VirtualFile virtualFile = Mockito.mock(VirtualFile.class);
EditorInput editorInput = Mockito.mock(EditorInput.class);
when(refactoringStatus.getSeverity()).thenReturn(OK);
when(refactoringStatus.getChanges()).thenReturn(changes);
when(editor.getEditorInput()).thenReturn(editorInput);
when(editorInput.getFile()).thenReturn(virtualFile);
presenter.onAcceptButtonClicked();
verify(refactoringStatusPromise).then(refactoringStatusOperation.capture());
refactoringStatusOperation.getValue().apply(refactoringStatus);
verify(view).hide();
// verify(refactoringUpdater).updateAfterRefactoring(null, changes);
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RenamePresenterTest method changesShouldBeAppliedWithNotErrorStatus.
@Test
public void changesShouldBeAppliedWithNotErrorStatus() throws Exception {
RefactorInfo refactorInfo = RefactorInfo.of(MoveType.REFACTOR_MENU, RefactoredItemType.COMPILATION_UNIT, new Resource[] { file });
when(changeCreationResult.isCanShowPreviewPage()).thenReturn(true);
when(refactoringStatus.getSeverity()).thenReturn(0);
renamePresenter.show(refactorInfo);
verify(refactorService).createRenameRefactoring(createRenameRefactoringDto);
verify(renameRefactoringSessionPromise).then(renameRefactoringSessionCaptor.capture());
renameRefactoringSessionCaptor.getValue().apply(session);
renamePresenter.onAcceptButtonClicked();
verify(refactoringSession).setSessionId(SESSION_ID);
verifyPreparingRenameSettingsDto();
verifyPreparingRenameChanges();
verify(changeCreationResultPromise).then(changeCreationResultCaptor.capture());
changeCreationResultCaptor.getValue().apply(changeCreationResult);
verify(refactorService).applyRefactoring(refactoringSession);
verify(refactoringStatusPromise).then(refactoringStatusCaptor.capture());
refactoringStatusCaptor.getValue().apply(refactoringStatus);
verify(view).hide();
verify(refactoringUpdater).updateAfterRefactoring(Matchers.<List<ChangeInfo>>anyObject());
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class RefactoringSession method apply.
/**
* @return instance of {@link org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus}.
* That describes status of the refactoring operation.
*/
public RefactoringResult apply() {
PerformChangeOperation operation = new PerformChangeOperation(change);
FinishResult result = internalPerformFinish(operation);
if (result.isException()) {
return DtoConverter.toRefactoringResultDto(RefactoringStatus.createErrorStatus("Refactoring failed with Exception."));
}
CompositeChange operationChange = (CompositeChange) operation.getUndoChange();
Change[] changes = operationChange.getChildren();
RefactoringStatus validationStatus = operation.getValidationStatus();
if (validationStatus != null) {
List<ChangeInfo> changesInfo = new ArrayList<>();
prepareChangesInfo(changes, changesInfo);
RefactoringResult status = DtoConverter.toRefactoringResultDto(validationStatus);
status.setChanges(changesInfo);
return status;
}
return DtoConverter.toRefactoringResultDto(new RefactoringStatus());
}
use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo in project che by eclipse.
the class MovePresenter method onAcceptButtonClicked.
/** {@inheritDoc} */
@Override
public void onAcceptButtonClicked() {
final 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()) {
eventBus.fireEvent(newFileTrackingSuspendEvent());
refactorService.applyRefactoring(session).then(new Operation<RefactoringResult>() {
@Override
public void apply(RefactoringResult arg) throws OperationException {
if (arg.getSeverity() == OK) {
view.hide();
refactoringUpdater.updateAfterRefactoring(arg.getChanges());
final Resource[] resources = refactorInfo.getResources();
if (resources != null && resources.length == 1) {
refactorService.reindexProject(resources[0].getRelatedProject().get().getLocation().toString());
}
} else {
view.showErrorMessage(arg);
}
for (ChangeInfo change : arg.getChanges()) {
final String path = change.getPath();
final String oldPath = change.getOldPath();
eventBus.fireEvent(newFileTrackingMoveEvent(path, oldPath));
}
eventBus.fireEvent(newFileTrackingResumeEvent());
}
});
} else {
view.showErrorMessage(arg.getStatus());
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(locale.applyMoveError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
}
});
}
Aggregations