Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to get the list of class names accessed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there way to get the list of class names(with package name) and method names invoked for a given class(Source).
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not aware of any way to get the list of class names by giving the package names. If you can get the list of "fully qualified class names" in a jvm, then you can filter by the package name.

In a previous project we accomplished the above by creating a map betwen package name and class names.

If you can get a class you can get the list of Methods using reflection api.
 
DharmendraKumar Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Class(X.java). I need to get all the classes accessed from X.java with package name and also the method invoked. Hope now it wud be clear.
 
Marshal
Posts: 27379
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have the compiled version of the class (X.class) then I believe the "javap" command displays something that contains that information.
 
DharmendraKumar Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a <b>Java file</b>(X.java). I need to get all the classes accessed from X.java with package name and also the method invoked.

For ex I have a Java file (X.java). It invokes couple of DAOs and Utility classes. I just need to write a tool to fetch all the class names accessed from the java source file(X.java).

X.java invokes
abc() method of Xyz.java (Package - pkg.sample)
cde() method of Jke.java (Package - pkg.sample)

I need to write a tool which fetches the list of classes(Xyz & Jke) invoked with Package name(pkg.sample) and method name (abc() & cde()).
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by DharmendraKumar Sharma:
Is there way to get the list of class names(with package name) and method names invoked for a given class(Source).



There must be a way to get such a list, because the compiler needs to do such things.
You might look at tools.jar to find out, how they do it.
You could parse all import statements for imported packages + java.lang (because of "Foobar".replaceAll ("o", "i"); ).
Parse your file for all Class-invokations and methodcalls.
Study the JLS to find out, how nameconflicts are avoided.
...
Another approach would be to look at Open-Source-Software, how it is managed there (eclipse for example).
...
Compiling the class and using reflection would be the fastest solution I guess. Dynamical compiling is again possible with tools.jar, but you have to take care about the special license for that jar (it isn't part of the jre).
[ December 16, 2005: Message edited by: Stefan Wagner ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This information is in the class file in a well-documented and readable format. Surely easier than keeping track of imports and class references in raw source. This will only help you find "static" class references, and won't spot any class.forName( name ).newInstance() style creation.

We use a tool with an interesting approach ... they insert a custom class loader immediately after the boot loader and keep track of all classes loaded. It works as long as all other custom class loaders delegate to their parents correctly.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic