diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java index 80f5bcc2f0d..ce1ae28f956 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java @@ -44,13 +44,11 @@ boolean after(T a, T b) { } } - /** - * Prefer reference-based equality for enums over {@link Predicate#isEqual(Object)} comparison. - */ - static final class PredicateIsEqualEnums> { + /** Prefer reference-based equality for enums over more contrived equality checks. */ + static final class EnumsReferenceEqualityLambda> { @BeforeTemplate Predicate before(T a) { - return isEqual(a); + return Refaster.anyOf(isEqual(a), a::equals); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java index af0ffcf3058..fe500959961 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java @@ -34,8 +34,11 @@ boolean testEqualsPredicate() { return Stream.of("foo").anyMatch(s -> "bar".equals(s)); } - boolean testPredicateIsEqualEnums() { - return Stream.of(RoundingMode.UP).anyMatch(isEqual(RoundingMode.DOWN)); + ImmutableSet testEnumsReferenceEqualityLambda() { + + return ImmutableSet.of( + Stream.of(RoundingMode.UP).anyMatch(isEqual(RoundingMode.DOWN)), + Stream.of(RoundingMode.UP).anyMatch(RoundingMode.DOWN::equals)); } boolean testDoubleNegation() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java index c56e21a4f0a..9884f8efb74 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java @@ -34,8 +34,11 @@ boolean testEqualsPredicate() { return Stream.of("foo").anyMatch("bar"::equals); } - boolean testPredicateIsEqualEnums() { - return Stream.of(RoundingMode.UP).anyMatch(v -> v == RoundingMode.DOWN); + ImmutableSet testEnumsReferenceEqualityLambda() { + + return ImmutableSet.of( + Stream.of(RoundingMode.UP).anyMatch(v -> v == RoundingMode.DOWN), + Stream.of(RoundingMode.UP).anyMatch(v -> v == RoundingMode.DOWN)); } boolean testDoubleNegation() {