Search in sources :

Example 21 with MultiTextEdit

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

the class TextEditTests method testUndefinedMultiEdit4.

@Test
public void testUndefinedMultiEdit4() throws Exception {
    MultiTextEdit m2 = new MultiTextEdit();
    m2.addChild(new DeleteEdit(1, 3));
    m2.addChild(new DeleteEdit(4, 2));
    Assert.assertEquals(1, m2.getOffset());
    Assert.assertEquals(5, m2.getLength());
}
Also used : DeleteEdit(org.eclipse.text.edits.DeleteEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 22 with MultiTextEdit

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

the class TextEditTests method testUndefinedMultiEdit3.

@Test
public void testUndefinedMultiEdit3() throws Exception {
    MultiTextEdit m2 = new MultiTextEdit();
    Assert.assertEquals(0, m2.getOffset());
    Assert.assertEquals(0, m2.getLength());
    m2.addChild(new DeleteEdit(1, 3));
    Assert.assertEquals(1, m2.getOffset());
    Assert.assertEquals(3, m2.getLength());
}
Also used : DeleteEdit(org.eclipse.text.edits.DeleteEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 23 with MultiTextEdit

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

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

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

MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)51 TextEdit (org.eclipse.text.edits.TextEdit)33 Test (org.junit.Test)18 IDocument (org.eclipse.jface.text.IDocument)13 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)13 Document (org.eclipse.jface.text.Document)11 TextEditGroup (org.eclipse.text.edits.TextEditGroup)10 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)9 DeleteEdit (org.eclipse.text.edits.DeleteEdit)7 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 ArrayList (java.util.ArrayList)5 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)5 HashSet (java.util.HashSet)4 List (java.util.List)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 TextChange (org.eclipse.ltk.core.refactoring.TextChange)4 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)4 TextEditCopier (org.eclipse.text.edits.TextEditCopier)4