If I've got a `data class X(val foo: Int, val bar:...
# getting-started
k
If I've got a
data class X(val foo: Int, val bar: Int)
and use it all over the place in a large codebase, is there a refactoring (either in IDEA Ultimate Edition or in a third-party plugin or CLI utility) that will swap the two parameters to make it
data class X(val bar: Int, val foo: Int)
?
j
Ctrl+F6 (change signature) - at least on windows. Probably macOS has CMD+F6 but not sure, I never how to map them
j
You can right click the function name Refactor -> Change Signature to reach it
k
Thanks, I'll try that, but will it also change
val (a, b) = getSomeX()
to
val (b, a) = getSomeX()
?
j
If that's a
Pair
then I don't think it'll work because its not your own code/signature
k
No, that's destructuring the data class X.
j
It seems you can right click your constructor and do the Change signature there so I guess that would work?
If I understand what you want to do then it works for me. However I needed to right click the class name not the constructor part.
Copy code
data class A(val a: String, val b: String)
fun a() {
    val (a, b) = A("a", "b")
}
turns into
Copy code
data class A(val b: String, val a: String)

fun a() {
    val (b, a) = A("b", "a")
}
by just running Change signature and changing the order
k
That works perfectly, thanks!