Watching variables contents in Eclipse IDE - java

How can I watch the contents of several variables (for example, TreeSet's) simultaneously? I can watch contents of one TreeSet, clicking on it in "Variables" window, but I have no idea how to do that for several variables.

You can use Expressions windows: while debugging, menu window -> Show View -> Expressions, then it has place to type variables of which you need to see contents

You can add a watchpoint for each variable you're interested in.
A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. Unlike breakpoints (which are line-specific), watchpoints are associated with files. They take effect whenever a specified condition is true, regardless of when or where it occurred. You can set a watchpoint on a global variable by highlighting the variable in the editor, or by selecting it in the Outline view.

You can do so by these ways.
Add watchpoint and while debugging you can see variable in debugger window perspective under variable tab.
OR
Add System.out.println("variable = " + variable); and see in console.

And how about selecting the text you want to watch, and then using the shortcut "Ctrl + shift + I"

Related

Eclipse hover variable debug never working for local variables

During the debuging, most of time i am forced to select a variable and right click display to see its value.
for exemple for this, it always works, but never for local variables? (or lets say most of time)
here its working (without right click display):
here its not !? :

Eclipse in debug mode do not show variable content?

I am not sure if it is recent issue or it was from the "beginning". Is it normal behavior that we can't see the value of variable in debug mode when we tick on it? (It says ctr+shift+I to watch).
You can also use ctrl + shift + D to display the selected content.
Whatever you are trying to get the contents debug should reach that code.
No, this isn't normal behaviour in Eclipse. As soon as a thread hits a breakpoint and enables the debugging perspective, you should be able to inspect your variables either by hovering, Ctrl+Shift+I or with "Inspect" in your context menu.
In what state is Eclipse when you are trying to watch the variable?

In Eclipse, is it possible to find, where, a certain function, class or variable is called?

When you want to open the declaration of a class/function/variable in java you can press Ctrl and click on it, but is there are way to go the other way round? If you had to find all instances where a function or variable is called how would you quickly get that?
Ctrl + Alt + H shows you all the places where a variable or method is used or called.
On both Windows and Mac, right-click the method, and choose "Open Call Hierarchy."
You can use this for identifiers other than methods. For example, if a class does not have an explicit constructor, you can use this to find all the callers of its default constructor.

Watching variable to see if it changes value

I'm debugging my code to see if the variable is receiving new values during execution.
How can I watch it and make it stops when the value is changed by something?
I've got a CheckList and set the selectedValues with some values, and for some reason, the values selected are disappearing.
Use the outline view (Window -> Show View -> Outline) to select your variable. Right-click it and select Toggle Watchpoint. It will create a breakpoint for your variable. Right-click this breakpoint, select properties and leave only the checkbox "Field modification" enabled.
I think that this cannot be done for variables declared inside methods, although you can use it for class or instance variables.
You could use a breakpoint with a condition for the value.
You could set a breakpoint on the setter method for the value.
If the debugger does appear to help. esp if the problem doesn't appear when you debug it. You can add logging which can show you where a change is made. e.g.
log.info("Changed "+changeDescription, new Throwable("HERE"));

How to get back auto-completion after misspelling a method name in Eclipse?

When I am coding Java in Eclipse I like the auto-completion feature. With that I mean the popup with method-names that comes when you start typing in a method name for an object. Or maybe it's called something different, i.e. method-suggestions?
But the popup is hidden if I misspells a method name, and it doesn't come back if I delete the misspelled part of the method name. Is there any way to get back the popup after a misspelling without starting to type in the hole method name again?
Press Ctrl+ (Blank). For a complete list of keyboard shortcuts have a look in the eclipse "Preferences" and there "General/Keys".
You should also check out Preferences->Java->Editor->Content Assist. You'll be able to select how it acts; things like if you use it in the middle of a word should it insert or overwrite, should it show deprecated methods, the delay before it automatically appears, and it can even (try to) guess your method parameters based on the variables in the current scope.
I think you're after the Ctrl-Space keyboard shortcut.
(In Eclipse this is called Content Assist. In Visual Studio it's called IntelliSense.)

Categories