Search in sources :

Example 6 with SourceLocation

use of org.autorefactor.jdt.internal.corext.dom.SourceLocation in project AutoRefactor by JnRouvignac.

the class ObsoleteRemoveSemiColonCleanUp method maybeRemoveSuperfluousSemiColons.

private boolean maybeRemoveSuperfluousSemiColons(final ASTNode visited, final int start, final int end) {
    if (end <= start) {
        return true;
    }
    boolean result = true;
    Map<String, SourceLocation> nonCommentsStrings = getNonCommentsStrings(visited, start, end);
    for (Entry<String, SourceLocation> entry : nonCommentsStrings.entrySet()) {
        String s = entry.getKey();
        // $NON-NLS-1$
        Matcher m = Pattern.compile("\\s*(;+)\\s*").matcher(s);
        while (m.find()) {
            int startPos = entry.getValue().getStartPosition();
            SourceLocation toRemove = SourceLocation.fromPositions(startPos + m.start(1), startPos + m.end(1));
            ASTRewrite rewrite = cuRewrite.getASTRewrite();
            rewrite.remove(toRemove);
            result = false;
        }
    }
    return result;
}
Also used : SourceLocation(org.autorefactor.jdt.internal.corext.dom.SourceLocation) Matcher(java.util.regex.Matcher) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite)

Aggregations

SourceLocation (org.autorefactor.jdt.internal.corext.dom.SourceLocation)6 Comment (org.eclipse.jdt.core.dom.Comment)3 Matcher (java.util.regex.Matcher)2 ASTRewrite (org.autorefactor.jdt.core.dom.ASTRewrite)2 BlockComment (org.eclipse.jdt.core.dom.BlockComment)2 LineComment (org.eclipse.jdt.core.dom.LineComment)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 NotImplementedException (org.autorefactor.util.NotImplementedException)1 Pair (org.autorefactor.util.Pair)1 Javadoc (org.eclipse.jdt.core.dom.Javadoc)1