File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Getting local variable names and their data types in a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Getting local variable names and their data types in a java program

Amol Parikh
Greenhorn

Joined: May 29, 2012
Posts: 11
I am writing a code which gets all the function names, function parameters , return type ,variable names as well as their data types using the reflection API. The problem I am facing is the information related to the variables is limited only to static class variables. I would also like to get the names and data types of the local variables inside different methods as well. If you guys could help me out with it. Thanks a lot...
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 888
    
    9
You don't get static variables only. You can also get instance variables using the clazz.getFields() method.
You however, cannot get local variables declared in methods using reflection. For that you'd need some debugging API and byte code manipulation languages like ASM.
You should try to find reasons not to have to do any of this.
Amol Parikh
Greenhorn

Joined: May 29, 2012
Posts: 11
What do you mean when you say some debugging api?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 888
    
    9
Amol Parikh wrote:What do you mean when you say some debugging api?

http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/

Again, please do yourself a favor and find/invent reasons for not having to do this.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Repeatedly asking the same question is not going to get you a different answer.
First time
Second time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting local variable names and their data types in a java program
 
Similar Threads
xml, servlet, velocity architecture
Please help!
Parameter Names
definitions
Getting a variable type using reflection