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();
}
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);
}
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());
}
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());
}
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());
}
Aggregations