I’m trying to add a ReplaceWith on a function that has the last argument outside of parentheses because it’s a lambda.
So I have this method
@Deprecated(
message = "use extension function from kotlinx",
replaceWith = ReplaceWith("observe(owner, observer)", "androidx.lifecycle.observe")
)
inline fun <T> LiveData<T>.observe(owner: LifecycleOwner, crossinline observer: (t: T?) -> Unit) {
observe(owner, Observer {
observer(it)
})
}
Problem 1
It puts the lambda back into the parentheses, making me have to do another alt + enter. Also, it adds the type, which isn’t needed because it can be deduced.
Before:
import com.package.extensions.observe
foo.observe(this) {
doSomething(it)
}
After alt + enter:
import androidx.lifecycle.observe
import com.package.extensions.observe
foo.observe<String?>(this, {
doSomething(it)
})
Problem 2: it now has both the old and new import, so the compiler doesn’t know which one to choose. This could be solved if the old import would be removed on alt + enter.
How can I solve these problems?