I understand that this question is quite old, but I want to publish this solution in case future googlers accidentally stumble upon it :)
The EijiAdachi workaround posted in the comments should work, but there is a more βcorrectβ way to do this, which I found while searching for a solution.
In order for ASTNode to correctly resolve bindings, you first need to fully analyze the contents of the page. This is done using the method (somewhat strangely called IMHO) ASTNode.accept(ASTVisitor) . Therefore, if you subclass ASTVisitor, you can override visiting methods for all types of ASTNode that you are interested in and add them to the data structures available after a full AST analysis.
In this example, all MethodDeclaration nodes will be available in the root directory of the CompilationUnit node (see the OP for this via the ASTParser class):
public class MethodVisitor extends ASTVisitor { private final List <MethodDeclaration> methods = new ArrayList <> (); @Override public boolean visit (final MethodDeclaration method) { methods.add (method); return super.visit (method); } public List <MethodDeclaration> getMethods () { return Collections.unmodifiableList (methods); } }
Any of the other ASTNode subtypes can be rounded using the same process (you can create separate types of visitors or put all of this into one).
If anyone is interested, you can find a more complete example in this article .
source share