From 346407b034e62e567b764012e9551f55ba4c7a23 Mon Sep 17 00:00:00 2001 From: Vincent Koeman Date: Tue, 6 Dec 2022 22:12:34 +0100 Subject: [PATCH] Extend the refaster rule for `new BigDecimal(...)` to doubles --- .../picnic/errorprone/refasterrules/BigDecimalRules.java | 8 ++++---- .../refasterrules/BigDecimalRulesTestInput.java | 2 +- .../refasterrules/BigDecimalRulesTestOutput.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java index b23406170bb..196df3abc39 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java @@ -50,17 +50,17 @@ BigDecimal after() { } } - /** Prefer {@link BigDecimal#valueOf(long)} over the associated constructor. */ - // XXX: Ideally we'd also rewrite `BigDecimal.valueOf("")`, but it doesn't + /** Prefer {@link BigDecimal#valueOf(double)} over the associated constructor. */ + // XXX: Ideally we'd also rewrite `new BigDecimal("")`, 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); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java index 37db5459ce1..4d60c6339eb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java @@ -18,6 +18,6 @@ ImmutableSet testBigDecimalTen() { } ImmutableSet testBigDecimalFactoryMethod() { - return ImmutableSet.of(new BigDecimal(0), new BigDecimal(0L)); + return ImmutableSet.of(new BigDecimal(2), new BigDecimal(2L), new BigDecimal(2.0)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java index 8be65ad5201..4579ed4bead 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java @@ -18,6 +18,6 @@ ImmutableSet testBigDecimalTen() { } ImmutableSet testBigDecimalFactoryMethod() { - return ImmutableSet.of(BigDecimal.valueOf(0), BigDecimal.valueOf(0L)); + return ImmutableSet.of(BigDecimal.valueOf(2), BigDecimal.valueOf(2L), BigDecimal.valueOf(2.0)); } }