Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rearrange method parameters in IntelliJ with keyboard shortcut

In IntelliJ I can easily rearrange the order of statements (or whole methods for that part) by pressing + Shift + (or + Shift + ).

I was wondering whether there's a shortcut to change the order of method parameters as easily, so that

public void sth(String a, String b) {...} 

will become

public void sth(String b, String a) {...} 

with the stroke of a keyboard shortcut (assuming my cursor is positioned on one of the parameters).

It would be enough for me, if IntelliJ would just reorder the parameters. That is, this need not trigger a whole Refactor > Change method signature thing.

like image 848
Stefan Haberl Avatar asked Feb 12 '16 09:02

Stefan Haberl


People also ask

What is Ctrl Shift O in IntelliJ?

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.

What does Ctrl Shift F do in IntelliJ?

In past IntelliJ versions, ctrl+shift+f would search the entire project (no matter whether you had at some point used "find in path").

How do I sort methods in IntelliJ?

You need to go to Settings (Ctrl + Alt +S) -> Editor -> Code Style -> Java -> Arrangement (tab) and scroll down until you find the icons with methods . There you can manipulate the options to sort them by visibility, or alphabetically, or to keep related ones grouped together.

What is Ctrl h in IntelliJ?

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!"


1 Answers

Since IDEA 16 EAP, there's an action for that. It's in the menu:

Code | Move Element Left/Right

Keyboard shortcuts are Alt+Ctrl+Shift+Left/Right (Alt+Cmd+Shift+Left/Right for OSX).

See http://blog.jetbrains.com/idea/2016/01/intellij-idea-16-eap-improves-editor-and-vcs-integration/ for more details.

like image 141
Peter Gromov Avatar answered Oct 08 '22 21:10

Peter Gromov