I'm using a visitor system with the Java JDT to read in source code. I am looking to find a method call for example :
System.out.println(i);
I understand the visitor pattern so I need something like :
public boolean visit(MethodPattern node) {
//code here
}
but I don't know what the type of node should be so that I would have access to information in the method call. Such as "i" in the first example or s in the following example:
foo(String s)
I don't know where you have taken the method signature visit(MethodPattern node)
from. But you could override visit(MethodInvocation node)
in order to be able to inspect method invocations. Then you can use the passed node to query method arguments and the like.
public class MyVisitor extends org.eclipse.jdt.core.dom.ASTVisitor {
public boolean visit(MethodInvocation node) {
List<?> arguments = node.getArguments();
// do something with the arguments, etc.
}
}