Get the value of a selected java field in a eclipse view - eclipse

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.

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.

Related

Anylogic: can you type a probability distribution into an edit box?

In the simulation window, before the run, I'd like to change some probability distributions (e.g. delay time) by typing, for example, "triangular(5, 20, 15)" into a specific editbox linked to a variable.
I know how to do this with static values, but I couldn't figure out how to do the same with probability distributions.
AnyLogic offers a built-in functionality for that with com.anylogic.engine.database.CodeValue.
It is originally meant that a distribution function stored as text in the internal database can be parsed to java code and executed, but it actually also works without the database and for any kind of code. It is the same idea as in Benjamin's answer, just that you do not need to add any external java library.
Use it like this:
CodeValue myCode = new CodeValue(this,"....java code to be executed");
myCode.execute();
And in your specific case, assuming you have a variable named variableA and an editbox named editbox, use the following to evaluate the expression, get a value and set it for the variable:
CodeValue myCode = new CodeValue(this,"variableA = "+editbox.getText());
myCode.execute();
Obviously, allowing the user to type any command there and running it without a check or error treatment is a bad idea, be aware of that.
This is a Java issue. You need to convert a String (your editbox content) to executable code. Not straight-forward but also not impossible, see Convert String to Code and similar posts.

MATLAB member function suggestion

If for example you have acquired a object of type handleplot with expression like below:
handle = plot(t,functoin1 , t , function2 ) ;
Now handle will be an array that contains two elements, handle(1) and handle(2). Now suppose you want to change some properties of one of these objects, like set a LineWidth, change the Color, or the like.
Is there any way in which you can activate auto-completion or suggestions when you type handle(1). (note the memebership operator .)? I am looking for the automatic suggestions that MATLAB provides for member functions in a combobox near the blinking cursor, similar to the way other IDEs provide this feature:
MATLAB's objects support tab completion. After typing handle(1). simply hit tab and you will receive a list of available methods and properties of the graphics object.
If you want more help on a method, you will also get a popup dialog of the method and the accepted input arguments.
If you want to programmatically get a list of properties of an object, you can use properties
properties(t)
If you want a listing of all properties and their values, just use get
get(t)
i use this method ...
for example i'm writing a program in matlab editor and when im want to know the properties of an object just stop coding and run the program , know it's have my object (for example handle) and know i can write the properties(handle) in command window to know the exact properties of handle . as Suever says .

Debug in Eclipse, for lazy people

When I define Breakpoint in Eclipse I can inspect variables's values by hovering mouse over it. Also I can switch to Debug perspective and perform more advanced tasks, like writing custom expressions and change value of variables.
I'd like to know if is it possible to perform some of these task in window which opened when I hovering mouse over variable? For example to write custom expression to translate Java Calendars object's value to human readable format on the fly, etc.
Thank you!
You can define a custom formatter that overrides the default toString() implementation of a type in Window->Preferences->Java->Debug->Detail Formatters:

Intellij IDEA insert variable names in methods

I'm using Intellij IDEA 13 for android development.
Some methods has long list of parameters. For example, db.query(...) and I can't remember the order of them.
Is there any plugin or can i change some settings to make IDEA insert variables from function template?
Thanks
You have a couple of options. Ctrl+P will show a lit of the parameters, with the current one bolded. As long as you have either the source or javadoc for the library (or JDK/SDK) attached to the corresponding definition, you will see the parameters' names.
If you invoke code completion while entering parameters, IDEA will show at the top only ones that are of the correct type. Furthermore, if one of you local variables is the same name (or similar to) the required parameter's name, it will be at the top of the list. So if there is a method that takes an int named 'width', and I have several int variables, but one is named 'theWidth', it would be at the top. (Again, this assumes you have javadoc or source attached so IDEA can determine parameter names.) If IDEA can find local variables that satisfy all parameters (or all the first x parameters) of the method, there will be an option in the code completion list to complete all of them, The icon will be a double circle. The below screen shot shows how the HttpServletReqest is at the top of the list. So I do not have to remember if the parameter order is "request, response" or "response, "request". Notice the fourth option is to complete both the request and the response.

Eclipse plugin that allows customized view of variables/objects while debugging

While using C++ I have to deal with programs that have objects like matrices, linked lists etc
The default view of eclipse for variables while debugging is not very useful. It normally shows pointer values with value of only the first element in the array.
Below is how it is in eclipse:
As we can see the matrix object has rows and columns integers and a double 2D array. I cannot see the values of the array in user friendly manner.
My question is that, is there anyway in eclipse (using plugin etc) through which I can define custom user interfaces (popups) for each object/class of my interest.
For example I would like to have the following (Matlab's view) kind of popup when I hover over an initialized matrix object:
The JDT has a feature called detail formatters to make that possible. The corresponding implementation for the CDT seems to have stalled after a first prototype however, and did not make it into Eclipse.