I’m looking for a way to locate which MethodInvocation expressions utilize the parameters declared by the caller method.
For example:
public void caller(int param1, int param2){
m1(param1)
m2(param2)
m3(param1, m4(param2))
}
I want to be able to identify that the m1 method invocation utilized ‘param1’, and that the m2 method invocation utilized ‘param2’, and that m3 utilized ‘param1’ and ‘param2’. Can I do this with an ASTVisitor? I’ve had no luck because MethodDeclaration.parameters() provides a list of SingleVariableDeclaration while MethodInvocation.arguments() provides a list of Expression. I do not see a link between SingleVariableDeclaration and Expression. I could just analyze them by their names, but that would be far too naive.
Bindings are the definitive way to identify a variable, field, method, class etc. Here, you need to compare the IVariableBinding of the parameter declaration and the reference.