Re: Java Reflection with local variables
ash wrote:
I agree with the idea that you need to look at this as a debug type of
operation, processing stack frames, rather than as reflection.
Can you explain at a higher level what you are trying to do?
Patricia
What i am trying to do is to be able to invoke some code (maybe a
Class) dynamically ( this can be done in many ways and i know how )
and then be able to access all of my Class's information ( local
variables , global variables , objects, methods, while loop
structures, .... etc. everything written in the code) and specify some
kind of condition to generate an event ( for example a specific
variable value has been changed) from the event i can then access to
variable's new value. But all of this should happen in run time.
This sounds exactly like what a debugger does. You set a "watch" and
the watch gets updated so that the user can see the new value.
Also, you seem at least somewhat experienced, but I want to point out
that most of the time this is done not with a debugger but by having the
class do this work for you.
In other words, the class has been designed so that you can receive
messages when its internal values change, and the class itself will send
the event.
In Java, you can do this with a Listener (often called an Event
Listener), an Observer and an Observable, or a Property Change Listener.
This will let you receive changes with out using a debugger.
But if you have to see everything, right down to the while loops, a
debugger it is. JPDA looks like a good start. Also check out things
called de-compilers:
<http://www.program-transformation.org/Transform/JavaDecompilers>