Search in sources :

Example 6 with InsertEdit

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

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

the class TextEditTests method testOverlap6.

@Test
public void testOverlap6() throws Exception {
    // [  [] ]
    fRoot.addChild(new ReplaceEdit(0, 3, "012"));
    boolean exception = false;
    try {
        fRoot.addChild(new InsertEdit(2, "xx"));
    } catch (MalformedTreeException e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) Test(org.junit.Test)

Example 8 with InsertEdit

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

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

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

InsertEdit (org.eclipse.text.edits.InsertEdit)73 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)33 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)25 TextEdit (org.eclipse.text.edits.TextEdit)24 DeleteEdit (org.eclipse.text.edits.DeleteEdit)22 Test (org.junit.Test)22 BadLocationException (org.eclipse.jface.text.BadLocationException)13 UndoEdit (org.eclipse.text.edits.UndoEdit)13 ArrayList (java.util.ArrayList)12 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IDocument (org.eclipse.jface.text.IDocument)8 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)8 Location (org.eclipse.titan.designer.AST.Location)8 Module (org.eclipse.titan.designer.AST.Module)7 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)7 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)5 CoreException (org.eclipse.core.runtime.CoreException)5 IFile (org.eclipse.core.resources.IFile)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4