Search in sources :

Example 46 with TextEdit

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

the class TextEditTests method testMoveUp.

@Test
public void testMoveUp() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit i1 = new InsertEdit(5, "x");
    TextEdit d1 = new DeleteEdit(9, 1);
    RangeMarker m1 = new RangeMarker(7, 2);
    s1.addChild(m1);
    fRoot.addChild(s1);
    fRoot.addChild(i1);
    fRoot.addChild(t1);
    fRoot.addChild(d1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0178234x56", fDocument.get());
    assertEquals(s1, 10, 0);
    assertEquals(i1, 7, 1);
    assertEquals(t1, 2, 2);
    assertEquals(m1, 2, 2);
    assertEquals(d1, 10, 0);
    doUndoRedo(undo, "0178234x56");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) InsertEdit(org.eclipse.text.edits.InsertEdit) 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 47 with TextEdit

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

the class TextEditTests method testDeleteWithChildren.

@Test
public void testDeleteWithChildren() throws Exception {
    TextEdit e1 = new DeleteEdit(2, 6);
    MultiTextEdit e2 = new MultiTextEdit(3, 3);
    e1.addChild(e2);
    TextEdit e3 = new ReplaceEdit(3, 1, "xx");
    TextEdit e4 = new ReplaceEdit(5, 1, "yy");
    e2.addChild(e3);
    e2.addChild(e4);
    fRoot.addChild(e1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0189", fDocument.get());
    assertEquals(fRoot, 2, 0);
    assertEquals(e1, 2, 0);
    assertTrue(e2.isDeleted());
    assertTrue(e3.isDeleted());
    assertTrue(e4.isDeleted());
    doUndoRedo(undo, "0189");
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 48 with TextEdit

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

the class TextEditTests method testMoveDown.

@Test
public void testMoveDown() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    TextEdit i1 = new InsertEdit(5, "x");
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit d1 = new DeleteEdit(9, 1);
    RangeMarker m1 = new RangeMarker(2, 2);
    s1.addChild(m1);
    fRoot.addChild(s1);
    fRoot.addChild(i1);
    fRoot.addChild(t1);
    fRoot.addChild(d1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "014x562378", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(i1, 3, 1);
    assertEquals(t1, 6, 2);
    assertEquals(m1, 6, 2);
    assertEquals(d1, 10, 0);
    doUndoRedo(undo, "014x562378");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) 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 49 with TextEdit

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

the class TextEditTests method testMoveDownWithSourceDelete.

@Test
public void testMoveDownWithSourceDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit d1 = new DeleteEdit(2, 2);
    d1.addChild(s1);
    RangeMarker m1 = new RangeMarker(2, 2);
    s1.addChild(m1);
    fRoot.addChild(t1);
    fRoot.addChild(d1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0145623789", fDocument.get());
    assertEquals(d1, 2, 0);
    assertTrue(s1.isDeleted());
    assertEquals(t1, 5, 2);
    assertEquals(m1, 5, 2);
    doUndoRedo(undo, "0145623789");
}
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 50 with TextEdit

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

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