Search in sources :

Example 41 with TextEdit

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

the class TextEditTests method testCopy1.

@Test
public void testCopy1() throws Exception {
    MultiTextEdit root = new MultiTextEdit();
    TextEdit e1 = new InsertEdit(2, "yy");
    TextEdit e2 = new ReplaceEdit(2, 3, "3456");
    root.addChild(e1);
    root.addChild(e2);
    List<TextEdit> org = flatten(root);
    TextEditCopier copier = new TextEditCopier(root);
    List<TextEdit> copy = flatten(copier.perform());
    compare(org, copy);
}
Also used : TextEditCopier(org.eclipse.text.edits.TextEditCopier) InsertEdit(org.eclipse.text.edits.InsertEdit) 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 42 with TextEdit

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

the class TextEditTests method testInsert1.

@Test
public void testInsert1() throws Exception {
    // [][  ]
    TextEdit e1 = new InsertEdit(2, "yy");
    TextEdit e2 = new ReplaceEdit(2, 3, "3456");
    fRoot.addChild(e1);
    fRoot.addChild(e2);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(fRoot, 2, 6);
    assertEquals(e1, 2, 2);
    assertEquals(e2, 4, 4);
    Assert.assertEquals("Buffer content", "01yy345656789", fDocument.get());
    doUndoRedo(undo, "01yy345656789");
}
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 43 with TextEdit

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

the class TextEditTests method testMoveTree2.

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

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

the class TextEditTests method testSwap1.

@Test
public void testSwap1() throws Exception {
    IDocument document = new Document("foo(1, 2), 3");
    MultiTextEdit root = new MultiTextEdit();
    {
        CopySourceEdit innerRoot = new CopySourceEdit(0, 9);
        TextEdit e1 = new ReplaceEdit(0, 9, "");
        e1.addChild(innerRoot);
        CopyTargetEdit t1 = new CopyTargetEdit(11, innerRoot);
        TextEdit e2 = new ReplaceEdit(11, 1, "");
        CopySourceEdit s2 = new CopySourceEdit(11, 1);
        e2.addChild(s2);
        CopyTargetEdit t2 = new CopyTargetEdit(0, s2);
        root.addChild(e1);
        root.addChild(t2);
        root.addChild(e2);
        root.addChild(t1);
    }
    root.apply(document);
    String result = "3, foo(1, 2)";
    Assert.assertEquals("Buffer content", result, document.get());
}
Also used : CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 45 with TextEdit

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

the class TextEditTests method testSwap2.

@Test
public void testSwap2() throws Exception {
    IDocument document = new Document("foo(1, 2), 3");
    MultiTextEdit root = new MultiTextEdit();
    {
        TextEdit e1 = new ReplaceEdit(4, 1, "");
        CopySourceEdit s1 = new CopySourceEdit(4, 1);
        e1.addChild(s1);
        CopyTargetEdit t1 = new CopyTargetEdit(7, s1);
        TextEdit e2 = new ReplaceEdit(7, 1, "");
        CopySourceEdit s2 = new CopySourceEdit(7, 1);
        e2.addChild(s2);
        CopyTargetEdit t2 = new CopyTargetEdit(4, s2);
        root.addChild(e1);
        root.addChild(t2);
        root.addChild(e2);
        root.addChild(t1);
    }
    root.apply(document);
    String result = "foo(2, 1), 3";
    Assert.assertEquals("Buffer content", result, document.get());
}
Also used : CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) 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