show array in single line in debug view in eclipse - java

Arrays in my debug view in eclipse are shown element-by-element downwards. This makes it difficult visually if I have too many arrays since I have to keep scrolling and cannot see all of them on a single screen.
Is there a way to see the array in a single line in the Variables section of the debug view in Eclipse?

You can use the below snippet to print in one line.
java.util.Arrays.toString(theArray);

There's no way (that I know of) of showing the array in a single line in the Variables View. I don't have eclipse installed in this PC but, as Kulbhushan said, you can try to execute the code
java.util.Arrays.toString(array);
in the Display View (to open it go to Window > Show View > Display).

Related

Eclipse debug mode view instance variable values

I am trying to view the instance variables values of the Arraylist in eclipse in debug mode but apart from the values in the list am unable to view variables like elementData or modCount that are part of the arraylist. I have tried using Watch, Display option as well but to no avail. Below is my screenshot after setting the breakpoint and triggering the program run:
Below is the screenshot that I found in one of the websites where the instance variables like elementData,modCount and size are visible:
In the current version (Oxygen.3) the default formatter for Collection shows only the members of the collection as an array. I'm not sure when the more detailed formatter was removed, but you can easily create a logical structure formatter.
Right click on the variable in the Variables tab and select Show Logical Structure/Edit Logical Structure
Your view will have the Collection entry hilighted, and won't contain the ArrayList entry I just created.
Add a new entry:
Provide the class name you want to format, and a description. Select List of Variables and then add the variables you want to display, providing a code snippet for each one. The code snippet executes as a method of the class.
End result:
In oxygen, "Show Logical Structure" is enabled by default. All you have to do is click on it to disable it.
[Image taken from eclipse.org]
In some instances that I cannot view variables, like in your case, I would suggest using Expression tab and add new expression. To load expression tab on Eclipse IDE, click on Window > Show View > Expression. Set breakpoint, hit debug, then expression tab should load arrNames and you can expand to view properties and data.
Go to Window->show view->expressions then in Expressions window go to variables tab
there you will see your variables right click on any one of them you will see Show logical structure.
Untick the Array option from there and debug again you will see elementData,modCount and size varibles.click here for image

Is there an easy way to show borders around Views and ViewGroups in the design tab of Android Studio for debugging and styling purposes?

I would like to see visually how much space each box takes with as little effort/changes to the code as possible.
I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.
Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.
Here someone asks a different but slightly related question with not a nice answer for my case.
Here someone gives an answer on how to outline one View.
Border for an Image view in Android?
Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.
To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="#drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.
There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.

Java Eclipse evaluate expression

Is it possible to evaluate a expression in Eclipse similar to IntelliJ. Where you can dynamically type code and the result will be displayed during debug?. I know it does something similar "Display" but you need to highlight code that has been written (so you cant write any new code unless you re-compile).
Perhaps there are plugins that i could use?. I have just started using eclipse
There is a Display view as well that can do exactly what you want. Go to Window > Show view > Display (or Other... if the Display view is not there. In the Display view, you can type any code you want during debug (content assist is available). The current objects and variables are also available to use. After you wrote your code, you have to highlight it, right click and select Execute or hit CTRL-U. You may play around with the other possible actions as well.
Besides that, you can also write in the source code during debug and evaluate it using Display as you mentioned, if you have the source for the class you are debugging.
1 - Type your expression inside a method that you are debugging
2 - Select that code
3 - Press CTRL + SHIFT + I
4 - Eclipse will evaluate your expression and show the results in a floating window
You can change variable values on the fly using the Debug perspective.
The top right corner of Eclipse should have the variables view from which you can select a variable name and change its value. You can also set conditional breakpoints by selecting the breakpoints view in the top right corner of Eclipse. Right-click on the breakpoint and select breakpoint properties. Check the conditional checkbox and write an expression that only when it evaluates as true does the program suspend during Debugging.
Change Variable Values during Debug
Conditional Breakpoints
Although Display View works; There are two ways else to evaluate an expression.
In the context of the debugging session, we can write and run custom code to evaluate possibilities. This is done in the Debug Shell. For example, if we need to cross-check the correctness of the sqrt functionality, we could do it in the Debug Shell. On the code, Right-click -> Inspect to see the value.
You can select an expression then open Context Menu -> Inspect or press CTRL + Shift + I, during debugging, the result will be displayed.
Select any expression in your code. Then right-click and select "Display" (or press the associated key-combination).
For completely new expressions, use the Display view. It's like a scrapbook for expressions. If the Display view is not visible, select Window > Show view > Display to add it. Then type any expression in the view, and do the same thing as for expressions in your code: select the expression, right-click and select "Display".
For expressions that you want to always see the value of, every time execution is halted, use the Expressions view instead.

How to display huge variables in eclipse IDE

Some of my variables are huge (include tables with so many rows). When I try to see the variables via variables view in Eclipse, it shows a part of it, not the all. So, I need to use system.out.println("myVariable"); to see, what my variable contains, and this not an effective way.
Is there a way to get over this? Or do you offer a better solution than sys.out.println?
The best I would suggest is to use the display view:
menu -> window -> show view -> debug ->display
inside the display view, type the variable name, right click and select display. Still if short, use the sysout statement there, and again, right click and select display.
Hope this helps.
In Variables window we have grid with list of variables and a field with variable signification below. Right click on this field => "Max Lenght ..."

Jump-To-Code-Line Eclipse Shortcuts

is it possible, in Eclipse, to mark certain lines with Shortcuts and be able to quickly jump to those lines?
Example: Let's say I have maintenanceHeavyMethod() at line 120 in my class, gameLoop() at line 800 and some listener at line 1460.
I'd like to f.ex. press CTRL+SHIFT+1, 2, 3 etc. to mark those positions, and then use f.ex. CTRL+1, 2, 3 to immediately jump to them. I don't like split-screens etc, but I need to jump around when writing.
Is there such a feature?
I'm using latest Eclipse to write Java-programs.
You can add Bookmarks in your code. Select the code fragment you want to bookmark and then go to Edit > Add Bookmark... (also possible via the menu available with a right-click in the left hand column of the editor, like breakpoints).
Then, add the Bookmarks view. Select Window > Show View > Other... > Bookmarks and you'll get something like this:
Sadly, I don't think you can bind a shortcut to a particular bookmark.
Just in case, the shortcut to jump to a particular line is CTRL+L.
That would be best taken care by mylyn:
Define a task with this three method, and you will be to see only those 3 in the package explorer view
To jump to a particular method, I use ctrl+o and then start typing the method. If you're a proficient typist, this shouldn't take any longer; keep in mind that you only have to start typing the name of the method.
Unfortunately this isn't a proper solution for jumping to a line of code within a method.
You can jump to methods by using the outline view. Outline view shows all the Methods, Fields, and Inner-Classes (and their methods and fields and inner-classes...etc) of the source file you currently have open. I personally prefer this method, unless I have a stacktrace and know which line I want to jump to, in which case I use ctrl+L.

Categories