Search in sources :

Example 86 with ReplaceEdit

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

the class TextEditTests method testOverlap5.

@Test
public void testOverlap5() throws Exception {
    // [ []  ]
    fRoot.addChild(new ReplaceEdit(0, 3, "012"));
    boolean exception = false;
    try {
        fRoot.addChild(new InsertEdit(1, "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 87 with ReplaceEdit

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

the class TextEditTests method testMoveTree1.

@Test
public void testMoveTree1() {
    TextEdit root = new MultiTextEdit();
    TextEdit e1 = new ReplaceEdit(0, 1, "");
    root.addChild(e1);
    TextEdit e2 = new ReplaceEdit(2, 2, "");
    root.addChild(e2);
    root.moveTree(3);
    Assert.assertEquals(3, root.getOffset());
    Assert.assertEquals(4, root.getLength());
    Assert.assertEquals(3, e1.getOffset());
    Assert.assertEquals(1, e1.getLength());
    Assert.assertEquals(5, e2.getOffset());
    Assert.assertEquals(2, e2.getLength());
}
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) Test(org.junit.Test)

Example 88 with ReplaceEdit

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

the class TextEditTests method testInsert3.

@Test
public void testInsert3() throws Exception {
    // [  ][][  ]
    TextEdit e1 = new ReplaceEdit(0, 2, "011");
    TextEdit e2 = new InsertEdit(2, "xx");
    TextEdit e3 = new ReplaceEdit(2, 2, "2");
    fRoot.addChild(e1);
    fRoot.addChild(e2);
    fRoot.addChild(e3);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(fRoot, 0, 6);
    assertEquals(e1, 0, 3);
    assertEquals(e2, 3, 2);
    assertEquals(e3, 5, 1);
    Assert.assertEquals("Buffer content", "011xx2456789", fDocument.get());
    doUndoRedo(undo, "011xx2456789");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 89 with ReplaceEdit

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

the class TextEditTests method testOverlap3.

@Test
public void testOverlap3() throws Exception {
    // [ [ ]]
    fRoot.addChild(new ReplaceEdit(0, 2, "01"));
    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)

Example 90 with ReplaceEdit

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

the class TextEditTests method testMoveDownWithInnerMark.

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