Can IntelliJ automatically populate constructor parameters on a "new" expression?

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

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

 MyClass myObject = new MyClass(); 

will find the appropriate parameters.

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

When I use ctrl + shift + spacebar after new , Intellij shows me the constructors, but I cannot choose one for autocomplete. Am I missing an option?

+59
intellij-idea
Jan 27 '11 at 10:41
source share
5 answers

In Intellij Idea 2016.3 you can use option + return . He will ask you if you want to provide a named argument for the argument you are in and all the followers.

enter image description here

+2
Dec 20 '16 at 11:08
source share

Usually I start with Ctrl P (the " Parameter Info " action) to see which arguments are accepted (automatic guessing is a way of error pricing, in my opinion). And if in your case you want to enter a name type n drop-down menu appears with all available variables / fields (etc.), Starting with n Arrow Up / Down and Tab to select a name, or Ctrl Space to select a method (or even Ctrl Alt Space to be killed sentences ;-), and then , and v Tab for the value.

+103
Nov 27 '11 at 14:22
source share

Well, I used the eclipse keyword map where no parameter information is assigned. Here's how to change it:

enter image description here

+13
Jan 27 '15 at 15:41
source share

Well, there is a combination of Ctrl + Shift + Space, which is trying to create a set of possible arguments. And if you press Ctrl + Shift + Space a second time, Idea tries to find arguments that are suitable for several calls and conversions.

Therefore, in your example, Ctrl + Shift + Space almost certainly recreates the "name" as a sentence. And the next Ctrl + Shift + Space will output the "value" as a sentence.

+12
Jan 27 '11 at 2:47 a.m.
source share

There is no such opportunity yet. Since IDEA does not automatically fill in arguments, distinguishing between constructors in a search does not make sense. There is a request for this (http://youtrack.jetbrains.net/issue/IDEABKL-5496), although I sincerely believe that such behavior is too dangerous and error-prone.

+3
Jan 27 '11 at 12:39 on
source share



All Articles