Search in sources :

Example 6 with ChangeInfo

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);
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) ArrayList(java.util.ArrayList) EditorInput(org.eclipse.che.ide.api.editor.EditorInput) Test(org.junit.Test)

Example 7 with ChangeInfo

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());
}
Also used : ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactorInfo(org.eclipse.che.ide.ext.java.client.refactoring.RefactorInfo) Test(org.junit.Test)

Example 8 with ChangeInfo

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());
}
Also used : PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) FinishResult(org.eclipse.ltk.internal.ui.refactoring.FinishResult) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) 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) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange)

Example 9 with ChangeInfo

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);
        }
    });
}
Also used : ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult) 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)

Aggregations

ChangeInfo (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo)9 ArrayList (java.util.ArrayList)5 RefactoringResult (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringResult)3 RenamePackageChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange)3 Change (org.eclipse.ltk.core.refactoring.Change)3 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)3 Test (org.junit.Test)3 OperationException (org.eclipse.che.api.promises.client.OperationException)2 RefactorInfo (org.eclipse.che.ide.ext.java.client.refactoring.RefactorInfo)2 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)2 MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)2 RenameCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange)2 PerformChangeOperation (org.eclipse.ltk.core.refactoring.PerformChangeOperation)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 UndoTextFileChange (org.eclipse.ltk.core.refactoring.UndoTextFileChange)2 Scheduler (com.google.gwt.core.client.Scheduler)1 Operation (org.eclipse.che.api.promises.client.Operation)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 EditorInput (org.eclipse.che.ide.api.editor.EditorInput)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1