how would you write a `ReplaceWith` for this: ``` ...
# announcements
d
how would you write a
ReplaceWith
for this:
Copy code
@Deprecated("Use BigDecimal for prices")
fun Double.formattedWithCurrency(locale: Locale = Constants.LOCALE): String {
    return toBigDecimal().formattedWithCurrency(locale)
}
or for this constructor?
Copy code
@Deprecated("Use the constructor with BigDecimal(s)")
constructor(
    originalPrice: Double?,
    price: Double,
    locale: String,
    percentage: Double?
): this(
    originalPrice = originalPrice?.toBigDecimal(),
    price = price.toBigDecimal(),
    locale = locale,
    percentage = percentage?.toBigDecimal()
)
n
safecalls in replacewith seem to be hairy.. so i would do
ReplaceWith("this.toBigDecimal().formattedWithCurrency(locale)")
and hope idea accepts it.. and follow nullablity suggestions afterwards
d
thanks @Nikky I didn't expect it but it does indeed work like that.. any tip for the constructor?
n
i think
ClassName(originalPrice = originalPrice?.toBigDecimal(), price = price?.toBigDecimal(), locale = locale, percentage = percentage?.toBigDecimal())
would work i am not sure on the named arguments and the safecalls still..
d
let me try
it kind-of work but add the
toBigDecimal()
even if you have
null
so it becomes
null?.toBigDecimal()
which works but it's kinda stupid eheh
still it would have been faster to replace in all project with that ReplaceWith and than just replace everywhere
null?.toBigDecimal()
with just
null
using a shell command, thanks I didn't know ReplaceWith was that smart