Search in sources :

Example 26 with MoveTargetEdit

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

the class TextEditTests method testMove9.

@Test
public void testMove9() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(1, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(5, s1);
    MoveSourceEdit s2 = new MoveSourceEdit(1, 1);
    MoveTargetEdit t2 = new MoveTargetEdit(3, s2);
    s1.addChild(s2);
    s1.addChild(t2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 1, 0);
    assertEquals(t1, 2, 3);
    assertEquals(s2, 2, 0);
    assertEquals(t2, 3, 1);
    Assert.assertEquals("Buffer content", "0421356789", fDocument.get());
    doUndoRedo(undo, "0421356789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 27 with MoveTargetEdit

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

the class TextEditTests method testMoveDownWithInnerMark.

@Test
public void testMoveDownWithInnerMark() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(7, 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", "01yy5623789", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(t1, 6, 2);
    assertEquals(m, 2, 2);
    doUndoRedo(undo, "01yy5623789");
}
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 28 with MoveTargetEdit

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

the class TextEditTests method testMoveUpWithParentMark.

@Test
public void testMoveUpWithParentMark() throws Exception {
    RangeMarker m = new RangeMarker(2, 6);
    MoveSourceEdit s1 = new MoveSourceEdit(4, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(3, s1);
    m.addChild(s1);
    m.addChild(t1);
    fRoot.addChild(m);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0124536789", fDocument.get());
    assertEquals(m, 2, 6);
    assertEquals(t1, 3, 2);
    assertEquals(s1, 6, 0);
    doUndoRedo(undo, "0124536789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) RangeMarker(org.eclipse.text.edits.RangeMarker) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 29 with MoveTargetEdit

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

the class TextEditTests method testNestedMoveSource.

@Test
public void testNestedMoveSource() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(1, 5);
    MoveSourceEdit s2 = new MoveSourceEdit(2, 3);
    MoveSourceEdit s3 = new MoveSourceEdit(3, 1);
    s1.addChild(s2);
    s2.addChild(s3);
    MoveTargetEdit t1 = new MoveTargetEdit(9, s1);
    MoveTargetEdit t2 = new MoveTargetEdit(8, s2);
    MoveTargetEdit t3 = new MoveTargetEdit(7, s3);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    fRoot.addChild(t2);
    fRoot.addChild(t3);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 1, 0);
    assertEquals(s2, 8, 0);
    assertEquals(s3, 5, 0);
    assertEquals(t1, 7, 2);
    assertEquals(t2, 4, 2);
    assertEquals(t3, 2, 1);
    String result = "0637248159";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    doUndoRedo(undo, result);
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 30 with MoveTargetEdit

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

the class TextEditTests method testSourceTransformationIncludes.

@Test
public void testSourceTransformationIncludes() 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(1, 1, "aa") };
        }
    });
    fRoot.apply(fDocument);
    String result = "016782aa459";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    assertEquals(r1, 6, 3);
}
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)

Aggregations

MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)32 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)32 Test (org.junit.Test)30 UndoEdit (org.eclipse.text.edits.UndoEdit)23 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)15 TextEdit (org.eclipse.text.edits.TextEdit)15 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)13 RangeMarker (org.eclipse.text.edits.RangeMarker)11 DeleteEdit (org.eclipse.text.edits.DeleteEdit)6 ISourceModifier (org.eclipse.text.edits.ISourceModifier)4 InsertEdit (org.eclipse.text.edits.InsertEdit)4 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)3 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)2 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)2