What's the purpose of "bindingKeys" in the "createASTs" method for the "AST [message #1780861] |
Mon, 29 January 2018 06:03  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04846 seconds