can Java reflect not only .Class file
Hi' i'm newbie in this topic, i'm really appreciate if somebody can help me..cos i'm really stuck in here...
My Problems are :
1. i want to ask about this, can Java reflect from .java file?
2. i'm using Eclipse IDE, i'm really interesting about how JTree or Package Explorer in Eclipse can always displaying update information about class structure? but .java files not compiled, how can? if Eclipse using reflection, .java files must be compiled first, correct me if i'm wrong?
The fact is Eclipse don't have to compiled .java files to get the update information about class structure and displaying in JTree or package Explorer...how implement like this?
what i mean like this :
ex : if i type int x = 100; (not only int, it could be anything else..) at the working files, JTree or Package Explorer in Eclipse can always update the informasion about class structure, but .java files not compiled..
i hope my question are easy to understand, i really need some help..
Thanks a lot..
There's two possibilities here
1) Eclipse performs background compilation of the Java sources, then performs reflection on those temporary classes
2) Eclipse has access to the results of the Java source code parser, and can extract the information from the java syntax parser, before it gets to the compilation stage.
regards,
Owen
hey, thanks for the answers, but i would like to ask :
>> 1) Eclipse performs background compilation of the Java sources, then performs reflection on those temporary classes
++ if i'm using this way, how about the performance? seems that it will be compiled all the time right?
>> 2) Eclipse has access to the results of the Java source code parser, and can extract the information from the java syntax parser, before it gets to the compilation stage.
++ how to implement this? what do you mean about java syntax parser?
do you know where i can find any article about this?
thanks a lot again...
I'm not directly familiar with any source code of these IDEs, but I'm pretty sure "real" reflection is not used. To use java's reflection, you have to load the class. This cannot be undone. You can load a class more than once using different classloaders, but this gets expensive really quickly. Also, reflection is rather expensive and it doesn't support many of the IDE's features like getting the names of method parameters. My guess is that IDEs use javacc or some custom implementation that directly parses the source or class file into a format that is interpreted by the IDE. You might check out eclipse's source if you're interested. Eclipse even uses its own configurable java compiler, so I suspect that their code is pretty cool.
hey,,,the link that you gave, that's so funny man,,,i think someone already gave it to you first...hehehehe...but it's ok..thanks a lot for the answer, it really gave me some pictures..