use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method testMixedChanges.
@Test
public void testMixedChanges() throws Exception {
IFile file1 = IResourcesSetupUtil.createFile(PROJECT + "/file1.txt", MODEL);
ITextEditor editor1 = openInEditor(file1);
CompositeChange compositeChange = new CompositeChange("test");
compositeChange.add(createEditorDocumentChange(editor1, 1, 1, "foo"));
compositeChange.add(createTextFileChange(file0, 1, 1, "foo"));
CompositeChange compositeChange1 = new CompositeChange("test");
compositeChange.add(compositeChange1);
compositeChange1.add(createEditorDocumentChange(editor1, 3, 1, "baz"));
compositeChange1.add(createTextFileChange(file0, 1, 1, "foo"));
compositeChange1.add(createTextFileChange(file0, 3, 1, "baz"));
Change combined = combiner.combineChanges(compositeChange);
Change undo = combined.perform(new NullProgressMonitor());
IDocument document1 = getDocument(editor1);
assertEquals(MODEL.replace("123", "foo2baz"), document1.get());
assertEquals(MODEL.replace("123", "foo2baz"), getContents(file0));
undo.perform(new NullProgressMonitor());
assertEquals(MODEL, document1.get());
assertEquals(MODEL, getContents(file0));
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method testEmptyChange.
@Test
public void testEmptyChange() throws Exception {
CompositeChange emptyChange = new CompositeChange("test");
assertNull(combiner.combineChanges(emptyChange));
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method testMultipleFileChanges.
@Test
public void testMultipleFileChanges() throws Exception {
CompositeChange compositeChange = new CompositeChange("test");
compositeChange.add(createTextFileChange(file0, 1, 1, "foo"));
compositeChange.add(createTextFileChange(file0, 2, 1, "bar"));
CompositeChange compositeChange1 = new CompositeChange("test");
compositeChange.add(compositeChange1);
compositeChange1.add(createTextFileChange(file0, 3, 1, "baz"));
compositeChange1.add(createTextFileChange(file0, 2, 1, "bar"));
compositeChange1.add(createMultiTextFileChange(file0, 1, 1, "foo", 4, 1, "foo"));
Change combined = combiner.combineChanges(compositeChange);
assertTrue(combined instanceof CompositeChange);
assertEquals(1, ((CompositeChange) combined).getChildren().length);
Change combinedChild = ((CompositeChange) combined).getChildren()[0];
assertTrue(combinedChild instanceof DisplayChangeWrapper.Wrapper);
Change delegate = ((DisplayChangeWrapper.Wrapper) combinedChild).getDelegate();
assertTextType(delegate);
Change undo = combined.perform(new NullProgressMonitor());
assertEquals(MODEL.replace("1234", "foobarbazfoo"), getContents(file0));
undo.perform(new NullProgressMonitor());
assertEquals(MODEL, getContents(file0));
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project erlide_eclipse by erlang.
the class RenameModuleRefactoring method createChange.
@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
final CompositeChange c = (CompositeChange) super.createChange(pm);
for (final ChangedFile f : changedFiles) {
if (f.isNameChanged()) {
final IPath p = f.getPath();
final String s = f.getNewName();
final RenameResourceChange rch = new RenameResourceChange(p, s);
c.add(rch);
}
}
return c;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project erlide_eclipse by erlang.
the class WranglerRefactoring method createChange.
@Override
public Change createChange(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
pm.beginTask("Creating changes", changedFiles.size() + 1);
final CompositeChange change = new CompositeChange(getName());
pm.internalWorked(1);
try {
Change c;
for (final ChangedFile e : changedFiles) {
c = e.createChanges();
if (c != null) {
change.add(c);
pm.internalWorked(1);
}
}
} catch (final IOException e) {
final Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage());
throw new CoreException(s);
} finally {
pm.done();
}
return change;
}
Aggregations