Search in sources :

Example 11 with DeleteEdit

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

the class TextEditTests method testUndefinedMultiEdit6.

@Test
public void testUndefinedMultiEdit6() throws Exception {
    DeleteEdit d1 = new DeleteEdit(1, 3);
    MultiTextEdit m2 = new MultiTextEdit();
    assertTrue(d1.covers(m2));
}
Also used : DeleteEdit(org.eclipse.text.edits.DeleteEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 12 with DeleteEdit

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

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

the class TextEditTests method testMoveWithTargetDelete.

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

Example 14 with DeleteEdit

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

use of org.eclipse.text.edits.DeleteEdit in project AutoRefactor by JnRouvignac.

the class ASTCommentRewriter method addRemovalEdits.

private void addRemovalEdits(List<TextEdit> commentEdits, String source) {
    if (this.removals.isEmpty()) {
        return;
    }
    for (Comment node : this.removals) {
        final int start = node.getStartPosition();
        final int length = node.getLength();
        // chomp from the end before the start variable gets modified
        final int startToRemove = chompWhitespacesBefore(source, start);
        final int endToRemove = chompWhitespacesAfter(source, start + length);
        final int lengthToRemove = endToRemove - startToRemove;
        commentEdits.add(new DeleteEdit(startToRemove, lengthToRemove));
    }
}
Also used : LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) DeleteEdit(org.eclipse.text.edits.DeleteEdit)

Aggregations

DeleteEdit (org.eclipse.text.edits.DeleteEdit)40 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)26 InsertEdit (org.eclipse.text.edits.InsertEdit)20 TextEdit (org.eclipse.text.edits.TextEdit)17 Test (org.junit.Test)15 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)11 UndoEdit (org.eclipse.text.edits.UndoEdit)10 IRegion (org.eclipse.jface.text.IRegion)6 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)6 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)6 ArrayList (java.util.ArrayList)5 IDocument (org.eclipse.jface.text.IDocument)5 HashSet (java.util.HashSet)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 RangeMarker (org.eclipse.text.edits.RangeMarker)4 Location (org.eclipse.titan.designer.AST.Location)4 Module (org.eclipse.titan.designer.AST.Module)4 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 Document (org.eclipse.jface.text.Document)3 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)3