Is there an option to do the following in InteliJ IDEA automatically? Or some macro or something?
From:
a.equals(b)
To
b.equals(a)
There are times when there is a NPE in the first operand and so it breaks the flow. Like when comparing some string from an object to an enum value. Clean code says it should be like enum.equals(value) and I want to do this at the press of keyboard shortcut.
If you put your cursor anywhere within a.equals(b) (even if it's after the closing parenthesis) and then press Alt-Enter, then you'll get a menu which includes "Flip '.equals'", which does exactly what you want.
An alternative way to get to that action is to press Ctrl-Shift-A to open the action search menu and enter any part of the name such as "flip".
When I write my code in NetBeans, there are times when I want to add/remove if statements and loops. However, every time I want to add/remove a statement but keep the content, I have to fix all the indenting for the contained code. Likewise, every time I try to paste code into a statement, the indenting is all messed up and I have to fix it.
Is there any way to highlight the code and fix indentation?
I'm aware that Eclipse has an option to fix all formatting upon saving. I'm not looking for something that changes formatting upon saving, rather only something I can click on the moment I want the formatting fixed. I put an example of what I'm talking about below.
if (condition == true){
//pasted code
//pasted code
//pasted code
}
or
//other code
//removed if statement
//original code that is spaced too far right
//original code that is spaced too far right
//removed }
//other code
Try to paste using Ctrl + Shift + V.
If it worked, look at the netbeans options to configure the shortcut you want.
To change shortcuts go to : Tools > Options > Keymap
Here is a table of defaults shortcuts in netbeans : https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf
It might be useful, you can notice the "Ctrl-Shift-V Paste formatted" shortcut.
String cmd = "start calc.exe";
Process process = Runtime.getRuntime().exec(codeString);
I can call calculator out, but I wish to specify a accurate position like (200,300).
how can I rewrite my cmd String?
I know that java.awt.window can set a window or frame to the specific position.
Is there any method I can use to fill frame or window with my process?
There is no clean pure java solution because JDK does not provide API that can control non-java windows. So, if you want to can use JNI/JNA.
But I can suggest you a patch that will typically work.
Windows OS allows moving windows using keyboard. Try the following manually:
Win+R
type calc and press enter
press alt+space
press M
press enter
now use arrows to move the window. Press ESC to exit this mode.
All these actions can be implemented using java.awt.Robot.
So, you can run calculator and then immediately move its window where you want.
Well, this is not clear solution, but very simple one.
Expected Problems:
Alt+space is mapped to other, custom application
Other window that started together with calc overlaps it.
User will see that window is created somewhere and then quickly moved.
So, everything depends on how important all this for you. This solution is good as an exercise or demo but bad for real commercial application.
I've started working with IntelliJ and I really like it, but there are a few features which I miss compared with Eclipse. One of which is selecting blocks between {}, (), or [] or jumping between the opening/closing of a block. For example, in eclipse if you double click just after an opening parentheses it will select everything up to the matching closing parentheses as in:
method(item1, method2(itemA), item3,
item4, item5);
Where if you double clicked after the opening parentheses method(|, then it would select everything up to the closing parentheses, right after item5. I have discovered that IntelliJ will select method bodies when you double click, but not regions inside of parentheses and not for class bodies.
Also, in eclipse, you can jump between the end and beginning of a block by pressing Ctrl+Shift+P just after the opening/closing of the block. In IntelliJ (using eclipse key mapping), Ctrl+Shift+P simply selects everything up to the method's closing curly brace '}'. I've discovered that Ctrl+Shift+} works the way that I expect but only for curly braces {} and it also selects everything between the block be it a method or class rather than just moving the cursor.
I can tell that IntelliJ is fairly sophisticated and customizable, but I can't figure out how to duplicate this feature from Eclipse. Any assistance would be appreciated in getting this functionality to work.
Thanks in advance!
Craig
One of which is selecting blocks between {}, (), or [] or jumping between the opening/closing of a block.
Let's assume you have cursor on itemA.
Ctrl+W -> selected:
itemA
Ctrl+W -> selected:
method2(itemA)
Ctrl+W -> selected:
item1, method2(itemA), item3,
item4, item5
Ctrl+W -> selected:
method(item1, method2(itemA), item3,
item4, item5)
And so on. After that it would select whole method, class etc.
Honestly this is the shortcut which I use most frequently. Unfortunately I sometimes try to use that in other applications - each web browser closes tab by pressing Ctrl+W :)
Another thing is:
Ctrl + {
Ctrl + }
It jumps to opening / closing bracket
In Mac, go to start of a block and do:
Command + Shift + Alt + }
or go to end of a block and do:
Command + Shift + Alt + {
In Windows do it as:
Ctrl + Shift + }
and
Ctrl + Shift + {
If you're using the Mac OS X 10.5+ keymap, selecting the enclosing scope is option(alt) + up arrow. Pressing it repeatedly expands the selection by the next enclosing scope.
If you're using the Mac OS X keymap, this action is mapped to command+W.
I've been using Ctrl+W, but this is very annoying as it first selects a word, then an enclosing statement, then another enclosing statement and so on. You have to press Ctrl+W just too much times.
The best way I've figured for any block selection is:
Press Ctrl+{ - this will take you to the beginning of the block
Press Ctrl+Shift+} - this will select the whole block from the beginning to the end.
This way you're able to select a block of any size with any amount of nested blocks with few actions.
I am using a workaround which works pretty well. Just beside the code block you will see minimize/maximize button (which is used for code folding, the minus and the plus sign you see beside the line numbers). You will find it on minus, as the code is unfolded.
Just press on the minus, the whole code block will be minimized, and in one line. Choose that line, copy it, paste it, delete it or whatever you want to do with it :)
I have two problems.
First when i type code, netbeans automatically completes the brackets. Now what i need is to move cursor out of brackets to type the semicolon. I have to do it with the right arrow key, but i have seen tutorials in which coders to it faster. Is there some other short key or a way to do it quicker i.e from the keys under my hands?
Second the Netbeans suggestion are quite slow in my machine. Is there a way to make them load faster?
Also, CTRL-; adds a semicolon at the end of the current line, without moving the cursor. The shortcut can be changed: Menu Tools -> Options -> Keymap and search for "Complete line".
There is also in the keymap an option for "Complete line and create new line", which does the same but then puts the cursor at the start of a newly created line below. By default, I had no mapping to it, but I added it as CTRL-SHIFT-;.
Type the closed backet. Netbeans realizes what's going on and does exactly what you describe.