use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class RefactoringUpdateAcceptor method createCompositeChange.
@Override
public Change createCompositeChange(String name, IProgressMonitor monitor) {
if (document2change.isEmpty() && document2textEdits.isEmpty())
return null;
CompositeChange compositeChange = new CompositeChange(name);
for (IRefactoringDocument document : document2textEdits.keySet()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
Iterable<TextEdit> textEdits = document2textEdits.get(document);
MultiTextEdit multiTextEdit = new MultiTextEdit();
for (TextEdit textEdit : textEdits) {
multiTextEdit.addChild(textEdit);
}
Change change = document.createChange(name, multiTextEdit);
compositeChange.add(change);
}
for (IRefactoringDocument document : document2change.keySet()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
Iterable<Change> documentChanges = document2change.get(document);
CompositeChange documentCompositeChange = new CompositeChange(name);
documentCompositeChange.addAll(Iterables.toArray(documentChanges, Change.class));
compositeChange.add(documentCompositeChange);
}
return compositeChange;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class CombinedJvmJdtRenameProcessor method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
SubMonitor monitor = SubMonitor.convert(pm, jvmElements2jdtProcessors.size() + 1);
CompositeChange compositeChange = new CompositeChange(getProcessorName());
compositeChange.add(super.createChange(monitor.newChild(1)));
for (JavaRenameProcessor processor : jvmElements2jdtProcessors.values()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
compositeChange.add(processor.createChange(monitor.newChild(1)));
}
return compositeChange;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombinerTest method testMultipleDocumentChanges.
@Test
public void testMultipleDocumentChanges() throws Exception {
ITextEditor editor = openInEditor(file0);
CompositeChange compositeChange = new CompositeChange("test");
compositeChange.add(createEditorDocumentChange(editor, 1, 1, "foo"));
compositeChange.add(createEditorDocumentChange(editor, 2, 1, "bar"));
CompositeChange compositeChange1 = new CompositeChange("test");
compositeChange.add(compositeChange1);
compositeChange1.add(createEditorDocumentChange(editor, 3, 1, "baz"));
compositeChange1.add(createEditorDocumentChange(editor, 2, 1, "bar"));
compositeChange1.add(createMultiEditorDocumentChange(editor, 1, 1, "foo", 4, 1, "foo"));
Change combined = combiner.combineChanges(compositeChange);
assertTrue(combined instanceof CompositeChange);
assertEquals(1, ((CompositeChange) combined).getChildren().length);
assertTrue(((CompositeChange) combined).getChildren()[0] instanceof EditorDocumentChange);
Change undo = combined.perform(new NullProgressMonitor());
IDocument document = getDocument(editor);
assertEquals(MODEL.replace("1234", "foobarbazfoo"), document.get());
undo.perform(new NullProgressMonitor());
assertEquals(MODEL, document.get());
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombiner method combineChanges.
public Change combineChanges(Change masterChange) {
if (!(masterChange instanceof CompositeChange))
return masterChange;
Map<Object, TextChange> resource2textChange = newLinkedHashMap();
List<Change> otherChanges = newArrayList();
Set<IEditorPart> editorsToSave = newHashSet();
visitCompositeChange((CompositeChange) masterChange, resource2textChange, otherChanges, editorsToSave);
CompositeChange compositeChange = new FilteringCompositeChange(masterChange.getName());
for (TextChange combinedTextChange : resource2textChange.values()) {
if (((MultiTextEdit) combinedTextChange.getEdit()).getChildrenSize() > 0) {
if (combinedTextChange instanceof EditorDocumentChange) {
((EditorDocumentChange) combinedTextChange).setDoSave(editorsToSave.contains(((EditorDocumentChange) combinedTextChange).getEditor()));
compositeChange.add(combinedTextChange);
} else
compositeChange.add(DisplayChangeWrapper.wrap(combinedTextChange));
}
}
for (Change otherChange : otherChanges) compositeChange.add(DisplayChangeWrapper.wrap(otherChange));
if (compositeChange.getChildren().length == 0)
return null;
return compositeChange;
}
use of org.eclipse.ltk.core.refactoring.CompositeChange in project xtext-eclipse by eclipse.
the class TextChangeCombiner method visitChange.
protected void visitChange(Change sourceChange, Map<Object, TextChange> resource2textChange, List<Change> otherChanges, Set<IEditorPart> editorsToSave) {
if (sourceChange instanceof DisplayChangeWrapper.Wrapper)
visitChange(((DisplayChangeWrapper.Wrapper) sourceChange).getDelegate(), resource2textChange, otherChanges, editorsToSave);
else if (sourceChange instanceof CompositeChange) {
visitCompositeChange((CompositeChange) sourceChange, resource2textChange, otherChanges, editorsToSave);
} else if (sourceChange instanceof TextChange) {
if (sourceChange instanceof EditorDocumentChange)
editorsToSave.add(((EditorDocumentChange) sourceChange).getEditor());
Object key = getKey((TextChange) sourceChange);
if (key != null) {
TextChange textChange = resource2textChange.get(key);
if (textChange == null) {
textChange = createTextChange(key, ((TextChange) sourceChange).getTextType());
resource2textChange.put(key, textChange);
}
MultiTextEdit combinedEdits = (MultiTextEdit) textChange.getEdit();
TextEdit newEdit = ((TextChange) sourceChange).getEdit().copy();
if (newEdit instanceof MultiTextEdit) {
for (TextEdit newTextEdit : ((MultiTextEdit) newEdit).getChildren()) {
addIfNotDuplicate(combinedEdits, newTextEdit);
}
} else {
addIfNotDuplicate(combinedEdits, newEdit);
}
}
} else {
CompositeChange parent = (CompositeChange) sourceChange.getParent();
if (parent != null)
parent.remove(sourceChange);
otherChanges.add(sourceChange);
}
}
Aggregations