tags:

views:

25

answers:

1

Hi, I making a eclipse view that is working with selected elements from other views. Let say I have opened a java file in the editor that has the following fields in it: private String world = " world!" private String hello = "hello" + world;

When I select "hello" in the Outline view I'm able to get IFiled selection and I have access to it's properties, but what i need is the true value of the field ("hello world!"). Any idea how can I do that? Thanks.

A: 

There is no value information available for variables before runtime (maybe except constant values), so such expressions cannot be evaluated (except using some serious inference about the variables). And I don't think these expressions could be evaluated even in theory, because the referenced variables might gain their values even from external input (that cannot be available during compiletime).

On the other hand, it is possible to evaluate such conditions using the JDT Debugger, there is a Display view for such reasons, and or the Inspect options. This way it is possible to get the selected values, as they can be read from the JVM. On the other hand, this information is not available in the Java AST but you have to use the debugger model.

Zoltán Ujhelyi
Can you give me a hint on how to use it ...I can't seem to find any information about that, or maybe I'm not searching properly. oh ..and yes this will be used only on constant values.
Yasko
I don't know the exact structure of the code, but I would look at the source code of the org.eclipse.jdt.debug.ui plug-in.The debugger does not rely on the fact that only constant values are used, instead can evaluate every single item. On the other hand, as in case of AST this cannot be guaranteed, I don't think, any simple solution is possible (e.g. you have to manually evaluate the constants, but I don't know that area very much).
Zoltán Ujhelyi
Well another "solution" I came up with is to load the classes I need from the project's output directory ..and use reflection to get the values. I'll also look at debug.ui. Thanks for the help :)
Yasko