use of org.eclipse.text.edits.TextEdit in project xtext-eclipse by eclipse.
the class TextChangeCombiner method addIfNotDuplicate.
protected void addIfNotDuplicate(MultiTextEdit multiTextEdit, final TextEdit editToBeAdded) {
final boolean[] overlaps = new boolean[] { false };
TextEditVisitor textEditVisitor = new TextEditVisitor() {
@Override
public boolean visitNode(TextEdit edit) {
overlaps[0] |= !(edit instanceof MultiTextEdit) && edit.covers(editToBeAdded);
return super.visitNode(edit);
}
};
multiTextEdit.accept(textEditVisitor);
if (!overlaps[0])
multiTextEdit.addChild(editToBeAdded.copy());
}
use of org.eclipse.text.edits.TextEdit in project xtext-eclipse by eclipse.
the class AbstractTextEditComposerTest method testObjectReplacement.
@Test
public void testObjectReplacement() throws Exception {
Resource res = getResource(newTestGrammar());
composer.beginRecording(res);
Grammar grammar = (Grammar) res.getContents().get(0);
ParserRule rule = (ParserRule) grammar.getRules().get(0);
Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
keyword.setValue("baz");
rule.setAlternatives(keyword);
TextEdit edit = composer.endRecording();
assertMatches("Foo: \"baz\";", edit);
}
use of org.eclipse.text.edits.TextEdit in project xtext-eclipse by eclipse.
the class AbstractTextEditComposerTest method testObjectRemoval.
@Test
public void testObjectRemoval() 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();
alternatives.getElements().remove(2);
TextEdit edit = composer.endRecording();
assertMatches("'foo' | 'bar'", edit);
}
use of org.eclipse.text.edits.TextEdit in project xtext-eclipse by eclipse.
the class AbstractTextEditComposerTest method testRemoveRootObject.
@Test
public void testRemoveRootObject() throws Exception {
Resource res = getResource(newTestGrammar());
composer.beginRecording(res);
res.getContents().clear();
TextEdit edit = composer.endRecording();
assertEquals("", ((ReplaceEdit) edit).getText());
}
use of org.eclipse.text.edits.TextEdit in project xtext-eclipse by eclipse.
the class AbstractTextEditComposerTest method testObjectModificationAndRemoval.
/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=292349 */
@Test
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.getElements().get(2);
bazKeyword.setValue("BAZ");
alternatives.getElements().remove(bazKeyword);
TextEdit edit = composer.endRecording();
assertMatches("'foo' | 'bar'", edit);
}
Aggregations