Bytecode method signatures corresponding to a MethodDeclaration node [message #913318] |
Sat, 15 September 2012 08:28  |
Eclipse User |
|
|
|
Hello,
I am using JDT's ASTParser in combination with a static analysis tool that works only with Java bytecode. To do so, I have to map information extracted using JDT to bytecode level information. Currently, I am stuck with computing bytecode-level method signatures for each method declared in the source code. I found that computing this mapping is straight-forward except in cases like the following.
In the following code, the doInBackground method in the MyTask class corresponds to two methods in the bytecode of MyTask class.
class AsyncTask<Params, Progress, Result> {
abstract protected Result doInBackground(Params... params);
}
class MyTask extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... params) {
}
}
The signatures of the two methods in bytecode (obtained from javap) are:
protected java.lang.Void doInBackground(java.lang.String[]);
protected java.lang.Object doInBackground(java.lang.Object[]);
Now my question is: Given the org.eclipse.jdt.core.dom.MethodDeclaration node corresponding to doInBackground method in the MyTask class, how can I compute the second signature from above? Specifically, are there JDT API methods that I can use for my purpose? I can compute the first signature.
Thanks so much!
Saswat
ps: I am using JDT's ASTParser totally outside of eclipse in a headless mode.
[Updated on: Sat, 15 September 2012 08:38] by Moderator Report message to a moderator
|
|
|
Re: Bytecode method signatures corresponding to a MethodDeclaration node [message #913508 is a reply to message #913318] |
Sat, 15 September 2012 21:12  |
Eclipse User |
|
|
|
If you build your AST with ASTParser#setResolveBindings(true) then your MethodDeclaration can answer to resolveBinding(). The resulting IMethodBinding (plus linked ITypeBinding;s) should hold all the information you are looking for.
Note, that setResolveBindings(true) requires more work to be done (and more memory be held), so use it only when needed.
Additionally, org.eclipse.jdt.core.Signature has various utility methods for working with signatures in different formats.
HTH,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.02662 seconds