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();
}
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;
}
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());
}
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);
}
});
}
Aggregations