Search in sources :

Example 1 with DeleteEdit

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

the class StubUtility method fixEmptyVariables.

// remove lines for empty variables
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
    IDocument doc = new Document(buffer.getString());
    int nLines = doc.getNumberOfLines();
    MultiTextEdit edit = new MultiTextEdit();
    HashSet<Integer> removedLines = new HashSet<Integer>();
    for (int i = 0; i < variables.length; i++) {
        // look if Javadoc tags have to be added
        TemplateVariable position = findVariable(buffer, variables[i]);
        if (position == null || position.getLength() > 0) {
            continue;
        }
        int[] offsets = position.getOffsets();
        for (int k = 0; k < offsets.length; k++) {
            int line = doc.getLineOfOffset(offsets[k]);
            IRegion lineInfo = doc.getLineInformation(line);
            int offset = lineInfo.getOffset();
            String str = doc.get(offset, lineInfo.getLength());
            if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
                int nextStart = doc.getLineOffset(line + 1);
                edit.addChild(new DeleteEdit(offset, nextStart - offset));
            }
        }
    }
    edit.apply(doc, 0);
    return doc.get();
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DeleteEdit(org.eclipse.text.edits.DeleteEdit) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) IRegion(org.eclipse.jface.text.IRegion) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with DeleteEdit

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

the class DocumentUndoManagerTest method testCompoundTextEdit.

public void testCompoundTextEdit() throws ExecutionException, BadLocationException {
    final int RANDOM_STRING_LENGTH = 50;
    final int RANDOM_REPLACE_COUNT = 100;
    assertTrue(RANDOM_REPLACE_COUNT >= 1);
    assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
    String original = createRandomString(RANDOM_STRING_LENGTH);
    final IDocument document = new Document(original);
    createUndoManager(document);
    // fUndoManager.beginCompoundChange();
    MultiTextEdit fRoot = new MultiTextEdit();
    TextEdit e1 = new DeleteEdit(3, 1);
    fRoot.addChild(e1);
    fRoot.apply(document);
    fRoot = new MultiTextEdit();
    TextEdit e2 = new DeleteEdit(3, 1);
    fRoot.addChild(e2);
    fRoot.apply(document);
    // fUndoManager.endCompoundChange();
    assertTrue(fUndoManager.undoable());
    // while (fUndoManager.undoable())
    fUndoManager.undo();
    assertTrue(!fUndoManager.undoable());
    final String reverted = document.get();
    assertEquals(original, reverted);
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DeleteEdit(org.eclipse.text.edits.DeleteEdit) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit)

Example 3 with DeleteEdit

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

the class TextEditTests method testUndefinedMultiEdit5.

@Test
public void testUndefinedMultiEdit5() throws Exception {
    MultiTextEdit m2 = new MultiTextEdit();
    m2.addChild(new DeleteEdit(4, 2));
    m2.addChild(new DeleteEdit(1, 3));
    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 4 with DeleteEdit

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

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

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