• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameter Names  RSS feed

 
Shanki Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am writing a Class Browser , am able to list all the methods along with their parameter types but am not able to get the parameter names and the local variables declared inside those methods. I understand that it is not possible to get this using refelection. Pls let me know as to how to acheive this. I have a question if this is not possible

1) How are decompilers able to retrieve the methods along with the parameter names and type and the local variables. ?

Thanks in advance
Shanki
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dissamblers (e.g., javap) can get parameter and variable name information for classes compiled with the -g switch (generate all debug information) but in general it's not possible.

Variables and parameters are offsets in the stack frame so no symbols are required required.

Rather than -g (there's no API to get that information anyway) use Java 5.0 meta data facilities: annotations. That's documented, defined, always available and easy to use. You can annotate parameters, fields, u-name-it.
 
Shanki Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response Rick. But i just wonder as to how the decompilers like JODE are able to retrieve these information.

Thanks
Shanki
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> I wonder how decompilers like JODE are able to retrieve this information.

Unless they examine the source they aren't retrieving that information from standard javac compiled sources. They make up the names using numeric offset information.

This is the only javac that I know of that will suck up and process all of the method parameter names and local variable names with no additional switches:

http://www.javac.com.au/
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanki, since JODE is listed on sourceforge, why don't you have a look through the source code and see what they do:

http://cvs.sourceforge.net/viewcvs.py/jode/jode/
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!