, 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?
a
Adam S
03/09/2023, 9:08 AM
Can you share some code to demonstrate what you've tried, what the result is, and what you'd expect?
Adam S
03/09/2023, 9:11 AM
my guess is that there's already an import with the same name, so IntelliJ won't replace it
Copy code
import 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
Copy code
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")
m
Michal Klimczak
03/09/2023, 10:06 AM
Sure thing. Take a look at this:
Copy code
package 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
Copy code
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
Michal Klimczak
03/09/2023, 10:06 AM
I would expect it to use both imports, why ide tries to be smarter and choose the ones that it thinks are used
a
Adam S
03/09/2023, 10:16 AM
yeah, I wouldn't expect that behaviour either, good find. I say you should make an issue on YouTrack.