-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigDecimalDoubleConstructorRecipe should also convert BigDecimal.valueOf(doubleLiteral) -> new BigDecimal(stringLiteral) #255
Comments
Thanks for the suggestion @timo-abele ! The current recipe is implemented as a refaster style recipe, which replaces Lines 24 to 42 in 88f3531
Do I understand correctly that you're looking to then go from I'm not entirely sure that's what folks would expect these days, especially as we're moving other number constructors over to Lines 87 to 116 in 88f3531
Reintroducing explicit constructors for BigDecimal might then be confusing; any thoughts on that? |
Hi, in my project the scale of a List.of(
new BigDecimal(1.00),
BigDecimal.valueOf(1.00),
new BigDecimal("1.00")
).forEach(bd -> System.out.printf("value: %-4s, scale: %s%n", bd, bd.scale())); that prints
Only the (argument of the) string constructor clearly indicates the BigDecimal value that is created. Right now (v1.3.1) Similarly, I believe, that a dev who writes ¹ There is also ² That's an assumption on my part of course. At the very least however it assumes that the semantics are worth changing. |
What problem are you trying to solve?
The String constructor of
BigDecimal
is much nicer thanBigDecimal.valueOf(doubleLiteral)
becauseDescribe the solution you'd like
Per API
BigDecimal.valueOf(double)
In addition to transforming
new Bigdecimal(existingDouble)
tovalueOf
,BigDecimalDoubleConstructorRecipe
should convertBigDecimal.valueOf(doubleLiteral)
tonew BigDecimal(doubleString)
wheredoubleString = Double.toString(doubleLiteral).toString()
.E.g.
BigDecimal.valueOf(1.00)
->new BigDecimal("1.0")
Have you considered any alternatives or workarounds?
Additional context
Are you interested in contributing this feature to OpenRewrite?
Iff the idea is approved.
The text was updated successfully, but these errors were encountered: