use of org.eclipse.text.edits.DeleteEdit in project flux by eclipse.
the class Utils method editsToJsonArray.
public static JSONArray editsToJsonArray(TextEdit edit) {
final LinkedList<JSONObject> list = new LinkedList<JSONObject>();
edit.accept(new TextEditVisitor() {
@Override
public boolean visit(DeleteEdit delete) {
try {
JSONObject json = new JSONObject();
json.put("offset", delete.getOffset());
json.put("length", delete.getLength());
json.put("text", "");
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(delete);
}
@Override
public boolean visit(InsertEdit insert) {
try {
JSONObject json = new JSONObject();
json.put("offset", insert.getOffset());
json.put("length", 0);
json.put("text", insert.getText());
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(insert);
}
@Override
public boolean visit(ReplaceEdit replace) {
try {
JSONObject json = new JSONObject();
json.put("offset", replace.getOffset());
json.put("length", replace.getLength());
json.put("text", replace.getText());
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(replace);
}
});
return new JSONArray(list);
}
use of org.eclipse.text.edits.DeleteEdit in project che by eclipse.
the class CorrectPackageDeclarationProposal method addEdits.
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.text.correction.CUCorrectionProposal#addEdits(org.eclipse.jdt.internal.corext.textmanipulation
* .TextBuffer)
*/
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
super.addEdits(doc, root);
ICompilationUnit cu = getCompilationUnit();
IPackageFragment parentPack = (IPackageFragment) cu.getParent();
IPackageDeclaration[] decls = cu.getPackageDeclarations();
if (parentPack.isDefaultPackage() && decls.length > 0) {
for (int i = 0; i < decls.length; i++) {
ISourceRange range = decls[i].getSourceRange();
root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
}
return;
}
if (!parentPack.isDefaultPackage() && decls.length == 0) {
String lineDelim = StubUtility.getLineDelimiterUsed(cu);
//$NON-NLS-1$
String str = "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim;
root.addChild(new InsertEdit(0, str));
return;
}
root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
use of org.eclipse.text.edits.DeleteEdit in project AutoRefactor by JnRouvignac.
the class SourceRewriter method addEdits.
/**
* Adds the edits contained in the current instance to the provided edits for the provided document.
*
* @param document the document to edit
* @param edits where to add edits
*/
public void addEdits(IDocument document, TextEdit edits) {
for (SourceLocation loc : this.removals) {
edits.addChild(new DeleteEdit(loc.getStartPosition(), loc.getLength()));
}
for (Entry<SourceLocation, String> entry : this.replacements.entrySet()) {
SourceLocation loc = entry.getKey();
String replacement = entry.getValue();
edits.addChild(new ReplaceEdit(loc.getStartPosition(), loc.getLength(), replacement));
}
}
use of org.eclipse.text.edits.DeleteEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testCovers1.
@Test
public void testCovers1() throws Exception {
InsertEdit insert = new InsertEdit(1, "");
DeleteEdit delete = new DeleteEdit(2, 2);
Assert.assertEquals(false, insert.covers(delete));
}
use of org.eclipse.text.edits.DeleteEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testDelete2.
@Test
public void testDelete2() throws Exception {
TextEdit e1 = new DeleteEdit(4, 1);
TextEdit e2 = new DeleteEdit(3, 1);
TextEdit e3 = new DeleteEdit(5, 1);
fRoot.addChild(e1);
fRoot.addChild(e2);
fRoot.addChild(e3);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(fRoot, 3, 0);
assertEquals(e1, 3, 0);
assertEquals(e2, 3, 0);
assertEquals(e3, 3, 0);
Assert.assertEquals("Buffer content", "0126789", fDocument.get());
doUndoRedo(undo, "0126789");
}
Aggregations