Search in sources :

Example 56 with TextEdit

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

the class TextEditTests method testMoveUpWithInnerMark.

@Test
public void testMoveUpWithInnerMark() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, 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", "017823yy569", fDocument.get());
    assertEquals(s1, 10, 0);
    assertEquals(t1, 2, 2);
    assertEquals(m, 6, 2);
    doUndoRedo(undo, "017823yy569");
}
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 57 with TextEdit

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

the class TextEditTests method testMoveWithTargetDelete.

@Test
public void testMoveWithTargetDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit e2 = new DeleteEdit(6, 2);
    e2.addChild(t1);
    fRoot.addChild(s1);
    fRoot.addChild(e2);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01589", fDocument.get());
    assertEquals(s1, 2, 0);
    assertTrue(t1.isDeleted());
    assertEquals(e2, 3, 0);
    doUndoRedo(undo, "01589");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 58 with TextEdit

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

the class TextEditTests method testComparator.

@Test
public void testComparator() throws Exception {
    DeleteEdit d1 = new DeleteEdit(1, 3);
    Accessor accessor = new Accessor(d1, TextEdit.class);
    @SuppressWarnings("unchecked") Comparator<TextEdit> comparator = (Comparator<TextEdit>) accessor.get("INSERTION_COMPARATOR");
    TextEdit edit1 = new InsertEdit(1, "test");
    TextEdit edit2 = new InsertEdit(1, "test");
    TextEdit edit3 = new InsertEdit(57, "test3");
    assertTrue(edit1.equals(edit1));
    Assert.assertEquals(0, comparator.compare(edit1, edit1));
    Assert.assertEquals(0, comparator.compare(edit1, edit2));
    Assert.assertEquals(0, comparator.compare(edit2, edit1));
    assertTrue(comparator.compare(edit1, edit3) == -comparator.compare(edit3, edit1));
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 59 with TextEdit

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

the class TextEditTests method testMoveTree3.

@Test
public void testMoveTree3() {
    boolean exception = false;
    try {
        TextEdit root = new ReplaceEdit(0, 1, "");
        root.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) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Test(org.junit.Test)

Example 60 with TextEdit

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

the class TextEditTests method testTreeUpdate1.

@Test
public void testTreeUpdate1() throws Exception {
    MultiTextEdit m1 = new MultiTextEdit();
    TextEdit e1 = new InsertEdit(2, "aa");
    TextEdit e2 = new InsertEdit(4, "bb");
    m1.addChild(e1);
    m1.addChild(e2);
    MultiTextEdit m2 = new MultiTextEdit();
    TextEdit e3 = new InsertEdit(6, "cc");
    TextEdit e4 = new InsertEdit(8, "dd");
    m2.addChild(e3);
    m2.addChild(e4);
    fRoot.addChild(m1);
    fRoot.addChild(m2);
    assertEquals(m1, 2, 2);
    assertEquals(m2, 6, 2);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01aa23bb45cc67dd89", fDocument.get());
    assertEquals(e1, 2, 2);
    assertEquals(e2, 6, 2);
    assertEquals(e3, 10, 2);
    assertEquals(e4, 14, 2);
    assertEquals(m1, 2, 6);
    assertEquals(m2, 10, 6);
    assertEquals(fRoot, 2, 14);
    doUndoRedo(undo, "01aa23bb45cc67dd89");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Aggregations

TextEdit (org.eclipse.text.edits.TextEdit)190 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)113 Test (org.junit.Test)49 IDocument (org.eclipse.jface.text.IDocument)48 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)48 BadLocationException (org.eclipse.jface.text.BadLocationException)34 Document (org.eclipse.jface.text.Document)33 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)32 UndoEdit (org.eclipse.text.edits.UndoEdit)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 InsertEdit (org.eclipse.text.edits.InsertEdit)22 CoreException (org.eclipse.core.runtime.CoreException)20 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)19 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)19 DeleteEdit (org.eclipse.text.edits.DeleteEdit)17 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)16 ArrayList (java.util.ArrayList)15 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)15 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)15 TextEditGroup (org.eclipse.text.edits.TextEditGroup)15