Rustam Aliyev
Rustam Aliyev

Reputation: 629

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.

Upvotes: 4

Views: 474

Answers (2)

Scalway
Scalway

Reputation: 1663

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

Upvotes: 5

Mario Galic
Mario Galic

Reputation: 48410

There exists intention action Use named arguments

enter image description here

which transforms

User("Worf")

to

User(name = "Worf")

Upvotes: 3

Related Questions