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. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~