I am trying to refactor existing legacy code and I noticed that I have many places with below pattern:
if (condition) {
// lot of code
} else {
throw new SomeException();
}
I was wondering if there is a fast way of flipping if-else construct to easily refactor current form to something like this:
if(!condition) throw new SomeException();
// lot of code
I want to remove unnecessary nesting and making checks at the begining of the function.
Ctrl + H = "Type Hierarchy" view = shows a tree of parent and child classes of this class. Ctrl + Shift + A = "It does a search as you type through all the commands in intellij. Not only that but when you find the command you want it also displays the corresponding shortcut key next to it!"
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.
In past IntelliJ versions, ctrl+shift+f would search the entire project (no matter whether you had at some point used "find in path").
Put the caret on 'if', press Alt+Enter, select "Invert 'if' condition" from the menu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With