Open
Description
What problem are you trying to solve?
The String constructor of BigDecimal
is much nicer than BigDecimal.valueOf(doubleLiteral)
because
- two chars shorter (even shorter if the double literal has trailing zeroes)
- more obvious that a new object is created
- performance gain because valueOf is converted to String constructor anyway during compilation (unlikely to be noticable).
Describe the solution you'd like
Per API BigDecimal.valueOf(double)
Translates a double into a BigDecimal, using the double's canonical string representation provided by the Double.toString(double) method.
In addition to transforming new Bigdecimal(existingDouble)
to valueOf
, BigDecimalDoubleConstructorRecipe
should convert BigDecimal.valueOf(doubleLiteral)
to new BigDecimal(doubleString)
where doubleString = 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Recipes Wanted