Search in sources :

Example 16 with MoveTargetEdit

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

the class TextEditTests method testMoveUpWithInnerMark.

@Test
public void testMoveUpWithInnerMark() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit m = new ReplaceEdit(4, 1, "yy");
    fRoot.addChild(t1);
    fRoot.addChild(m);
    fRoot.addChild(s1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "017823yy569", fDocument.get());
    assertEquals(s1, 10, 0);
    assertEquals(t1, 2, 2);
    assertEquals(m, 6, 2);
    doUndoRedo(undo, "017823yy569");
}
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)

Example 17 with MoveTargetEdit

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

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

the class TextEditTests method testOverlap9.

@Test
public void testOverlap9() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(3, 1);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    MoveSourceEdit s2 = new MoveSourceEdit(2, 3);
    MoveTargetEdit t2 = new MoveTargetEdit(8, s2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    boolean exception = false;
    try {
        fRoot.addChild(s2);
        fRoot.addChild(t2);
    } catch (MalformedTreeException e) {
        exception = true;
    }
    assertTrue(exception);
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) Test(org.junit.Test)

Example 19 with MoveTargetEdit

use of org.eclipse.text.edits.MoveTargetEdit in project webtools.sourceediting by eclipse.

the class JSPTranslationUtil method translateTextEdit.

public TextEdit translateTextEdit(TextEdit textEdit) {
    TextEdit translatedTextEdit = null;
    int javaOffset = textEdit.getOffset();
    int jspOffset = getTranslation().getJspOffset(textEdit.getOffset());
    int length = textEdit.getLength();
    if (textEdit instanceof MultiTextEdit) {
        translatedTextEdit = new MultiTextEdit();
        TextEdit[] children = ((MultiTextEdit) textEdit).getChildren();
        for (int i = 0; i < children.length; i++) {
            TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
            if (translatedChildTextEdit != null)
                ((MultiTextEdit) translatedTextEdit).addChild(translatedChildTextEdit);
        }
    } else if (textEdit instanceof ReplaceEdit) {
        if (jspOffset == -1)
            return null;
        if (!getTranslation().javaSpansMultipleJspPartitions(javaOffset, length))
            translatedTextEdit = new ReplaceEdit(jspOffset, length, ((ReplaceEdit) textEdit).getText());
    } else if (textEdit instanceof InsertEdit) {
        translatedTextEdit = new InsertEdit(jspOffset, ((InsertEdit) textEdit).getText());
    } else if (textEdit instanceof DeleteEdit) {
        translatedTextEdit = new DeleteEdit(jspOffset, length);
        TextEdit[] children = ((DeleteEdit) textEdit).getChildren();
        for (int i = 0; i < children.length; i++) {
            TextEdit translatedChildTextEdit = translateTextEdit(children[i]);
            if (translatedChildTextEdit != null)
                ((DeleteEdit) translatedTextEdit).addChild(translatedChildTextEdit);
        }
    } else if (textEdit instanceof CopySourceEdit) {
        translatedTextEdit = new CopySourceEdit(jspOffset, length);
        ((CopySourceEdit) translatedTextEdit).setTargetEdit(((CopySourceEdit) textEdit).getTargetEdit());
        ((CopySourceEdit) translatedTextEdit).setSourceModifier(((CopySourceEdit) textEdit).getSourceModifier());
    } else if (textEdit instanceof CopyTargetEdit) {
        translatedTextEdit = new CopyTargetEdit(jspOffset);
        ((CopyTargetEdit) textEdit).getSourceEdit().setTargetEdit((CopyTargetEdit) translatedTextEdit);
    } else if (textEdit instanceof MoveSourceEdit) {
        translatedTextEdit = new MoveSourceEdit(jspOffset, length);
        ((MoveSourceEdit) translatedTextEdit).setTargetEdit(((MoveSourceEdit) textEdit).getTargetEdit());
    } else if (textEdit instanceof MoveTargetEdit) {
        translatedTextEdit = new MoveTargetEdit(jspOffset);
        ((MoveTargetEdit) textEdit).getSourceEdit().setTargetEdit((MoveTargetEdit) translatedTextEdit);
    } else {
        // $NON-NLS-1$
        System.out.println("Need to translate " + textEdit);
    }
    return translatedTextEdit;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 20 with MoveTargetEdit

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

the class TextEditTests method testMove5.

@Test
public void testMove5() throws Exception {
    // Move onto itself
    MoveSourceEdit s1 = new MoveSourceEdit(2, 1);
    MoveTargetEdit t1 = new MoveTargetEdit(3, s1);
    TextEdit e2 = new ReplaceEdit(2, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 2, 0);
    assertEquals(t1, 2, 1);
    assertEquals(e2, 2, 1);
    Assert.assertEquals("Buffer content", "01x3456789", fDocument.get());
    doUndoRedo(undo, "01x3456789");
}
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

MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)32 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)32 Test (org.junit.Test)30 UndoEdit (org.eclipse.text.edits.UndoEdit)23 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)15 TextEdit (org.eclipse.text.edits.TextEdit)15 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)13 RangeMarker (org.eclipse.text.edits.RangeMarker)11 DeleteEdit (org.eclipse.text.edits.DeleteEdit)6 ISourceModifier (org.eclipse.text.edits.ISourceModifier)4 InsertEdit (org.eclipse.text.edits.InsertEdit)4 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)3 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)2 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)2