Search in sources :

Example 1 with ChangePreview

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

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

the class TextEditChangePreviewViewer method setInput.

//	public void createControl(Composite parent) {
//		fViewer = new ComparePreviewer(parent);
//	}
//
//	public Control getControl() {
//		return fViewer;
//	}
public ChangePreview setInput(ChangePreviewViewerInput input) {
    try {
        Change change = input.getChange();
        if (input instanceof TextEditBasedChangeInput) {
            TextEditBasedChangeInput extended = (TextEditBasedChangeInput) input;
            if (extended.group != null && extended.surroundingLines >= 0) {
                TextEditBasedChangeGroup group = extended.group;
                TextEditBasedChange editChange = group.getTextEditChange();
                //					setInput(editChange, editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(new TextEditBasedChangeGroup[]{group}, group.getRegion(), true, 2,
                //														  new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(group.getRegion(), true, 2, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(new TextEditBasedChangeGroup[] { group }, group.getRegion(), true, 2, new NullProgressMonitor()));
                return preview;
            } else if (extended.groups != null && extended.groups.length > 0 && extended.range != null) {
                TextEditBasedChange editChange = extended.groups[0].getTextEditChange();
                TextEditBasedChangeGroup[] groups = extended.groups;
                //					if (extended.groupCategory != null) {
                //
                //					}
                //					setInput(editChange, editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()),
                //							 editChange.getTextType());
                ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
                preview.setFileName(getFileName(editChange));
                preview.setOldContent(editChange.getCurrentContent(extended.range, true, 0, new NullProgressMonitor()));
                preview.setNewContent(editChange.getPreviewContent(groups, extended.range, true, 0, new NullProgressMonitor()));
                return preview;
            }
        } else if (change instanceof TextEditBasedChange) {
            TextEditBasedChange editChange = (TextEditBasedChange) change;
            //				setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()),
            //						 editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
            ChangePreview preview = DtoFactory.newDto(ChangePreview.class);
            preview.setFileName(getFileName(editChange));
            preview.setOldContent(editChange.getCurrentContent(new NullProgressMonitor()));
            preview.setNewContent(editChange.getPreviewContent(new NullProgressMonitor()));
            return preview;
        } else {
            //				fViewer.setInput(null);
            return null;
        }
    } catch (CoreException | AssertionFailedException e) {
        JavaPlugin.log(e);
        //			fViewer.setInput(null);
        return null;
    }
    //		}
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ChangePreview(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) TextEditBasedChange(org.eclipse.ltk.core.refactoring.TextEditBasedChange) Change(org.eclipse.ltk.core.refactoring.Change) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) TextEditBasedChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)

Example 3 with ChangePreview

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

use of org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangePreview 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)4 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 AssertionFailedException (org.eclipse.core.runtime.AssertionFailedException)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Change (org.eclipse.ltk.core.refactoring.Change)1 TextEditBasedChange (org.eclipse.ltk.core.refactoring.TextEditBasedChange)1 TextEditBasedChangeGroup (org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup)1