use of org.autorefactor.refactoring.SourceLocation in project AutoRefactor by JnRouvignac.
the class RemoveSemiColonRefactoring method removeSuperfluousSemiColons.
private boolean removeSuperfluousSemiColons(ASTNode node, int start, int end) {
if (end <= start) {
return VISIT_SUBTREE;
}
boolean result = VISIT_SUBTREE;
final Map<String, SourceLocation> nonCommentsStrings = getNonCommentsStrings(node, start, end);
for (Entry<String, SourceLocation> entry : nonCommentsStrings.entrySet()) {
final String s = entry.getKey();
final Matcher m = Pattern.compile("\\s*(;+)\\s*").matcher(s);
while (m.find()) {
int startPos = entry.getValue().getStartPosition();
SourceLocation toRemove = fromPositions(startPos + m.start(1), startPos + m.end(1));
this.ctx.getRefactorings().remove(toRemove);
result = DO_NOT_VISIT_SUBTREE;
}
}
return result;
}
use of org.autorefactor.refactoring.SourceLocation in project AutoRefactor by JnRouvignac.
the class RemoveSemiColonRefactoring method putResult.
private void putResult(String source, int start, int end, final LinkedHashMap<String, SourceLocation> results) {
final SourceLocation sourceLoc = fromPositions(start, end);
final String s = sourceLoc.substring(source);
results.put(s, sourceLoc);
}
use of org.autorefactor.refactoring.SourceLocation in project AutoRefactor by JnRouvignac.
the class RemoveEmptyLinesRefactoring method maybeRemoveEmptyLines.
private boolean maybeRemoveEmptyLines(String source, int endOfLineIndex, int newLineIndex) {
if (endOfLineIndex < newLineIndex) {
Matcher matcher = NEWLINE_PATTERN.matcher(source).region(endOfLineIndex, newLineIndex);
boolean isEqualToNewline = matcher.matches();
if (!isEqualToNewline && matcher.find() && matcher.end() < newLineIndex) {
final SourceLocation toRemove = SourceLocation.fromPositions(matcher.end(), newLineIndex);
this.ctx.getRefactorings().remove(toRemove);
return true;
}
}
return false;
}
use of org.autorefactor.refactoring.SourceLocation in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method getIndentForJavadoc.
private SourceLocation getIndentForJavadoc(LineComment lineComment, String source, TreeSet<Integer> lineStarts) {
final SourceLocation indentLoc = getIndent(lineComment, lineStarts);
final Matcher matcher = INDENT.matcher(source).region(indentLoc.getStartPosition(), indentLoc.getEndPosition());
if (matcher.matches()) {
return indentLoc;
}
return SourceLocation.fromPositions(0, 0);
}
use of org.autorefactor.refactoring.SourceLocation 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();
}
Aggregations