use of org.eclipse.text.edits.MoveTargetEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveUpWithInnerMark.
@Test
public void testMoveUpWithInnerMark() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
TextEdit m = new ReplaceEdit(4, 1, "yy");
fRoot.addChild(t1);
fRoot.addChild(m);
fRoot.addChild(s1);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "017823yy569", fDocument.get());
assertEquals(s1, 10, 0);
assertEquals(t1, 2, 2);
assertEquals(m, 6, 2);
doUndoRedo(undo, "017823yy569");
}
use of org.eclipse.text.edits.MoveTargetEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveWithTargetDelete.
@Test
public void testMoveWithTargetDelete() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
TextEdit e2 = new DeleteEdit(6, 2);
e2.addChild(t1);
fRoot.addChild(s1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "01589", fDocument.get());
assertEquals(s1, 2, 0);
assertTrue(t1.isDeleted());
assertEquals(e2, 3, 0);
doUndoRedo(undo, "01589");
}
use of org.eclipse.text.edits.MoveTargetEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testOverlap9.
@Test
public void testOverlap9() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(3, 1);
MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
MoveSourceEdit s2 = new MoveSourceEdit(2, 3);
MoveTargetEdit t2 = new MoveTargetEdit(8, s2);
fRoot.addChild(s1);
fRoot.addChild(t1);
boolean exception = false;
try {
fRoot.addChild(s2);
fRoot.addChild(t2);
} catch (MalformedTreeException e) {
exception = true;
}
assertTrue(exception);
}
use of org.eclipse.text.edits.MoveTargetEdit in project webtools.sourceediting by eclipse.
the class JSPTranslationUtil method translateTextEdit.
public TextEdit translateTextEdit(TextEdit textEdit) {
TextEdit translatedTextEdit = null;
int javaOffset = textEdit.getOffset();
int jspOffset = getTranslation().getJspOffset(textEdit.getOffset());
int length = textEdit.getLength();
if (textEdit instanceof MultiTextEdit) {
translatedTextEdit = new MultiTextEdit();
TextEdit[] children = ((MultiTextEdit) textEdit).getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
if (translatedChildTextEdit != null)
((MultiTextEdit) translatedTextEdit).addChild(translatedChildTextEdit);
}
} else if (textEdit instanceof ReplaceEdit) {
if (jspOffset == -1)
return null;
if (!getTranslation().javaSpansMultipleJspPartitions(javaOffset, length))
translatedTextEdit = new ReplaceEdit(jspOffset, length, ((ReplaceEdit) textEdit).getText());
} else if (textEdit instanceof InsertEdit) {
translatedTextEdit = new InsertEdit(jspOffset, ((InsertEdit) textEdit).getText());
} else if (textEdit instanceof DeleteEdit) {
translatedTextEdit = new DeleteEdit(jspOffset, length);
TextEdit[] children = ((DeleteEdit) textEdit).getChildren();
for (int i = 0; i < children.length; i++) {
TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
if (translatedChildTextEdit != null)
((DeleteEdit) translatedTextEdit).addChild(translatedChildTextEdit);
}
} else if (textEdit instanceof CopySourceEdit) {
translatedTextEdit = new CopySourceEdit(jspOffset, length);
((CopySourceEdit) translatedTextEdit).setTargetEdit(((CopySourceEdit) textEdit).getTargetEdit());
((CopySourceEdit) translatedTextEdit).setSourceModifier(((CopySourceEdit) textEdit).getSourceModifier());
} else if (textEdit instanceof CopyTargetEdit) {
translatedTextEdit = new CopyTargetEdit(jspOffset);
((CopyTargetEdit) textEdit).getSourceEdit().setTargetEdit((CopyTargetEdit) translatedTextEdit);
} else if (textEdit instanceof MoveSourceEdit) {
translatedTextEdit = new MoveSourceEdit(jspOffset, length);
((MoveSourceEdit) translatedTextEdit).setTargetEdit(((MoveSourceEdit) textEdit).getTargetEdit());
} else if (textEdit instanceof MoveTargetEdit) {
translatedTextEdit = new MoveTargetEdit(jspOffset);
((MoveTargetEdit) textEdit).getSourceEdit().setTargetEdit((MoveTargetEdit) translatedTextEdit);
} else {
// $NON-NLS-1$
System.out.println("Need to translate " + textEdit);
}
return translatedTextEdit;
}
use of org.eclipse.text.edits.MoveTargetEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMove5.
@Test
public void testMove5() throws Exception {
// Move onto itself
MoveSourceEdit s1 = new MoveSourceEdit(2, 1);
MoveTargetEdit t1 = new MoveTargetEdit(3, s1);
TextEdit e2 = new ReplaceEdit(2, 1, "x");
s1.addChild(e2);
fRoot.addChild(s1);
fRoot.addChild(t1);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 2, 0);
assertEquals(t1, 2, 1);
assertEquals(e2, 2, 1);
Assert.assertEquals("Buffer content", "01x3456789", fDocument.get());
doUndoRedo(undo, "01x3456789");
}
Aggregations