Skip to content

Java: Add Argument.getParameter() #5188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions java/ql/src/semmle/code/java/Expr.qll
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions java/ql/src/semmle/code/java/Member.qll
Original file line number Diff line number Diff line change
@@ -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, _) }