Czar
12/28/2019, 2:53 PMinterface Provider {
fun <P : X> provide(name: String, clazz: KClass<out P>): P?
}
inline fun <reified P : X> Provider.provide(name: String): P? =
provide(configName, P::class)
I want to discourage use of normal provide and enable easy migration, so I put @Deprecated
annotation on it like this:
@Deprecated(
message = "Direct usage of provide(name, clazz) is discouraged",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith(
expression = "???",
imports = ["com.example.provider.provide"]
)
)
I can't get the replacement exception right.
Say I have this in code: myProvider.provide("asdf", MyData::class)
when expression is
1. provide(name)
→ the code is replaced with provide("asdf")
- receiver is lost
2. provide<clazz>(name)
→ the code is replaced with myProvider.provide<clazz>("asdf")
I understand, that substitutor is not smart enough to decode clazz
, but when I don't specify it resulting code is even more broken.
Is this a bug?
I want the replacement to be either myProvider.provide<MyData>("asdf")
or at least myProvider.provide("asdf")
Marc Knaup
12/29/2019, 1:55 AMexpression = "this.provide<P>(name)"
The replacement expression is interpreted in the context of the symbol being used …Hence
this
is Provider
and P
is available.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-replace-with/expression.htmlCzar
12/29/2019, 1:47 PM