use of org.eclipse.text.edits.TextEditVisitor in project xtext-eclipse by eclipse.
the class TextChangeCombiner method addIfNotDuplicate.
protected void addIfNotDuplicate(MultiTextEdit multiTextEdit, final TextEdit editToBeAdded) {
final boolean[] overlaps = new boolean[] { false };
TextEditVisitor textEditVisitor = new TextEditVisitor() {
@Override
public boolean visitNode(TextEdit edit) {
overlaps[0] |= !(edit instanceof MultiTextEdit) && edit.covers(editToBeAdded);
return super.visitNode(edit);
}
};
multiTextEdit.accept(textEditVisitor);
if (!overlaps[0])
multiTextEdit.addChild(editToBeAdded.copy());
}
use of org.eclipse.text.edits.TextEditVisitor in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method overlaps.
private boolean overlaps(TextEdit edits, TextEdit edit2) {
final SourceLocation range = toSourceLoc(edit2);
final AtomicBoolean overlaps = new AtomicBoolean();
edits.accept(new TextEditVisitor() {
@Override
public boolean visit(MultiTextEdit edit) {
// move on there is nothing to check here
return VISIT_SUBTREE;
}
@Override
public boolean visitNode(TextEdit edit) {
if (!overlaps.get()) {
overlaps.set(range.overlapsWith(toSourceLoc(edit)));
}
return !overlaps.get();
}
});
return overlaps.get();
}
use of org.eclipse.text.edits.TextEditVisitor 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.TextEditVisitor in project flux by eclipse.
the class Utils method getOffsetAdjustment.
public static int getOffsetAdjustment(TextEdit edit, final int offset) {
final int[] holder = new int[] { 0 };
edit.accept(new TextEditVisitor() {
@Override
public boolean visit(DeleteEdit edit) {
if (offset >= edit.getOffset()) {
holder[0] -= edit.getLength();
}
return super.visit(edit);
}
@Override
public boolean visit(InsertEdit edit) {
if (offset >= edit.getOffset()) {
holder[0] += edit.getText().length();
}
return super.visit(edit);
}
@Override
public boolean visit(ReplaceEdit edit) {
if (offset >= edit.getOffset()) {
holder[0] += edit.getText().length() - edit.getLength();
}
return super.visit(edit);
}
});
return holder[0];
}
use of org.eclipse.text.edits.TextEditVisitor in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method overlaps.
private boolean overlaps(final TextEdit edits, final TextEdit edit2) {
final SourceLocation range = toSourceLoc(edit2);
final AtomicBoolean overlaps = new AtomicBoolean();
edits.accept(new TextEditVisitor() {
@Override
public boolean visit(final MultiTextEdit edit) {
// Move on there is nothing to check here
return true;
}
@Override
public boolean visitNode(final TextEdit edit) {
if (!overlaps.get()) {
overlaps.lazySet(range.overlapsWith(toSourceLoc(edit)));
}
return !overlaps.get();
}
});
return overlaps.get();
}
Aggregations