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);
});
}
Aggregations