Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate method or constructor parameter names against provided arguments in IntelliJ IDEA

Suppose I have the following class and respective instance:

case class Account(name: String, age: Int, amount: BigDecimal, currency: String)

Account("name", 93, 100, "USD")

Question: Is there a shortcut in IntelliJ IDEA that will generate parameter names against passed arguments, i.e.

Account(name = "name", age = 93, amount = 100, currency = "USD")

This is very useful when you have a constructor or a method taking a long list of parameters and helps to read / refactor some old code.

Please note that I am aware of Ctrl+P showing parameter info and I am also aware of Inlay Hints setting in IntelliJ showing the hints in the editor.

like image 525
Rustam Aliyev Avatar asked Sep 01 '25 10:09

Rustam Aliyev


2 Answers

Just alt+Enter and then choose "use named argument ...": enter image description here

like image 94
Scalway Avatar answered Sep 04 '25 17:09

Scalway


There exists intention action Use named arguments

enter image description here

which transforms

User("Worf")

to

User(name = "Worf")
like image 41
Mario Galic Avatar answered Sep 04 '25 17:09

Mario Galic