I was wondering if there exists some sort of plugin for Eclipse to add onto the Outline view that will comment out blocks of methods.
This would be useful for me during unit testing and I want to retest specific failing methods while leaving alone the ones I know will pass.
My current workaround is simply using
/*
unit test code
*/
You can select blocks then do CTRL+/ and Ctrl+Shift+/
Ctrl+/ comments all selected lines each with //
Ctrl+Shift+/ Comments out all selected lines with /* */
Doing it again uncomments
To select an entire method from within a method (may require multiple chains), press Alt + Shift + Up. To traverse methods, Ctrl + Shift + Up or Down.
Depending on where you are in the method, it will select the following things in ascending order (approximately).
parent object
individual statement or method call
full line
enclosing brackets
enclosing if/else, for, while loop structures
method declarations
class declarations
Then, using the comment shortcut provided in the other answer, you can quickly navigate and comment.
Related
I find it useful to have fields colored in different way than local variables so that I find it easier to visually read the code flow.
In the same way, I would like to color method calls acting on the current instance, so that they look different from method calls acting on other instances (regardless of their type). This should affect interface methods, inherited methods, abstract methods...
These methods are most of the time self-documenting code, or duplicated code that was refactored but not deemed worthy enough of having another class handle the common logic. Therefore I find it useful to visually see I'm not leaving the responsibility of this class.
How can I achieve this in IntelliJ Idea?
I am writing this question because I have found a similar question related to Android Studio while looking for an answer to this, but when I tried to google/search the question days later it was absolutely painful as it did not come up anywhere in the search results, I did not remember how I found it in the first place. I'm writing this question in the hopes it will be useful to any future reader having the same question.
There's a way, but it's a workaround, it will have side effects.
How:
Go to File > Settings > Inspections (Choose the Global Profile if necessary).
Type in the search: qualified.
Tick the checkbox next to "Instance method call not qualified with 'this'".
Click on Severity > Edit severities, add new entry by clicking the green + button.
Name it whatever you want.
You must put it at the bottom of the list using the arrows. If you don't, the F2 key will no longer work as you expect it as it will prioritize errors at the top of the list.
Set the Error stripe mark to #FFFFFF, or the same color as the scrollbar.
Set it bold if you wish.
If you want to set a color, you must set a background color to white (or black if you have a black interface). If you don't, the color will appear black in most conditions.
If you really want to, do the same for "Unnecessary 'this' qualifier"; there is an additional checkbox to make it only apply to methods and not fields.
Side effects:
This enables inspections, which is not desired.
Pointing the mouse cursor onto the method calls will cause a hover text to appear describing the inspection.
If your code has no errors, no warnings, and no additional informative inspections, pressing F2 will jump through these calls.
sometimes it happens that we need to make comment a entire method in Java and reactive, more than once in same code in same time to test something. so is there any way in eclipse by which a method can be commented from its start or end, without going to the end and start for making comment?
First Drag Mouse and Select the Method then
Press Left(cntrl+shift+/) to comment
Press Left(cntrl+shift+\) to uncomment
Position on the method name and use Alt+Shift+Up twice to select the entire method. Then use Ctrl+/ to comment the selected text.
I implemented DnD between 2 JTables in my java applet.
It works fine: when I drag a line from one table to another (or from a table to itself - reordering), it copies to the destination and removed from the origin.
The problem is when I drag a line outside the java window. The cursor shows like a circle showing that this drag is illegal, exportData() is called anyway, and I don't know how to identify whether the DnD was legal or not?
This is important because only if it was legal, I would want to remove the line from the origin JTable...
I guess, you are talking about the TransferHandler class. Then, exportData does only the preparation of the transfer; exportDone is the method to override and implement the removal for the case action==MOVE. By the way, the API documentation for both methods clearly describes this.
Is there any way to set breakpoints on all methods of a given class?
I have a huge (2300 lines) legacy class and I need to set breakpoints on all method calls to understand how this mess works.
You can follow the steps below:
Run -> View breakpoints -> Add -> Java Method Breakpoints
Class pattern -> full reference of your class (e.g., mypackage.MyClass)
Method Name -> * (i.e., asterisk wild card)
I have discovered workaround :
1. I have set "Toggle Brakepoint" hotkey to Alt+Numpad 0.
2. After that you can click on first method
3. Use "Toggle Brakepoint"
4. Alt+Down - goto Next Method. ( Alt+Up - goto Previous Method. )
5. Repeat 3 step.
This is similar to Sergey Senkov's answer, but without hotkeys.
In the structure view, click on the first method. Repeat the following for each method:
Context Menu Key
M to toggle the method breakpoint.
Down
There is a plugin for idea:
Simple Toggle All Method Breakpoint.
It allows you to breakpoint all methods / clear all method's breakpoints in one click from context menu on class in Project view.
As Andrey Lavrukhin suggested, there is Simple Toggle All Method Breakpoint, install it through Settings -> Plugins. Works perfectly.
The only way you'll be able to do what you want is to set method breakpoints on each and every method with the class in question. You need to click on the left hand gutter next to the method - a little red circle with 4 dots will appear and you may get a warning saying method level breakpoints can impact performance. You can then further configure the breakpoint (by rightclicking on it, or select shift+F8) and set it so that it breaks on entry, exit or both
I'm afraid theres no way to do this in a single step/setting.
Working with eclipse in a java collapsed file if i try to write a method between two collapsed methods when I write public and press space automatically the ide collapses the word public inside the method below.
State initial
- public methodA()
- public methodC()
Step 1:
- public methodA()
public
- public methodC()
Eclipse bug
- public methodA()
- public methodC() //Error because public is declared twice!
If I write the method faster the problem doesn't occur. Any form to avoid this weird behaviour without disable code folding?
Thanks in advance
What I do is to unfold the method before where I want to insert the code. Then it doesn't actually fold the new text into the previous (folded) method. But the simplest way is probably to just not fold the code and use the outline view to navigate around the file.
You really have only a few things you can do besides disabling folding. Even though the "public" you just typed gets folded into the following method it is still present in the text and the cursor is still just after the last letter. You can:
Continue typing and the public will become visible, as will the following method that was previously folded. This will through off the formatting, though.
Press Enter. This will move you to the next line and unfold the following method, but it will disentangle the code you're typing from that next method. You're on the next line after the "public" but the formatting stays nice. Just typing a backspace will get the cursor back into the right place and you can continue typing from there.