private static ImmutableList<VarSymbol> getFormalParametersWithoutVarArgs( MethodSymbol invokedMethodSymbol) { List<VarSymbol> formalParameters = invokedMethodSymbol.getParameters(); /* javac can get argument names from debugging symbols if they are not available from other sources. When it does this for an inner class sometimes it returns the implicit this pointer for the outer class as the first name (but not the first type). If we see this, then just abort */ if (!formalParameters.isEmpty() && formalParameters.get(0).getSimpleName().toString().matches("this\\$[0-9]+")) { return ImmutableList.of(); } /* If we have a varargs method then just ignore the final parameter and trailing actual parameters */ int size = invokedMethodSymbol.isVarArgs() ? formalParameters.size() - 1 : formalParameters.size(); return ImmutableList.copyOf(formalParameters.subList(0, size)); } }
if (args.size() == 1 && (formatMethodSymbol == null || formatMethodSymbol.isVarArgs())) { Type type = ASTHelpers.getType(Iterables.getOnlyElement(args)); if (type instanceof Type.ArrayType
if (declaredMethod.isVarArgs() && i == params.size() - 1) { if (i >= argumentTypeRequirements.size()) {
if (!methodSymbol.isVarArgs()) { return false;
boolean hasTrustMeAnno = m.attribute(syms.trustMeType.tsym) != null; Type varargElemType = null; if (m.isVarArgs()) { varargElemType = types.elemtype(tree.params.last().type);
private Type visitMethodInvocationOrNewClass( List<? extends ExpressionTree> arguments, MethodSymbol sym, Type type) { int idx = arguments.indexOf(current); if (idx == -1) { return null; } if (type.getParameterTypes().size() <= idx) { if (!sym.isVarArgs()) { if ((sym.flags() & Flags.HYPOTHETICAL) != 0) { // HYPOTHETICAL is also used for signature-polymorphic methods return null; } throw new IllegalStateException( String.format( "saw %d formal parameters and %d actual parameters on non-varargs method %s\n", type.getParameterTypes().size(), arguments.size(), sym)); } idx = type.getParameterTypes().size() - 1; } Type argType = type.getParameterTypes().get(idx); if (sym.isVarArgs() && idx == type.getParameterTypes().size() - 1) { argType = state.getTypes().elemtype(argType); } return argType; }
private void removeByIndex(List<? extends Tree> trees) { if (trees.size() == 1) { fix.delete(getOnlyElement(trees)); return; } int startPos; int endPos; if (index >= 1) { startPos = state.getEndPosition(trees.get(index - 1)); endPos = state.getEndPosition(trees.get(index)); } else { startPos = ((JCTree) trees.get(index)).getStartPosition(); endPos = ((JCTree) trees.get(index + 1)).getStartPosition(); } if (index == methodSymbol.params().size() - 1 && methodSymbol.isVarArgs()) { endPos = state.getEndPosition(getLast(trees)); } fix.replace(startPos, endPos, ""); } }.scan(state.getPath().getCompilationUnit(), null);
private static ImmutableList<VarSymbol> getFormalParametersWithoutVarArgs( MethodSymbol invokedMethodSymbol) { List<VarSymbol> formalParameters = invokedMethodSymbol.getParameters(); /* javac can get argument names from debugging symbols if they are not available from other sources. When it does this for an inner class sometimes it returns the implicit this pointer for the outer class as the first name (but not the first type). If we see this, then just abort */ if (!formalParameters.isEmpty() && formalParameters.get(0).getSimpleName().toString().matches("this\\$[0-9]+")) { return ImmutableList.of(); } /* If we have a varargs method then just ignore the final parameter and trailing actual parameters */ int size = invokedMethodSymbol.isVarArgs() ? formalParameters.size() - 1 : formalParameters.size(); return ImmutableList.copyOf(formalParameters.subList(0, size)); } }
if (i == argsLength - 1 && !applyVarargs && methSym != null && methSym.isVarArgs()) { if (arg instanceof JCIdent && ((JCIdent) arg).sym instanceof VarSymbol) { VarSymbol var = (VarSymbol) ((JCIdent) arg).sym; if (var.owner instanceof MethodSymbol && ((MethodSymbol) var.owner).isVarArgs() && ((MethodSymbol) var.owner).getParameters().last() == var) { print("...");
if (i == formalParams.size() - 1 && methodSymbol.isVarArgs()) {
callee.isVarArgs() ? expandVarargsToArity(callee.getParameters(), sourceNode.args.size()) : callee.getParameters().stream()
|| !ASTHelpers.getSymbol(enclosingMethod).isVarArgs() || ASTHelpers.hasAnnotation(enclosingMethod, FormatMethod.class, state)) { return Description.NO_MATCH;
&& methodSymbol.isVarArgs() && p.type instanceof ArrayType && !state.getTypes().isAssignable(a.type, p.type)) {
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { MethodSymbol sym = ASTHelpers.getSymbol(tree); if (!sym.isVarArgs()) { return NO_MATCH;
if (!methodSymbol.isVarArgs()) { return false;
endPos = ((JCTree) trees.get(index + 1)).getStartPosition(); if (index == methodSymbol.params().size() - 1 && methodSymbol.isVarArgs()) { endPos = state.getEndPosition(getLast(trees));
if (param.equals(sym.getParameters().last()) && sym.isVarArgs()) { break; // TODO(b/121273225): support varargs
@Nullable private Type visitMethodInvocationOrNewClass( List<? extends ExpressionTree> arguments, MethodSymbol sym, Type type) { int idx = arguments.indexOf(current); if (idx == -1) { return null; } if (type.getParameterTypes().size() <= idx) { if (!sym.isVarArgs()) { if ((sym.flags() & Flags.HYPOTHETICAL) != 0) { // HYPOTHETICAL is also used for signature-polymorphic methods return null; } throw new IllegalStateException( String.format( "saw %d formal parameters and %d actual parameters on non-varargs method %s\n", type.getParameterTypes().size(), arguments.size(), sym)); } idx = type.getParameterTypes().size() - 1; } Type argType = type.getParameterTypes().get(idx); if (sym.isVarArgs() && idx == type.getParameterTypes().size() - 1) { argType = state.getTypes().elemtype(argType); } return argType; }
@Override public Description matchMethodInvocation( MethodInvocationTree methodInvocationTree, VisitorState state) { if (!MATCHER.matches(methodInvocationTree, state)) { return Description.NO_MATCH; } if (methodInvocationTree.getArguments().size() % 2 == 0) { return Description.NO_MATCH; } List<? extends ExpressionTree> arguments = methodInvocationTree.getArguments(); MethodSymbol methodSymbol = getSymbol(methodInvocationTree); if (methodSymbol == null || !methodSymbol.isVarArgs()) { return Description.NO_MATCH; } Type varArgsArrayType = getLast(methodSymbol.params()).type; Type lastArgType = ASTHelpers.getType(getLast(arguments)); if (arguments.size() == methodSymbol.params().size() && ASTHelpers.isSameType(varArgsArrayType, lastArgType, state)) { return Description.NO_MATCH; } return describeMatch(methodInvocationTree); } }