When I instantiate classes (or call methods) with a large number of parameters I'm always using named arguments. But it's tiring to type each argument name every time:
data class User(val id: String,
val name: String,
val age: Int)
val user = User(id = "1", name = "John", age = 99)
Can IDEA pre-fill parameters like this?
val user = User(
id = ,
name = ,
age =
)
See the following requests:
There is an experimental feature you can enable by adding
java.completion.argument.live.template=true
into Help | Edit Custom Properties.Though this is not actually generating the whole call template with all the parameter names, it might be helpful anyway.
Kotlin IDEA plugin 1.1.1 suggests the parameter names in auto completion as you start typing them. For the
User
constructor from the example, start typing:There should be a suggestion
id =
:It is inserted if you press Enter or Tab. Then you can continue with the other arguments:
Here,
name =
should appear in suggestions, and so on.Also, the parameters info popup should help you with it:
you can use Live template:
setting > Editor > Live Templates
choice code group and add by Green Plus 1.live Template
now you need fill items
Abbreviation is name for call template code.
in template type your code like it:
$arg1$ means where you can type new and jump by Tab
in code when you type Abbreviation name of your code, can selected and Code Generate there
GoodLuck