This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Classes referenced in a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Classes referenced in a class" Watch "Classes referenced in a class" New topic
Author

Classes referenced in a class

Rahul Dias
Greenhorn

Joined: Jul 05, 2005
Posts: 3
Hi

Is it possible to get a list of all classes referenced in a class?.
I can get all class variables using getDeclaredClasses() method in Class object, but how do i get the classes of local variable used inside a method
?
Can anyone help?
Thanks in advance.
Rahul
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm not sure if there are APIs from the Class object, but the format of the class file is well documented and not too hard to parse. Some of the tools that seek out all references for dependency mapping just read the class files that way. A quick Google for "java class file format" got THIS. See if that approach is at all promising.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You may be able to use BCEL.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Rahul",
Welcome to the JavaRanch!

We're light on rules, but one we take quite serioulsy is the one on display names.

We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and fix your display name.

thanks,
Dave.
Rahul Dias
Greenhorn

Joined: Jul 05, 2005
Posts: 3
yep!!!
parsing the class file seems to be the right step
thaks James, David

David:
Sorry about the disp. name
I have change the display name

cheers

Rahul
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I appreciate it, Thanks!

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classes referenced in a class
 
Similar Threads
get allclasses from java file
javac problem
class loader
Local inner classes
Could we have classes inside methods