dylan
10/17/2024, 2:46 PM@Deprecated
annotation with ReplaceWith
?
I want to replace a function which has some default values and when I run my current replace it always adds the default values
so if I have this
@Deprecated(
message = "Use NewFunction instead",
replaceWith = ReplaceWith(
expression = "NewFunction(value1 = value1, value2 = value2, image = image?.let{ ImageVector.vectorResource(id = it) })",
),
)
DeprecatedFunction(
value1 : String,
value2: Boolean = true,
@DrawableRes image: Int? = null
) { ... }
NewFunction(
value1 : String,
value2: Boolean = true,
image: ImageVector? = null
) { ... }
and I run this on the following code
DeprecatedFunction(
value1 = "some value",
)
I end up with
NewFunction(
value1 = "some value",
value2 = true,
image = null?.let<Int, ImageVector?> { ImageVector.vectorResource(id = it) },
)
while I expect the replace to generate this
NewFunction(
value1 = "some value",
)
Eugen Martynov
10/18/2024, 6:21 AMdylan
10/18/2024, 6:58 AMOsip Fatkullin
10/24/2024, 10:45 AMimage
parameter which has different type and has some transformations, so replacer is not smart enough to understand that the default value is actually the same. You could create a copy of your deprecated function, but without this parameter and then apply the suggestion for it and for your original function separately:
@Deprecated(
"Use NewFunction instead",
ReplaceWith("NewFunction(value1 = value1, value2 = value2) })"),
)
DeprecatedFunction(
value1 : String,
value2: Boolean = true,
) { ... }