Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Oct 23, 2024
1 parent fcf5894 commit e80ef1d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Enum<T>> {
static final class SetsImmutableEnumSetIterable<T extends Enum<T>> {
@BeforeTemplate
ImmutableSet<T> before(Collection<T> elements) {
return ImmutableSet.copyOf(elements);
Expand All @@ -33,10 +36,10 @@ ImmutableSet<T> after(Collection<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSetIterableArray<T extends Enum<T>> {
@BeforeTemplate
ImmutableSet<T> before(T[] elements) {
return ImmutableSet.copyOf(elements);
Expand All @@ -50,11 +53,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet1<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> before(T e1) {
return Refaster.anyOf(ImmutableSet.of(e1), ImmutableSet.copyOf(EnumSet.of(e1)));
}
Expand All @@ -68,11 +71,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet2<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> before(T e1, T e2) {
return Refaster.anyOf(ImmutableSet.of(e1, e2), ImmutableSet.copyOf(EnumSet.of(e1, e2)));
}
Expand All @@ -86,11 +89,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet3<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> before(T e1, T e2, T e3) {
return Refaster.anyOf(
ImmutableSet.of(e1, e2, e3), ImmutableSet.copyOf(EnumSet.of(e1, e2, e3)));
Expand All @@ -105,11 +108,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet4<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> 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)));
Expand All @@ -124,11 +127,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet5<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> 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)));
Expand All @@ -143,9 +146,9 @@ ImmutableSet<T> 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<T extends Enum<T>> {
static final class SetsImmutableEnumSet6<T extends Enum<T>> {
@BeforeTemplate
ImmutableSet<T> before(T e1, T e2, T e3, T e4, T e5, T e6) {
return ImmutableSet.of(e1, e2, e3, e4, e5, e6);
Expand All @@ -160,11 +163,11 @@ ImmutableSet<T> 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<T extends Enum<T>> {
@BeforeTemplate
@SuppressWarnings("ImmutableEnumSetIterable" /* This is a more specific template. */)
@SuppressWarnings("SetsImmutableEnumSetIterable" /* This is a more specific template. */)
ImmutableSet<T> before(T e1, @Repeated T elements) {
return ImmutableSet.copyOf(EnumSet.of(e1, Refaster.asVarargs(elements)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,32 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
return ImmutableSet.of(EnumSet.class);
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetIterable() {
return ImmutableSet.of(
ImmutableSet.copyOf(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)),
ImmutableSet.copyOf(EnumSet.allOf(RoundingMode.class)));
ImmutableSet<RoundingMode> testSetsImmutableEnumSetIterable() {
return ImmutableSet.copyOf(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetIterable1() {
return ImmutableSet.of(
ImmutableSet.copyOf(RoundingMode.values()),
ImmutableSet.copyOf(RoundingMode.class.getEnumConstants()));
ImmutableSet<RoundingMode> testSetsImmutableEnumSetIterableArray() {
return ImmutableSet.copyOf(RoundingMode.values());
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetOneElement() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet1() {
return ImmutableSet.of(
ImmutableSet.of(RoundingMode.UP), ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP)));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetTwoElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet2() {
return ImmutableSet.of(
ImmutableSet.of(RoundingMode.UP, RoundingMode.DOWN),
ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP, RoundingMode.DOWN)));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetThreeElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet3() {
return ImmutableSet.of(
ImmutableSet.of(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING),
ImmutableSet.copyOf(EnumSet.of(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING)));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFourElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet4() {
return ImmutableSet.of(
ImmutableSet.of(
RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR),
Expand All @@ -49,7 +45,7 @@ ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFourElements() {
RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR)));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFiveElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet5() {
return ImmutableSet.of(
ImmutableSet.of(
RoundingMode.UP,
Expand All @@ -66,7 +62,7 @@ ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFiveElements() {
RoundingMode.UNNECESSARY)));
}

ImmutableSet<RoundingMode> testImmutableEnumSetSixElements() {
ImmutableSet<RoundingMode> testSetsImmutableEnumSet6() {
return ImmutableSet.of(
RoundingMode.UP,
RoundingMode.DOWN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,40 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
return ImmutableSet.of(EnumSet.class);
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetIterable() {
return ImmutableSet.of(
Sets.immutableEnumSet(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY)),
Sets.immutableEnumSet(EnumSet.allOf(RoundingMode.class)));
ImmutableSet<RoundingMode> testSetsImmutableEnumSetIterable() {
return Sets.immutableEnumSet(EnumSet.range(RoundingMode.UP, RoundingMode.UNNECESSARY));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetIterable1() {
return ImmutableSet.of(
Sets.immutableEnumSet(Arrays.asList(RoundingMode.values())),
Sets.immutableEnumSet(Arrays.asList(RoundingMode.class.getEnumConstants())));
ImmutableSet<RoundingMode> testSetsImmutableEnumSetIterableArray() {
return Sets.immutableEnumSet(Arrays.asList(RoundingMode.values()));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetOneElement() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet1() {
return ImmutableSet.of(
Sets.immutableEnumSet(RoundingMode.UP), Sets.immutableEnumSet(RoundingMode.UP));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetTwoElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet2() {
return ImmutableSet.of(
Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN),
Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetThreeElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet3() {
return ImmutableSet.of(
Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING),
Sets.immutableEnumSet(RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFourElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet4() {
return ImmutableSet.of(
Sets.immutableEnumSet(
RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR),
Sets.immutableEnumSet(
RoundingMode.UP, RoundingMode.DOWN, RoundingMode.CEILING, RoundingMode.FLOOR));
}

ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFiveElements() {
ImmutableSet<ImmutableSet<RoundingMode>> testSetsImmutableEnumSet5() {
return ImmutableSet.of(
Sets.immutableEnumSet(
RoundingMode.UP,
Expand All @@ -66,7 +62,7 @@ ImmutableSet<ImmutableSet<RoundingMode>> testImmutableEnumSetFiveElements() {
RoundingMode.UNNECESSARY));
}

ImmutableSet<RoundingMode> testImmutableEnumSetSixElements() {
ImmutableSet<RoundingMode> testSetsImmutableEnumSet6() {
return Sets.immutableEnumSet(
RoundingMode.UP,
RoundingMode.DOWN,
Expand Down

0 comments on commit e80ef1d

Please sign in to comment.