Search in sources :

Example 1 with MoveTargetEdit

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

the class TextEditTests method testSourceTranformationSplit2.

@Test
public void testSourceTranformationSplit2() 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(2, 2, "aa") };
        }
    });
    fRoot.apply(fDocument);
    String result = "0167823aa9";
    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)

Example 2 with MoveTargetEdit

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

the class TextEditTests method testOverlap7.

@Test
public void testOverlap7() throws Exception {
    MoveSourceEdit source = new MoveSourceEdit(2, 5);
    MoveTargetEdit target = new MoveTargetEdit(3, source);
    fRoot.addChild(source);
    boolean exception = false;
    try {
        fRoot.addChild(target);
    } catch (MalformedTreeException e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) Test(org.junit.Test)

Example 3 with MoveTargetEdit

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

the class TextEditTests method testMoveUp.

@Test
public void testMoveUp() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit i1 = new InsertEdit(5, "x");
    TextEdit d1 = new DeleteEdit(9, 1);
    RangeMarker m1 = new RangeMarker(7, 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", "0178234x56", fDocument.get());
    assertEquals(s1, 10, 0);
    assertEquals(i1, 7, 1);
    assertEquals(t1, 2, 2);
    assertEquals(m1, 2, 2);
    assertEquals(d1, 10, 0);
    doUndoRedo(undo, "0178234x56");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) InsertEdit(org.eclipse.text.edits.InsertEdit) 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 4 with MoveTargetEdit

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

the class TextEditTests method testSourceTranformationMultipleCovers.

// Regression test for 108672 [quick fix] Exception when applying Convert to enhanced for loop
@Test
public void testSourceTranformationMultipleCovers() 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, 0);
    ms.addChild(r1);
    RangeMarker r2 = new RangeMarker(3, 0);
    ms.addChild(r2);
    RangeMarker r3 = new RangeMarker(4, 2);
    ms.addChild(r3);
    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());
    assertTrue(r1.isDeleted());
    assertTrue(r2.isDeleted());
    assertEquals(r3, 7, 2);
}
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 5 with MoveTargetEdit

use of org.eclipse.text.edits.MoveTargetEdit 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)

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