Can IntelliJ auto-complete constructor parameters on "new" expression?

Intellij Idea

Intellij Idea Problem Overview


If my class has a non-empty constructor, is it possible to auto-complete parameters in the new expression?

With Eclipse, if you press ctrl+space when the cursor is between the parenthesis:

MyClass myObject = new MyClass();

it will find the appropriate parameters.

-->  MyClass myObject = new MyClass(name, value);

When I use ctrl+shift+spacebar after the new, Intellij shows me the constructors, but I can't choose one for auto-completion. Am I missing an option?

Intellij Idea Solutions


Solution 1 - Intellij Idea

I usually start with CtrlP (Parameter Info action) to see what arguments are accepted (auto guess complete is way to error prone in my opinion). And if as in your case you want to fill in name type n a dropdown menu appears with all available variables/fields (etc) starting with n Arrow Up/Down and Tab to select name, or CtrlSpace to select a method (or even CtrlAltSpace to be killed by suggestions;-), followed by , and v Tab for value.

Solution 2 - Intellij Idea

Well I used the eclipse key map where Parameter Info is unassigned. Here is how to change that:

enter image description here

Solution 3 - Intellij Idea

Well there's the Ctrl+Shift+Space combination, which tries to come up with a set of possible arguments. And if you press the Ctrl+Shift+Space a second time, Idea tries find arguments which fit across multiple calls & conversions.

So in your example Ctrl+Shift+Space would almost certainly bring up the 'name' as suggestion. And the next Ctrl+Shift+Space would bring up 'value' as suggestion.

Solution 4 - Intellij Idea

In Intellij Idea 2016.3 you can use option + return. It will ask you if you want to introduce the named argument for the argument you are on and all the followers.

enter image description here

Solution 5 - Intellij Idea

There's no such possibility yet. As IDEA doesn't fill the arguments automatically, distinguishing the constructors in the lookup makes no sense. There's a request for that (http://youtrack.jetbrains.net/issue/IDEABKL-5496) although I sincerely believe such a behavior is too dangerous and error-prone.

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
QuestionLoicView Question on Stackoverflow
Solution 1 - Intellij IdeaosundbladView Answer on Stackoverflow
Solution 2 - Intellij IdeajoecksView Answer on Stackoverflow
Solution 3 - Intellij IdeaGamlorView Answer on Stackoverflow
Solution 4 - Intellij IdeaFilippo De LucaView Answer on Stackoverflow
Solution 5 - Intellij IdeaPeter GromovView Answer on Stackoverflow