Search in sources :

Example 81 with ReplaceEdit

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

the class TextEditTests method testMove5.

@Test
public void testMove5() throws Exception {
    // Move onto itself
    MoveSourceEdit s1 = new MoveSourceEdit(2, 1);
    MoveTargetEdit t1 = new MoveTargetEdit(3, s1);
    TextEdit e2 = new ReplaceEdit(2, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 2, 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 82 with ReplaceEdit

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

the class TextEditTests method testMoveTree4.

@Test
public void testMoveTree4() {
    boolean exception = false;
    try {
        TextEdit root = new MultiTextEdit();
        TextEdit e1 = new ReplaceEdit(0, 1, "");
        root.addChild(e1);
        e1.moveTree(1);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Test(org.junit.Test)

Example 83 with ReplaceEdit

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

the class TextEditTests method testOverlap2.

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

Example 84 with ReplaceEdit

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

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

the class TextEditTests method testOverlap4.

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

Aggregations

ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)131 TextEdit (org.eclipse.text.edits.TextEdit)53 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)43 Test (org.junit.Test)34 InsertEdit (org.eclipse.text.edits.InsertEdit)25 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)22 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15 BadLocationException (org.eclipse.jface.text.BadLocationException)14 IDocument (org.eclipse.jface.text.IDocument)14 DeleteEdit (org.eclipse.text.edits.DeleteEdit)13 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)13 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)13 UndoEdit (org.eclipse.text.edits.UndoEdit)13 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)11 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)10 ArrayList (java.util.ArrayList)9 SearchResultGroup (org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)8 TextChange (org.eclipse.ltk.core.refactoring.TextChange)8 List (java.util.List)7 Document (org.eclipse.jface.text.Document)7