Skip to main content

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 08:28 Go to next message
Saswat Anand is currently offline Saswat AnandFriend
Messages: 1
Registered: September 2012
Junior Member

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!

ps: I am using JDT's ASTParser totally outside of eclipse in a headless mode.

[Updated on: Sat, 15 September 2012 08: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 21:12 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
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.

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: Mon Apr 15 22:33:18 GMT 2024

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

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

Back to the top