I'm trying to use `@Deprecated` with `ReplaceWith`...
# stdlib
m
I'm trying to use
@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?
a
Can you share some code to demonstrate what you've tried, what the result is, and what you'd expect?
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
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
I would expect it to use both imports, why ide tries to be smarter and choose the ones that it thinks are used
a
yeah, I wouldn't expect that behaviour either, good find. I say you should make an issue on YouTrack.
👍 1