Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » What's the purpose of "bindingKeys" in the "createASTs" method for the "AST
What's the purpose of "bindingKeys" in the "createASTs" method for the "AST [message #1780861] Mon, 29 January 2018 06:03 Go to next message
Eclipse UserFriend
To first explain what my goal is:

For a given "Method Invocation", I want to find where the matching "Method Declaration" is. This is not limited to a single file. For example, if a method, `foo()`, is declared in `A.java` and that file is imported and called in `B.java`, I want to get a MethodInvocation type object that is representing the call of `foo()` from `B.java` that is bound to MethodDeclaration type object from `A.java`.

In doing so, I need to parse an entire project. To do that I'm using the following function:

     public void createASTs(String[] sourceFilePaths,
                        String[] encodings,
                        String[] bindingKeys,
                        FileASTRequestor requestor,
                        IProgressMonitor monitor)


For the bindingKeys, apparently I have to do something like this:
new String[] { BindingKey.createTypeBindingKey("java.lang.Iterable") };
and explicitly give all the types that you want to find bindings of.

(I don't understand the purpose of this. Why does this exist for `createASTs` but not `createAST`?)

I want to get bindings of all types. Is that not possible?
Re: What's the purpose of "bindingKeys" in the "createASTs" method for the " [message #1780960 is a reply to message #1780861] Tue, 30 January 2018 08:20 Go to previous message
Eclipse UserFriend
For your use case bindingKeys should not be needed, as the javadoc explains these essentially trigger invocations of ASTRequestor.acceptBinding().
For your case parser.setResolveBinding(true) should be sufficient in order to get resolved bindings.

To get from the binding of the MethodInvocation to the desired MethodDeclaration you may consult the JDT FAQ, or you may get inspiration from existing (internal) code, like, e.g. org.eclipse.jdt.internal.corext.fix.NullAnnotationsRewriteOperations.Builder.findCUForMethod(CompilationUnit, ICompilationUnit, IMethodBinding)

HTH
Stephan
Previous Topic:Can I use JDT to parse Java project strictly using command-line?
Next Topic:With JDK set to jdk1.8.0_152, Tomcat in Eclipse tries to use JRE1.8.0_144 and fails
Goto Forum:
  


Current Time: Tue Jul 08 05:58:31 EDT 2025

Powered by FUDForum. Page generated in 0.04846 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top