Skip to content

Commit

Permalink
Extend the refaster rule for new BigDecimal(...) to doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
Venorcis authored and Stephan202 committed Dec 7, 2022
1 parent cf995ec commit 25ca321
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ BigDecimal after() {
}
}

/** Prefer {@link BigDecimal#valueOf(long)} over the associated constructor. */
// XXX: Ideally we'd also rewrite `BigDecimal.valueOf("<some-integer-value>")`, but it doesn't
/** Prefer {@link BigDecimal#valueOf(double)} over the associated constructor. */
// XXX: Ideally we'd also rewrite `new BigDecimal("<some-integer-value>")`, but it doesn't
// appear that's currently possible with Error Prone.
static final class BigDecimalFactoryMethod {
@BeforeTemplate
BigDecimal before(long value) {
BigDecimal before(double value) {
return new BigDecimal(value);
}

@AfterTemplate
BigDecimal after(long value) {
BigDecimal after(double value) {
return BigDecimal.valueOf(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ ImmutableSet<BigDecimal> testBigDecimalTen() {
}

ImmutableSet<BigDecimal> testBigDecimalFactoryMethod() {
return ImmutableSet.of(new BigDecimal(0), new BigDecimal(0L));
return ImmutableSet.of(new BigDecimal(2), new BigDecimal(2L), new BigDecimal(2.0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ ImmutableSet<BigDecimal> testBigDecimalTen() {
}

ImmutableSet<BigDecimal> testBigDecimalFactoryMethod() {
return ImmutableSet.of(BigDecimal.valueOf(0), BigDecimal.valueOf(0L));
return ImmutableSet.of(BigDecimal.valueOf(2), BigDecimal.valueOf(2L), BigDecimal.valueOf(2.0));
}
}

0 comments on commit 25ca321

Please sign in to comment.