From cf38b37c8c46bb41c9a66a73ca06dd1e4c51efff Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 8 Dec 2022 09:00:50 +0100 Subject: [PATCH] Have `ReverseOrder` rule flag `Collections.reverseOrder(String::compareTo)` --- .../picnic/errorprone/refasterrules/ComparatorRules.java | 1 + .../errorprone/refasterrules/ComparatorRulesTestInput.java | 1 + .../errorprone/refasterrules/ComparatorRulesTestOutput.java | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java index c15b466aa4..e6de26976d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java @@ -58,6 +58,7 @@ static final class ReverseOrder> { Comparator before() { return Refaster.anyOf( Collections.reverseOrder(), + Collections.reverseOrder(T::compareTo), Collections.reverseOrder(naturalOrder()), Comparator.naturalOrder().reversed()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java index 8fde90183a..e8329f08a3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java @@ -38,6 +38,7 @@ ImmutableSet> testNaturalOrder() { ImmutableSet> testReverseOrder() { return ImmutableSet.of( Collections.reverseOrder(), + Collections.reverseOrder(String::compareTo), Collections.reverseOrder(naturalOrder()), Comparator.naturalOrder().reversed()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java index 9c27527ddf..72a83b341d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java @@ -33,7 +33,10 @@ ImmutableSet> testNaturalOrder() { ImmutableSet> testReverseOrder() { return ImmutableSet.of( - Comparator.reverseOrder(), Comparator.reverseOrder(), Comparator.reverseOrder()); + Comparator.reverseOrder(), + Comparator.reverseOrder(), + Comparator.reverseOrder(), + Comparator.reverseOrder()); } ImmutableSet> testCustomComparator() {