Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Bytecode method signatures corresponding to a MethodDeclaration node
Bytecode method signatures corresponding to a MethodDeclaration node [message #913318] Sat, 15 September 2012 04:28 Go to next message
Saswat Anand is currently offline Saswat Anand
Messages: 1
Registered: September 2012
Junior Member
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 04:38]

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 17:12 Go to previous message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 984
Registered: July 2009
Senior Member
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
Previous Topic:Question about Breakpoint Tabs when looking at breakpoint properties
Next Topic:How to call the difference view on two Java files
Goto Forum:
  


Current Time: Wed Jul 30 11:34:44 EDT 2014

Powered by FUDForum. Page generated in 0.01805 seconds