Michal Klimczak
03/09/2023, 7:35 AM@Deprecated
with ReplaceWith
, but it doesn't use all the imports. One of the imports is related to the expression used in ReplaceWith, the other is added for a top level extension function which would retrofit the old deprecated usage. But the other one is not automatically included by IDE, when replacing.
Is that by design or am I encountering some bug?Adam S
03/09/2023, 9:08 AMimport a.b.c.OldFoo
import a.b.c.NewFoo
@Deprecated("", ReplaceWith("x.y.z.NewFoo(...)")
val x = OldFoo("blah")
val someOtherVar = NewFoo("asd")
results in
import a.b.c.OldFoo
import a.b.c.NewFoo
// import x.y.z.NewFoo // can't add this import
val x = x.y.z.NewFoo("blah") // so must use the FQN
val someOtherVar = NewFoo("asd")
Michal Klimczak
03/09/2023, 10:06 AMpackage com.example.utils
@Deprecated(
"oh well",
ReplaceWith("FooNew", "com.example.utils.FooNew", "com.example.utils.bar"),
)
class FooOld {
fun bar() = Unit
}
class FooNew
fun FooNew.bar() = Unit
And then used like this
package com.example.something
import com.example.utils.FooOld
fun something() = FooOld().bar()
It will import com.example.utils.FooNew
, but will not import com.example.utils.bar
Adam S
03/09/2023, 10:16 AMMichal Klimczak
03/09/2023, 10:24 AM