Search in sources :

Example 1 with SimpleDocument

use of org.eclipse.jdt.internal.core.util.SimpleDocument in project eclipse.jdt.ls by eclipse.

the class TextEditConverter method applySourceModifier.

private String applySourceModifier(String content, ISourceModifier modifier) {
    if (StringUtils.isBlank(content) || modifier == null) {
        return content;
    }
    SimpleDocument subDocument = new SimpleDocument(content);
    TextEdit newEdit = new MultiTextEdit(0, subDocument.getLength());
    ReplaceEdit[] replaces = modifier.getModifications(content);
    for (ReplaceEdit replace : replaces) {
        newEdit.addChild(replace);
    }
    try {
        newEdit.apply(subDocument, TextEdit.NONE);
    } catch (BadLocationException e) {
        JavaLanguageServerPlugin.logException("Error applying edit to document", e);
    }
    return subDocument.get();
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) SimpleDocument(org.eclipse.jdt.internal.core.util.SimpleDocument) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

SimpleDocument (org.eclipse.jdt.internal.core.util.SimpleDocument)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)1 TextEdit (org.eclipse.text.edits.TextEdit)1