Search in sources :

Example 1 with RefactoringChange

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

the class MoveRefactoringSessionTest method testPreviewChanges.

@Test
public void testPreviewChanges() throws Exception {
    IType type = fProject.findType("p.A");
    ICompilationUnit unit = type.getCompilationUnit();
    String sessionId = manager.createMoveRefactoringSession(new IJavaElement[] { unit });
    ReorgDestination destination = new DtoServerImpls.ReorgDestinationImpl();
    destination.setSessionId(sessionId);
    destination.setProjectPath(RefactoringTestSetup.getProject().getPath().toOSString());
    destination.setDestination(p1.getPath().toOSString());
    destination.setType(ReorgDestination.DestinationType.PACKAGE);
    manager.setRefactoringDestination(destination);
    MoveSettings settings = new DtoServerImpls.MoveSettingsImpl();
    settings.setUpdateReferences(true);
    settings.setSessionId(sessionId);
    manager.setMoveSettings(settings);
    manager.createChange(sessionId);
    RefactoringPreview change = manager.getRefactoringPreview(sessionId);
    RefactoringChange change1 = new DtoServerImpls.ChangeEnabledStateImpl();
    change1.setSessionId(sessionId);
    change1.setChangeId(change.getChildrens().get(0).getId());
    ChangePreview preview = manager.getChangePreview(change1);
    assertThat(preview).isNotNull();
    assertThat(preview.getFileName()).isNotNull().isNotEmpty();
    assertThat(preview.getOldContent()).isNotNull().isNotEmpty();
    assertThat(preview.getNewContent()).isNotNull().isNotEmpty();
}
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) ReorgDestination(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings) RefactoringPreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 2 with RefactoringChange

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange 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 3 with RefactoringChange

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

the class PreviewPresenter method onSelectionChanged.

/** {@inheritDoc} */
@Override
public void onSelectionChanged(RefactoringPreview change) {
    RefactoringChange refactoringChanges = dtoFactory.createDto(RefactoringChange.class);
    refactoringChanges.setChangeId(change.getId());
    refactoringChanges.setSessionId(session.getSessionId());
    Promise<ChangePreview> changePreviewPromise = refactoringService.getChangePreview(refactoringChanges);
    changePreviewPromise.then(new Operation<ChangePreview>() {

        @Override
        public void apply(ChangePreview arg) throws OperationException {
            view.showDiff(arg);
        }
    });
}
Also used : RefactoringChange(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ChangePreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview)3 RefactoringChange (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringChange)3 RefactoringPreview (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringPreview)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IType (org.eclipse.jdt.core.IType)2 Test (org.junit.Test)2 OperationException (org.eclipse.che.api.promises.client.OperationException)1 MoveSettings (org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)1 RefactoringStatus (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringStatus)1 RenameRefactoringSession (org.eclipse.che.ide.ext.java.shared.dto.refactoring.RenameRefactoringSession)1 ReorgDestination (org.eclipse.che.ide.ext.java.shared.dto.refactoring.ReorgDestination)1 DtoServerImpls (org.eclipse.che.plugin.java.server.dto.DtoServerImpls)1