Search in sources :

Example 21 with MoveTargetEdit

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

the class TextEditTests method testNestedMoveSourceWithInsert.

@Test
public void testNestedMoveSourceWithInsert() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(1, 5);
    MoveSourceEdit s2 = new MoveSourceEdit(2, 3);
    MoveSourceEdit s3 = new MoveSourceEdit(3, 1);
    InsertEdit i1 = new InsertEdit(4, "x");
    s1.addChild(s2);
    s2.addChild(s3);
    s3.addChild(i1);
    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, 9, 0);
    assertEquals(s3, 6, 0);
    assertEquals(i1, 3, 1);
    assertEquals(t1, 8, 2);
    assertEquals(t2, 5, 2);
    assertEquals(t3, 2, 2);
    String result = "063x7248159";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    doUndoRedo(undo, result);
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 22 with MoveTargetEdit

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

the class TextEditTests method testMove6.

@Test
public void testMove6() throws Exception {
    // Move onto itself
    MoveSourceEdit s1 = new MoveSourceEdit(2, 1);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit e2 = new ReplaceEdit(2, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 3, 0);
    assertEquals(t1, 2, 1);
    assertEquals(e2, 2, 1);
    Assert.assertEquals("Buffer content", "01x3456789", fDocument.get());
    doUndoRedo(undo, "01x3456789");
}
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 23 with MoveTargetEdit

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

the class TextEditTests method testMove2.

@Test
public void testMove2() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(5, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0156234789", fDocument.get());
    assertEquals(s1, 7, 0);
    assertEquals(t1, 2, 2);
    doUndoRedo(undo, "0156234789");
}
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 24 with MoveTargetEdit

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

the class TextEditTests method compare.

private static void compare(List<TextEdit> org, List<TextEdit> copy) {
    assertTrue("Same length", org.size() == copy.size());
    for (Iterator<TextEdit> iter = copy.iterator(); iter.hasNext(); ) {
        TextEdit edit = iter.next();
        assertTrue("Original is part of copy list", !org.contains(edit));
        if (edit instanceof MoveSourceEdit) {
            MoveSourceEdit source = (MoveSourceEdit) edit;
            assertTrue("Target edit isn't a copy", copy.contains(source.getTargetEdit()));
            assertTrue("Traget edit is a original", !org.contains(source.getTargetEdit()));
        } else if (edit instanceof MoveTargetEdit) {
            MoveTargetEdit target = (MoveTargetEdit) edit;
            assertTrue("Source edit isn't a copy", copy.contains(target.getSourceEdit()));
            assertTrue("Source edit is a original", !org.contains(target.getSourceEdit()));
        } else if (edit instanceof CopySourceEdit) {
            CopySourceEdit source = (CopySourceEdit) edit;
            assertTrue("Target edit isn't a copy", copy.contains(source.getTargetEdit()));
            assertTrue("Traget edit is a original", !org.contains(source.getTargetEdit()));
        } else if (edit instanceof CopyTargetEdit) {
            CopyTargetEdit target = (CopyTargetEdit) edit;
            assertTrue("Source edit isn't a copy", copy.contains(target.getSourceEdit()));
            assertTrue("Source edit is a original", !org.contains(target.getSourceEdit()));
        }
    }
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit)

Example 25 with MoveTargetEdit

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

the class TextEditTests method testMove1.

@Test
public void testMove1() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(5, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0142356789", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(t1, 3, 2);
    doUndoRedo(undo, "0142356789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) 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