Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classes referenced in a class

 
Rahul Dias
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to use BCEL.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate it, Thanks!

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic