From e80ef1d3d34a8016cac2ab7d84155adcf6ff242d Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 23 Oct 2024 10:51:33 +0200 Subject: [PATCH] Suggestions --- .../refasterrules/ImmutableEnumSetRules.java | 51 ++++++++++--------- .../ImmutableEnumSetRulesTestInput.java | 24 ++++----- .../ImmutableEnumSetRulesTestOutput.java | 24 ++++----- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRules.java index b513725c2b0..8d38be3b929 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRules.java @@ -11,16 +11,19 @@ import java.util.EnumSet; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; -/** Refaster rules related to expressions dealing with immutable {@link Enum} collections. */ +/** + * Refaster rules related to expressions dealing with {@code + * com.google.common.collect.ImmutableEnumSet}s. + */ @OnlineDocumentation final class ImmutableEnumSetRules { private ImmutableEnumSetRules() {} /** - * Prefer {@link Sets#immutableEnumSet(Iterable)} for enum collections to take advantage of + * Prefer {@link Sets#immutableEnumSet(Iterable)} for enum collections to take advantage of the * internally used {@link EnumSet}. */ - static final class ImmutableEnumSetIterable> { + static final class SetsImmutableEnumSetIterable> { @BeforeTemplate ImmutableSet before(Collection elements) { return ImmutableSet.copyOf(elements); @@ -33,10 +36,10 @@ ImmutableSet after(Collection elements) { } /** - * Prefer {@link Sets#immutableEnumSet(Iterable)} for enum collections to take advantage of + * Prefer {@link Sets#immutableEnumSet(Iterable)} for enum collections to take advantage of the * internally used {@link EnumSet}. */ - static final class ImmutableEnumSetIterable1> { + static final class SetsImmutableEnumSetIterableArray> { @BeforeTemplate ImmutableSet before(T[] elements) { return ImmutableSet.copyOf(elements); @@ -50,11 +53,11 @@ ImmutableSet after(T[] elements) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetOneElement> { + static final class SetsImmutableEnumSet1> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1) { return Refaster.anyOf(ImmutableSet.of(e1), ImmutableSet.copyOf(EnumSet.of(e1))); } @@ -68,11 +71,11 @@ ImmutableSet after(T e1) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetTwoElements> { + static final class SetsImmutableEnumSet2> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1, T e2) { return Refaster.anyOf(ImmutableSet.of(e1, e2), ImmutableSet.copyOf(EnumSet.of(e1, e2))); } @@ -86,11 +89,11 @@ ImmutableSet after(T e1, T e2) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetThreeElements> { + static final class SetsImmutableEnumSet3> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1, T e2, T e3) { return Refaster.anyOf( ImmutableSet.of(e1, e2, e3), ImmutableSet.copyOf(EnumSet.of(e1, e2, e3))); @@ -105,11 +108,11 @@ ImmutableSet after(T e1, T e2, T e3) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetFourElements> { + static final class SetsImmutableEnumSet4> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1, T e2, T e3, T e4) { return Refaster.anyOf( ImmutableSet.of(e1, e2, e3, e4), ImmutableSet.copyOf(EnumSet.of(e1, e2, e3, e4))); @@ -124,11 +127,11 @@ ImmutableSet after(T e1, T e2, T e3, T e4) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetFiveElements> { + static final class SetsImmutableEnumSet5> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1, T e2, T e3, T e4, T e5) { return Refaster.anyOf( ImmutableSet.of(e1, e2, e3, e4, e5), ImmutableSet.copyOf(EnumSet.of(e1, e2, e3, e4, e5))); @@ -143,9 +146,9 @@ ImmutableSet after(T e1, T e2, T e3, T e4, T e5) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ - static final class ImmutableEnumSetSixElements> { + static final class SetsImmutableEnumSet6> { @BeforeTemplate ImmutableSet before(T e1, T e2, T e3, T e4, T e5, T e6) { return ImmutableSet.of(e1, e2, e3, e4, e5, e6); @@ -160,11 +163,11 @@ ImmutableSet after(T e1, T e2, T e3, T e4, T e5, T e6) { /** * Prefer {@link Sets#immutableEnumSet(Enum, Enum[])} for enum collections to take advantage of - * internally used {@link EnumSet}. + * the internally used {@link EnumSet}. */ static final class ImmutableEnumSetVarArgs> { @BeforeTemplate - @SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */) + @SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */) ImmutableSet before(T e1, @Repeated T elements) { return ImmutableSet.copyOf(EnumSet.of(e1, Refaster.asVarargs(elements))); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestInput.java index c693d024ae8..c3d1c5ac780 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestInput.java @@ -11,36 +11,32 @@ public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(EnumSet.class); } - ImmutableSet> testImmutableEnumSetIterable() { - return ImmutableSet.of( - ImmutableSet.copyOf(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)), - ImmutableSet.copyOf(EnumSet.allOf(RoundingMode.class))); + ImmutableSet testSetsImmutableEnumSetIterable() { + return ImmutableSet.copyOf(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)); } - ImmutableSet> testImmutableEnumSetIterable1() { - return ImmutableSet.of( - ImmutableSet.copyOf(RoundingMode.values()), - ImmutableSet.copyOf(RoundingMode.class.getEnumConstants())); + ImmutableSet testSetsImmutableEnumSetIterableArray() { + return ImmutableSet.copyOf(RoundingMode.values()); } - ImmutableSet> testImmutableEnumSetOneElement() { + ImmutableSet> testSetsImmutableEnumSet1() { return ImmutableSet.of( ImmutableSet.of(RoundingMode.UP), ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP))); } - ImmutableSet> testImmutableEnumSetTwoElements() { + ImmutableSet> testSetsImmutableEnumSet2() { return ImmutableSet.of( ImmutableSet.of(RoundingMode.UP, RoundingMode.DOWN), ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP, RoundingMode.DOWN))); } - ImmutableSet> testImmutableEnumSetThreeElements() { + ImmutableSet> testSetsImmutableEnumSet3() { return ImmutableSet.of( ImmutableSet.of(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING), ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING))); } - ImmutableSet> testImmutableEnumSetFourElements() { + ImmutableSet> testSetsImmutableEnumSet4() { return ImmutableSet.of( ImmutableSet.of( RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR), @@ -49,7 +45,7 @@ ImmutableSet> testImmutableEnumSetFourElements() { RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR))); } - ImmutableSet> testImmutableEnumSetFiveElements() { + ImmutableSet> testSetsImmutableEnumSet5() { return ImmutableSet.of( ImmutableSet.of( RoundingMode.UP, @@ -66,7 +62,7 @@ ImmutableSet> testImmutableEnumSetFiveElements() { RoundingMode.UNNECESSARY))); } - ImmutableSet testImmutableEnumSetSixElements() { + ImmutableSet testSetsImmutableEnumSet6() { return ImmutableSet.of( RoundingMode.UP, RoundingMode.DOWN, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestOutput.java index 11b22b26c19..45544b7fa6a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableEnumSetRulesTestOutput.java @@ -13,36 +13,32 @@ public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(EnumSet.class); } - ImmutableSet> testImmutableEnumSetIterable() { - return ImmutableSet.of( - Sets.immutableEnumSet(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)), - Sets.immutableEnumSet(EnumSet.allOf(RoundingMode.class))); + ImmutableSet testSetsImmutableEnumSetIterable() { + return Sets.immutableEnumSet(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)); } - ImmutableSet> testImmutableEnumSetIterable1() { - return ImmutableSet.of( - Sets.immutableEnumSet(Arrays.asList(RoundingMode.values())), - Sets.immutableEnumSet(Arrays.asList(RoundingMode.class.getEnumConstants()))); + ImmutableSet testSetsImmutableEnumSetIterableArray() { + return Sets.immutableEnumSet(Arrays.asList(RoundingMode.values())); } - ImmutableSet> testImmutableEnumSetOneElement() { + ImmutableSet> testSetsImmutableEnumSet1() { return ImmutableSet.of( Sets.immutableEnumSet(RoundingMode.UP), Sets.immutableEnumSet(RoundingMode.UP)); } - ImmutableSet> testImmutableEnumSetTwoElements() { + ImmutableSet> testSetsImmutableEnumSet2() { return ImmutableSet.of( Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN), Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN)); } - ImmutableSet> testImmutableEnumSetThreeElements() { + ImmutableSet> testSetsImmutableEnumSet3() { return ImmutableSet.of( Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING), Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING)); } - ImmutableSet> testImmutableEnumSetFourElements() { + ImmutableSet> testSetsImmutableEnumSet4() { return ImmutableSet.of( Sets.immutableEnumSet( RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR), @@ -50,7 +46,7 @@ ImmutableSet> testImmutableEnumSetFourElements() { RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR)); } - ImmutableSet> testImmutableEnumSetFiveElements() { + ImmutableSet> testSetsImmutableEnumSet5() { return ImmutableSet.of( Sets.immutableEnumSet( RoundingMode.UP, @@ -66,7 +62,7 @@ ImmutableSet> testImmutableEnumSetFiveElements() { RoundingMode.UNNECESSARY)); } - ImmutableSet testImmutableEnumSetSixElements() { + ImmutableSet testSetsImmutableEnumSet6() { return Sets.immutableEnumSet( RoundingMode.UP, RoundingMode.DOWN,