aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwannheden2009-10-15 04:19:14 (EDT)
committersefftinge2009-10-15 04:19:14 (EDT)
commit5e33334e270783a07059b8a196f574d5c26b6f40 (patch)
treeaa12626bf3bf2ccea5c7734555424c13e2fe7ebe
parente5a1616d5a46336c06f7976657e6bf5aa8c227de (diff)
downloadorg.eclipse.xtext-5e33334e270783a07059b8a196f574d5c26b6f40.zip
org.eclipse.xtext-5e33334e270783a07059b8a196f574d5c26b6f40.tar.gz
org.eclipse.xtext-5e33334e270783a07059b8a196f574d5c26b6f40.tar.bz2
Fix: fixed problem with non-contained objects - https://bugs.eclipse.org/bugs/show_bug.cgi?id=292349
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposer.java22
-rw-r--r--tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposerTest.java16
2 files changed, 33 insertions, 5 deletions
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposer.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposer.java
index c436074..cc64e6c 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposer.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposer.java
@@ -24,6 +24,8 @@ import org.eclipse.xtext.parsetree.NodeAdapter;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.parsetree.reconstr.SerializerUtil;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
@@ -91,7 +93,14 @@ public class DefaultTextEditComposer extends EContentAdapter implements ITextEdi
}
}
+ private void reset() {
+ getModifiedObjects().clear();
+ resourceChanged = false;
+ }
+
public void beginRecording(Resource newResource) {
+ reset();
+
if (newResource != resource) {
if (resource != null)
resource.eAdapters().remove(this);
@@ -112,9 +121,7 @@ public class DefaultTextEditComposer extends EContentAdapter implements ITextEdi
recording = false;
TextEdit textEdit = getTextEdit();
- getModifiedObjects().clear();
- resourceChanged = false;
-
+ reset();
return textEdit;
}
@@ -147,9 +154,14 @@ public class DefaultTextEditComposer extends EContentAdapter implements ITextEdi
private List<TextEdit> getObjectEdits() {
final Collection<EObject> modifiedObjects = getModifiedObjects();
Collection<EObject> topLevelObjects = EcoreUtil.filterDescendants(modifiedObjects);
- List<TextEdit> edits = Lists.newArrayList();
+ Iterable<EObject> containedObjects = Iterables.filter(topLevelObjects, new Predicate<EObject>() {
+ public boolean apply(EObject input) {
+ return input.eResource() == resource;
+ }
+ });
+ List<TextEdit> edits = Lists.newArrayListWithExpectedSize(Iterables.size(containedObjects));
- for (EObject eObject : topLevelObjects) {
+ for (EObject eObject : containedObjects) {
NodeAdapter nodeAdapter = NodeUtil.getNodeAdapter(eObject);
CompositeNode node = nodeAdapter.getParserNode();
diff --git a/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposerTest.java b/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposerTest.java
index 7bb4659..2b805e3 100644
--- a/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposerTest.java
+++ b/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/editor/model/edit/DefaultTextEditComposerTest.java
@@ -111,6 +111,22 @@ public class DefaultTextEditComposerTest extends AbstractXtextTests {
assertMatches(alternatives, edit);
}
+ /* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=292349 */
+ public void testObjectModificationAndRemoval() throws Exception {
+ Resource res = getResource(newTestGrammar());
+
+ composer.beginRecording(res);
+ Grammar grammar = (Grammar) res.getContents().get(0);
+ AbstractRule rule = grammar.getRules().get(0);
+ Alternatives alternatives = (Alternatives) rule.getAlternatives();
+ Keyword bazKeyword = (Keyword) alternatives.getGroups().get(2);
+ bazKeyword.setValue("BAZ");
+ alternatives.getGroups().remove(bazKeyword);
+ TextEdit edit = composer.endRecording();
+
+ assertMatches(alternatives, edit);
+ }
+
public void testObjectReplacement() throws Exception {
Resource res = getResource(newTestGrammar());