How to add semicolon after method call when inside parameter list in IntelliJ IDEA?

JavaIntellij Idea

Java Problem Overview


I'm finally making the voyage back to IntelliJ via Eclipse. Currently my Eclipse is set up so that if I currently have a statement such as this (where ^ denotes where my cursor currently sits):

foo.bar("hello"^)

and I hit the semi-colon (;) key, it will automatically put the semi-colon at the end of the statement:

foo.bar("hello");

Currently IntelliJ does this:

foo.bar("hello";)

Meaning I will have to explicitly type the closing bracket before typing the semi-colon.

Not a huge problem obviously but I have found myself putting the semi-colon in the wrong place a few times today as I make the transition back to IntelliJ and thought that it may be more efficient (for both my fingers and brain) not to have to type the closing bracket.

Java Solutions


Solution 1 - Java

For Windows or Linux users, Ctrl+Shift+Enter.

For macOS/OS X users, ⌘ Command+⇧ Shift+Enter.

That finishes the statement you're currently writing. Try it in a few different situations, like in if statements, for loops etc, and you'll see that it'll complete the line and open some curly braces for you if necessary.

Solution 2 - Java

You can add a keymap of your own. I added Ctrl+; to my Keymaps for the "Complete Current Statement" action. This saved me an extra key stroke and made it a little bit more intuitive.

  1. Go to Settings > Keymap
  2. In the search box, enter "Complete Current Statement".
  3. Right-click on the entry and select "Add Keyboard shortcut"
  4. With the First Stroke field hightlighted, enter your key combination. E.g., Ctrl+;, which will display as Ctrl+Semicolon
  5. Click OK, and OK to save and exit.

You can opt to remove or keep the existing mapping. Should look something like this when you're done:

enter image description here

Solution 3 - Java

if you want always have it just do this

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondigiarnieView Question on Stackoverflow
Solution 1 - JavaNoel MView Answer on Stackoverflow
Solution 2 - JavaLimaNightHawkView Answer on Stackoverflow
Solution 3 - JavaHamidreza SadeghView Answer on Stackoverflow