From 973446e5a6adaa46b75dc3b545c5537ea0249f1a Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 8 Nov 2022 16:20:45 +0100 Subject: [PATCH] Suggestion: move --- .../errorprone/refasterrules/MapRules.java | 26 +++++++++---------- .../refasterrules/MapRulesTestInput.java | 14 +++++----- .../refasterrules/MapRulesTestOutput.java | 14 +++++----- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java index c5be81f733..2d56fbbc76 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java @@ -41,6 +41,19 @@ static final class MapGetOrNull { } } + /** Prefer {@link Map#isEmpty()} over more contrived alternatives. */ + static final class MapIsEmpty { + @BeforeTemplate + boolean before(Map map) { + return Refaster.anyOf(map.keySet(), map.values(), map.entrySet()).isEmpty(); + } + + @AfterTemplate + boolean after(Map map) { + return map.isEmpty(); + } + } + /** Prefer {@link Map#size()} over more contrived alternatives. */ static final class MapSize { @BeforeTemplate @@ -105,17 +118,4 @@ Stream after(Map map) { return map.values().stream(); } } - - /** Prefer {@link Map#isEmpty()} over more contrived alternatives. */ - static final class MapIsEmpty { - @BeforeTemplate - boolean before(Map map) { - return Refaster.anyOf(map.keySet(), map.values(), map.entrySet()).isEmpty(); - } - - @AfterTemplate - boolean after(Map map) { - return map.isEmpty(); - } - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java index 77fe2418d5..a8dc6e7fa4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java @@ -22,6 +22,13 @@ String testMapGetOrNull() { return ImmutableMap.of(1, "foo").getOrDefault("bar", null); } + ImmutableSet testMapIsEmpty() { + return ImmutableSet.of( + ImmutableMap.of("foo", 1).keySet().isEmpty(), + ImmutableMap.of("bar", 2).values().isEmpty(), + ImmutableMap.of("baz", 3).entrySet().isEmpty()); + } + ImmutableSet testMapSize() { return ImmutableSet.of( ImmutableMap.of("foo", 1).keySet().size(), @@ -44,11 +51,4 @@ Stream testMapKeyStream() { Stream testMapValueStream() { return ImmutableMap.of("foo", 1).entrySet().stream().map(Map.Entry::getValue); } - - ImmutableSet testMapIsEmpty() { - return ImmutableSet.of( - ImmutableMap.of("foo", 1).keySet().isEmpty(), - ImmutableMap.of("bar", 2).values().isEmpty(), - ImmutableMap.of("baz", 3).entrySet().isEmpty()); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java index 632491b2eb..650cd4094f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java @@ -23,6 +23,13 @@ String testMapGetOrNull() { return ImmutableMap.of(1, "foo").get("bar"); } + ImmutableSet testMapIsEmpty() { + return ImmutableSet.of( + ImmutableMap.of("foo", 1).isEmpty(), + ImmutableMap.of("bar", 2).isEmpty(), + ImmutableMap.of("baz", 3).isEmpty()); + } + ImmutableSet testMapSize() { return ImmutableSet.of( ImmutableMap.of("foo", 1).size(), @@ -45,11 +52,4 @@ Stream testMapKeyStream() { Stream testMapValueStream() { return ImmutableMap.of("foo", 1).values().stream(); } - - ImmutableSet testMapIsEmpty() { - return ImmutableSet.of( - ImmutableMap.of("foo", 1).isEmpty(), - ImmutableMap.of("bar", 2).isEmpty(), - ImmutableMap.of("baz", 3).isEmpty()); - } }