Search in sources :

Example 21 with ReplaceEdit

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

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

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

the class TextEditTests method testMove8.

@Test
public void testMove8() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(5, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(1, s1);
    TextEdit e2 = new ReplaceEdit(6, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "05x7123489", fDocument.get());
    assertEquals(s1, 8, 0);
    assertEquals(t1, 1, 3);
    assertEquals(e2, 2, 1);
    doUndoRedo(undo, "05x7123489");
}
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 24 with ReplaceEdit

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

the class TextEditTests method testOverlap6.

@Test
public void testOverlap6() throws Exception {
    // [  [] ]
    fRoot.addChild(new ReplaceEdit(0, 3, "012"));
    boolean exception = false;
    try {
        fRoot.addChild(new InsertEdit(2, "xx"));
    } catch (MalformedTreeException e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Test(org.junit.Test)

Example 25 with ReplaceEdit

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

the class TextEditTests method testMove3.

@Test
public void testMove3() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit e2 = new ReplaceEdit(4, 1, "x");
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    fRoot.addChild(e2);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01x5623789", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(t1, 5, 2);
    assertEquals(e2, 2, 1);
    doUndoRedo(undo, "01x5623789");
}
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)

Aggregations

ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)117 TextEdit (org.eclipse.text.edits.TextEdit)48 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)42 Test (org.junit.Test)34 InsertEdit (org.eclipse.text.edits.InsertEdit)24 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)14 IDocument (org.eclipse.jface.text.IDocument)13 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)13 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)13 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)13 UndoEdit (org.eclipse.text.edits.UndoEdit)13 BadLocationException (org.eclipse.jface.text.BadLocationException)12 DeleteEdit (org.eclipse.text.edits.DeleteEdit)12 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Document (org.eclipse.jface.text.Document)7 CoreException (org.eclipse.core.runtime.CoreException)6 Position (org.eclipse.jface.text.Position)6 TextChange (org.eclipse.ltk.core.refactoring.TextChange)6