Search in sources :

Example 6 with ErrorProneToken

use of com.google.errorprone.util.ErrorProneToken in project error-prone by google.

the class ParameterName method checkArguments.

private void checkArguments(Tree tree, List<? extends ExpressionTree> arguments, VisitorState state) {
    if (arguments.isEmpty()) {
        return;
    }
    MethodSymbol sym = (MethodSymbol) ASTHelpers.getSymbol(tree);
    if (NamedParameterComment.containsSyntheticParameterName(sym)) {
        return;
    }
    int start = ((JCTree) tree).getStartPosition();
    int end = state.getEndPosition(getLast(arguments));
    String source = state.getSourceCode().subSequence(start, end).toString();
    if (!source.contains("/*")) {
        // fast path if the arguments don't contain anything that looks like a comment
        return;
    }
    Deque<ErrorProneToken> tokens = new ArrayDeque<>(ErrorProneTokens.getTokens(source, state.context));
    forEachPair(sym.getParameters().stream(), arguments.stream(), (p, a) -> {
        while (!tokens.isEmpty() && ((start + tokens.peekFirst().pos()) < ((JCTree) a).getStartPosition())) {
            tokens.removeFirst();
        }
        if (tokens.isEmpty()) {
            return;
        }
        Range<Integer> argRange = Range.closedOpen(((JCTree) a).getStartPosition(), state.getEndPosition(a));
        if (!argRange.contains(start + tokens.peekFirst().pos())) {
            return;
        }
        checkArgument(p, a, start, tokens.removeFirst(), state);
    });
}
Also used : MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ErrorProneToken(com.google.errorprone.util.ErrorProneToken) JCTree(com.sun.tools.javac.tree.JCTree) ArrayDeque(java.util.ArrayDeque)

Aggregations

ErrorProneToken (com.google.errorprone.util.ErrorProneToken)6 JCTree (com.sun.tools.javac.tree.JCTree)5 ArrayDeque (java.util.ArrayDeque)3 Builder (com.google.errorprone.fixes.SuggestedFix.Builder)2 MethodTree (com.sun.source.tree.MethodTree)2 ModifiersTree (com.sun.source.tree.ModifiersTree)2 Tree (com.sun.source.tree.Tree)2 VariableTree (com.sun.source.tree.VariableTree)2 Function (com.google.common.base.Function)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Predicates (com.google.common.base.Predicates)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getLast (com.google.common.collect.Iterables.getLast)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 CharStreams (com.google.common.io.CharStreams)1