Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Classes used in a class

Thread view: 
Gregor Kovač - 18 Jan 2006 14:11 GMT
Hi!

Is it possible to get all class names that are used in a specific class?
For example you have code:
String a = "AAAA";
MyClass c = new MyClass();

and the tool would return String, MyClass

Best regards,
       Kovi

Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

| Gregor Kovac | Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
|            Experience Linux.               |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Oliver Wong - 18 Jan 2006 15:00 GMT
> Hi!
>
[quoted text clipped - 4 lines]
>
> and the tool would return String, MyClass

   Yes, it's certainly possible, because a compiler has to do this before
it can perform the type checking phase.

   If your next question is "where can I download such a tool?",
unfortunately I don't know of any such tool. If you have some experience
writing parsers, writing the tool yourself should be easy enough, since you
can get a grammar for Java on various sites on the net. If not, then you'd
better start learning!

   - Oliver
IchBin - 18 Jan 2006 17:05 GMT
>> Hi!
>>
[quoted text clipped - 15 lines]
>
>     - Oliver

Do you meen something like this...

public class FieldTypes
{
    public static void main(String[] args) {
        GridBagConstraints g = new GridBagConstraints();
        printFieldNames(g);
     }

     static void printFieldNames(Object o) {
        Class c = o.getClass();
        java.lang.reflect.Field[] publicFields = c.getFields();
        for (int i = 0; i < publicFields.length; i++) {
           String fieldName = publicFields[i].getName();
           Class typeClass = publicFields[i].getType();
           String fieldType = typeClass.getName();
           System.out.println("Name: " + fieldName +
             ", Type: " + fieldType);
           }
        }
  }

Signature

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

Oliver Wong - 18 Jan 2006 23:11 GMT
>>> Hi!
>>>
[quoted text clipped - 35 lines]
>         }
>   }

   This is a good start, but I don't think you can use reflection to peer
into the bodies of methods to check for references to classes there.

   - Oliver
Chris Uppal - 18 Jan 2006 15:11 GMT
Gregor Kovaè wrote:

> Is it possible to get all class names that are used in a specific class?

You can get that kind of information rather easily by parsing the .class files.
There are several libraries that will do the hard work of parsing for you, so
it's just a matter of learning how to use them.

   -- chris
Gregor Kovač - 20 Jan 2006 10:10 GMT
>> Is it possible to get all class names that are used in a specific class?
>
[quoted text clipped - 3 lines]
>
>     -- chris

Yes, there are. Since I'm using NetBeans all the time, I just used their
plugin.
I got a solution in just one line :)))

Best regards,
  Kovi

Signature

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

| Gregor Kovac | Gregor.Kovac@mikropis.si    |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
|            Experience Linux.               |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.