Use @Deprecation `ReplaceWith` for multiple substitutions

I need to split a function that has an argument and 3 lambas in 3 different extension functions like this:

@Deprecated(
    "Change it!",
    ReplaceWith("subject.f1(l1)\nsubject.f2(l2)\nsubject.f3(l3)")
)
fun deprecatedFunction(subject: Int, l1: (Int) -> Unit, l2: (Int) -> Unit, l3: (Int) -> Unit) {}

fun Int.f1(l: (Int) -> Unit) {}
fun Int.f2(l: (Int) -> Unit) {}
fun Int.f3(l: (Int) -> Unit) {}

So that when it is written:

deprecatedFunction(10, { a -> }, { b -> }, { c -> })

it is recommended to switch to:

10.f1 ({ a -> })
10.f2 ({ b -> })
10.f3 ({ c -> })

Unfortunately the IDE does not recognize "subject.f1(l1)\nsubject.f2(l2)\nsubject.f3(l3)" as a valid refactor and the substitution is not recommended at all.
Tried "subject.f1(l1);subject.f2(l2);subject.f3(l3)" as well, no luck.

Is there a way to do it?

This looks like just missing IDE functionality, in principle no language changes are required. Please submit a feature request at http://kotl.in/issue. Thanks!

Done :slight_smile:
https://youtrack.jetbrains.com/issue/KT-32649?project=kt

1 Like

In the meantime it can be helpful to create a simple (temporary) helper function that is the direct replacement for the code. You can then use inlining to replace the code. Unfortunately that doesn’t really work for libraries.

Could you elaborate?