Search in sources :

Example 51 with TextEdit

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

the class TextEditTests method testInsert5.

@Test
public void testInsert5() throws Exception {
    TextEdit e1 = new InsertEdit(10, "xx");
    fRoot.addChild(e1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer length", 12, fDocument.getLength());
    assertEquals(fRoot, 10, 2);
    assertEquals(e1, 10, 2);
    Assert.assertEquals("Buffer content", "0123456789xx", fDocument.get());
    doUndoRedo(undo, "0123456789xx");
}
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) Test(org.junit.Test)

Example 52 with TextEdit

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

the class TextEditTests method testMoveUpWithSourceDelete.

@Test
public void testMoveUpWithSourceDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(5, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit d1 = new DeleteEdit(5, 2);
    d1.addChild(s1);
    RangeMarker marker = new RangeMarker(5, 2);
    s1.addChild(marker);
    fRoot.addChild(d1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0156234789", fDocument.get());
    assertEquals(t1, 2, 2);
    assertEquals(marker, 2, 2);
    assertTrue(s1.isDeleted());
    assertEquals(d1, 7, 0);
    doUndoRedo(undo, "0156234789");
}
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) RangeMarker(org.eclipse.text.edits.RangeMarker) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 53 with TextEdit

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

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

the class TextEditTests method testDelete3.

@Test
public void testDelete3() throws Exception {
    TextEdit e1 = new InsertEdit(3, "x");
    TextEdit e2 = new DeleteEdit(3, 1);
    fRoot.addChild(e1);
    fRoot.addChild(e2);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(fRoot, 3, 1);
    assertEquals(e1, 3, 1);
    assertEquals(e2, 4, 0);
    Assert.assertEquals("Buffer content", "012x456789", fDocument.get());
    doUndoRedo(undo, "012x456789");
}
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) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 55 with TextEdit

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

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