Search in sources :

Example 6 with MoveSourceEdit

use of org.eclipse.text.edits.MoveSourceEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testSourceTranformationSplit1.

@Test
public void testSourceTranformationSplit1() throws Exception {
    MoveSourceEdit ms = new MoveSourceEdit(2, 4);
    MoveTargetEdit mt = new MoveTargetEdit(9, ms);
    fRoot.addChild(ms);
    fRoot.addChild(mt);
    RangeMarker r1 = new RangeMarker(3, 2);
    ms.addChild(r1);
    ms.setSourceModifier(new ISourceModifier() {

        @Override
        public ISourceModifier copy() {
            return this;
        }

        @Override
        public ReplaceEdit[] getModifications(String source) {
            return new ReplaceEdit[] { new ReplaceEdit(0, 2, "aa") };
        }
    });
    fRoot.apply(fDocument);
    String result = "01678aa459";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    assertEquals(r1, 7, 1);
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) ISourceModifier(org.eclipse.text.edits.ISourceModifier) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) RangeMarker(org.eclipse.text.edits.RangeMarker) Test(org.junit.Test)

Example 7 with MoveSourceEdit

use of org.eclipse.text.edits.MoveSourceEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMoveDown.

@Test
public void testMoveDown() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    TextEdit i1 = new InsertEdit(5, "x");
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit d1 = new DeleteEdit(9, 1);
    RangeMarker m1 = new RangeMarker(2, 2);
    s1.addChild(m1);
    fRoot.addChild(s1);
    fRoot.addChild(i1);
    fRoot.addChild(t1);
    fRoot.addChild(d1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "014x562378", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(i1, 3, 1);
    assertEquals(t1, 6, 2);
    assertEquals(m1, 6, 2);
    assertEquals(d1, 10, 0);
    doUndoRedo(undo, "014x562378");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) RangeMarker(org.eclipse.text.edits.RangeMarker) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 8 with MoveSourceEdit

use of org.eclipse.text.edits.MoveSourceEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMoveDownWithSourceDelete.

@Test
public void testMoveDownWithSourceDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit d1 = new DeleteEdit(2, 2);
    d1.addChild(s1);
    RangeMarker m1 = new RangeMarker(2, 2);
    s1.addChild(m1);
    fRoot.addChild(t1);
    fRoot.addChild(d1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0145623789", fDocument.get());
    assertEquals(d1, 2, 0);
    assertTrue(s1.isDeleted());
    assertEquals(t1, 5, 2);
    assertEquals(m1, 5, 2);
    doUndoRedo(undo, "0145623789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) RangeMarker(org.eclipse.text.edits.RangeMarker) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 9 with MoveSourceEdit

use of org.eclipse.text.edits.MoveSourceEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMove7.

@Test
public void testMove7() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit e2 = new ReplaceEdit(3, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01562x4789", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(t1, 4, 3);
    assertEquals(e2, 5, 1);
    doUndoRedo(undo, "01562x4789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 10 with MoveSourceEdit

use of org.eclipse.text.edits.MoveSourceEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMoveUpWithSourceDelete.

@Test
public void testMoveUpWithSourceDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(5, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit d1 = new DeleteEdit(5, 2);
    d1.addChild(s1);
    RangeMarker marker = new RangeMarker(5, 2);
    s1.addChild(marker);
    fRoot.addChild(d1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0156234789", fDocument.get());
    assertEquals(t1, 2, 2);
    assertEquals(marker, 2, 2);
    assertTrue(s1.isDeleted());
    assertEquals(d1, 7, 0);
    doUndoRedo(undo, "0156234789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) RangeMarker(org.eclipse.text.edits.RangeMarker) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Aggregations

MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)32 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)31 Test (org.junit.Test)31 UndoEdit (org.eclipse.text.edits.UndoEdit)23 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)14 TextEdit (org.eclipse.text.edits.TextEdit)14 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)12 RangeMarker (org.eclipse.text.edits.RangeMarker)11 DeleteEdit (org.eclipse.text.edits.DeleteEdit)5 ISourceModifier (org.eclipse.text.edits.ISourceModifier)4 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)4 InsertEdit (org.eclipse.text.edits.InsertEdit)3 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)1 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)1