making comment a entire method at one time - java

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.

Related

Differentiate between typing and pasting in JTextField

i've been looking around and haven't been able to find any solution to this problem: i have a JTextField and i want to do some things when the user paste something in there, i've found this: What event to use when pasting something in a JTextField?
which works ok, except that i want only to do things when the user paste something, not when it writes on the text field, i've though of saving the previous value of it and compare it with the new, and if it was empty and now is not, do things, but this won't work since it will enter in that condition when the user types the first letter in the text field.
If anyone knows how to do it whit the documentListener or whit any other listener it would be of grate help.
Update: since various people has asked, the reason i want to do this is because the text will come from a bar code reader or some similar device.
except that i want only to do things when the user paste something
Why should pasted text be treated any different than typed text? Sounds like a design issue. If you specify a better reason/requirement for doiong this we might be able to come up with a better solution.
i want to do some things when the user paste something in there
You might be able to override the paste() method of the JTextField. Just override the method to invoke super.paste() and then add your custom code.
how to do it whit the documentListener
Maybe you would consider a "paste" to mean more than one character is added at a time. In which case you just test the length of the String that is added to the Document.
I was able to fix my problem by configuring my bar code scanner and making it send a "new line" after each reading, and executing my code every time this happens with the actionPerformed of the JTextField. Thanks to everybody who tried to help.

Comment out methods using the Outline view in Eclipse

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.

Is there any way to set breakpoints on all methods of a class?

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.

Eclipse folding with java

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.

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