Search in sources :

Example 1 with ISourceModifier

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

use of org.eclipse.text.edits.ISourceModifier 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 3 with ISourceModifier

use of org.eclipse.text.edits.ISourceModifier 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 4 with ISourceModifier

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

ISourceModifier (org.eclipse.text.edits.ISourceModifier)4 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)4 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)4 RangeMarker (org.eclipse.text.edits.RangeMarker)4 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)4 Test (org.junit.Test)4