"syso" shortcut in Eclipse- changing a bit behaviour - java

I look for some trick which gives me possibility to change the syso behaviour in Eclipse (please assume that below there is Eclipse´s editor), now it works in this way:
syso%someVariable
% - means the plase when i typed ctrl + space, and result is:
System.out.println();someVariable
but I want to have of course without copying text..:
System.out.println(someVariable);
Any hints ? :-) Thanks in advance !

Reference
The feature is called "code templates" in Eclipse. You can add templates with Preferences->Java->Editor->Templates. Two good articles:
http://eclipse.dzone.com/news/effective-eclipse-dont-write-c
http://eclipse.dzone.com/news/effective-eclipse-custom-templ
Also, this SO question:
Useful Eclipse Java Code Templates
System.out.println() is already mapped to sysout, so you may save time by learning a few of the existing templates first.

If you wan´t to change current template you can press shift + end (to select 'someVariable') and then press ctrl + space and up, enter to select sysout.

Answering the original question or at least how I understood it:
Modify the existing template syntax for sysout (Preferences->Java->Editor->Templates find sysout and select edit) to read:
System.out.println(${cursor});
Now you can type syso and then ctr+space and instantly get the output:
System.out.println(<cursorHere>);
Or as you put it:
System.out.println(someVariable);
...with the cursor inside the brackets which is indeed more efficient than starting after the semicolon.

Related

Automatic code formatting for Eclipse IDE

I use many brackets and braces when I code. Be it casting multiple times, casting multiple times in if blocks, etc. I sometimes get lost in the brackets and also, hate putting a lot of them.
Is there any short-cut key to format this selected part of code?
I have tried Ctrl-Shift-F, but that doesn't give me what I want.
Note: I work on Eclipse Mars.
What you want is Source menu | Cleanup, then customize the profile to add the remove extra parenthesis. From the Code Style tab check the Use parenthesis in expressions Only if necessary. And then complete the wizard:
That changes:
super.start(((BundleContext)(context)));
to:
super.start(context);
As an extra you can set your project to do code cleanup tasks on save automatically if you desire.
did you try ctrl+3 and type formate? for me Ctrl-Shift-F was bound by other app and cause eclipse to miss catching it.
search for formatter Java->code style->formatter
There is a tab Braces.
If you select specific lines and press Ctrl + Shift + F eclipse will only format the lines you selected according to your formatter.

How to invoke method/constructor parameter hint in IntelliJ?

If I write code sequentially, then after I enter some method call and opening parenthesis, I get a hint after delay:
if I discard it or return to the place later, I see no any hint:
How to invoke it without retyping the code?
Ctrl+P will give you a pop-up with the method parameters. Usefully, the parameter corresponding to your cursor position will be highlighted and will change as you move back and forth through the parameters.
Intellij provides a lot of assistance. See here for a summary of what's available.
I faced the same condition in the earlier days.
No need to retype the complete code but just retype the comma(,) intellij is intelligent enough to guess the next variable value and suggest you better. I used this many times so far and made me to save my time in all instances.
Hope i was useful.
On Mac the shortcut is ⌘ (Command) + P.
It works fine.

Netbeans hotkey to show overloaded version(s) of a Java method?

At the moment, when write code and get into a method that has many overloaded versions, Ctrl-Space will display the overloaded list as snapshot #1 below.
After I choose one version, I want to switch to another overloaded version but I don't know what hotkey to reshow the overloaded list, as shown in snapshot #2. Currently I have to delete the arguments and hit Ctrl-Space again which is quite tiring to me.
What is the hotkey to reshow that list then?
I think there's no way to do what you want. I took a look at the shortcuts configuration and didn't find anything.
Ctrl + Space is related to code completion. Hitting Ctrl + Z again can work if you selected the method with less parameters.
Maybe the best alternative is to hit Ctrl + Z after the wrong completion. It will restore the state just before the wrong selection. Then hit Ctrl + Space again.

Search a code line in Eclipse

I'm developing a code in Eclipse (java). While debugging the code, I used a lot of System.out.println(...). Now I need to delete all these lines. To do this, I wrote System.out.println in Search->Java, but it hasn't provided any search result. So, how can I find all occurancies of this string System.out.println?
Search -> File. Input "System.out.println" and select the type of files you want to search in "*.java" (without quotes)
The "Java search" is something different. It doesn't allow you to find stuff in java files but methods/declarations/etc. in java files. For instance declare somewhere in your project "String canYou = "FindMe?";" and then do Search -> Java, input "String" and select "Type" and hit search. It should find all the String uses in you project, including the aforementioned one.
Try writing System.out.println anywhere in your project, select this text and afterwards press ctrl + alt + g (sorry don't know exactly what kind of search this stands for) and it will give you all the occurrences of this string in all your projects(workspace-wise). I'm 100% sure it stands for exactly something in search > java - you can take a closer look to see for exactly what. Other than that you can have a conditional execution for the logs - i.e
if(Consts.DEBUG){
Log("something");
}
press Control + H
this will open up the search window, go to File Search tab and look for the system.out.println(
just search for println. I bet eclipse is interpreting what you are putting in as a regex.
I would do Find usages on the println method (ctrl+shift+g)
Use the menu Search->File and in the "Containing Text" field type in "System.out.println*", in the "File name patterns" field type in "*.java". Now press the "Replace" button in the lower right corner. Leave blank the "With" field and click the "Preview" button. Uncheck any occurrences you want to keep and then press "OK".
You may want to make sure your code is in version control before attempting this in case you do it wrong and want to go back.
We have written an eclipse plugin to do the same. It will find the System.out.println in your java code and comment it out. We will soon have a version which will delete it also. Hope this is useful.
http://eclipseo.blogspot.in/2013/05/commenting-systemoutprintln-from.html

How to access Java API within netbeans and another question

I just have two specific questions that over the years I have never been able to figure out in netbeans.
How do I access the Java API documentation without having to use my web browser. It would be nice if I could have a window in netbeans of the Java API. Is this not possible? How do you normally access the API document? Note that I don't mean just access for the documentation for the current code (cntrl-space, I think)... I just mean for browsing.
Code completion will automatically generate right brackets (which I like). When this occurs, the cursor is still within the brackets. How do you jump out of the brackets without mousing? I know a command to move to the end of line, but sometimes the brackets aren't at the end of the line... it seems like there should be a way to just jump to the end of the autocompletion.
For 2) I honestly just use the right arrow.
re 1) I guess you are looking for: Windows -> Others -> Javadoc
Additionally if you use Shift-F1 (instead of Alt-F1) on e.g. a classname it will show the documentation in the internal browser as well.
re 2) I don't think there is a shortcut for this, but you might be able to do this with a (recorded) keyboard macro (by searching for a closing bracket).
You can open the JavaDoc window
with Window > Other > JavaDoc
Typing the closing bracket or
parenthesis just puts you outside of
the generated brackets

Categories

Resources