diff --git a/java/ql/src/semmle/code/java/Expr.qll b/java/ql/src/semmle/code/java/Expr.qll index aef353088bec..4b977d9b9355 100755 --- a/java/ql/src/semmle/code/java/Expr.qll +++ b/java/ql/src/semmle/code/java/Expr.qll @@ -1953,6 +1953,15 @@ class Argument extends Expr { /** Gets the position of this argument. */ int getPosition() { result = pos } + /** + * Gets the parameter for which this argument is a value. If this argument is part + * of an implicit varargs array this predicate has no result. + */ + Parameter getParameter() { + result = call.getCallee().getParameter(pos) and + not isVararg() + } + /** * Holds if this argument is an array of the appropriate type passed to a * varargs parameter. @@ -1976,6 +1985,12 @@ class Argument extends Expr { /** Holds if this argument is part of an implicit varargs array. */ predicate isVararg() { isNthVararg(_) } + /** + * If this argument is part of an implicit varargs array gets the + * varargs parameter it is a value for. Otherwise has no result. + */ + Parameter getVarargsParameter() { isVararg() and result = call.getCallee().getVarargsParameter() } + /** * Holds if this argument is part of an implicit varargs array at the * given array index. diff --git a/java/ql/src/semmle/code/java/Member.qll b/java/ql/src/semmle/code/java/Member.qll index e9d4fe82978d..78cecab80606 100755 --- a/java/ql/src/semmle/code/java/Member.qll +++ b/java/ql/src/semmle/code/java/Member.qll @@ -171,6 +171,9 @@ class Callable extends StmtParent, Member, @callable { /** Gets the formal parameter at the specified (zero-based) position. */ Parameter getParameter(int n) { params(result, _, n, this, _) } + /** Gets the varargs (variable arity) parameter, if any. */ + Parameter getVarargsParameter() { result = getAParameter() and result.isVarargs() } + /** Gets the type of the formal parameter at the specified (zero-based) position. */ Type getParameterType(int n) { params(_, result, n, this, _) }