From d014fed4009ba357ed216dd4764ff5f72c2dc125 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 24 Jul 2021 17:02:13 +0200 Subject: [PATCH] Deduplicate Refaster templates --- .../refastertemplates/AssertJTemplates.java | 26 ++++++++++++++++--- .../DoubleStreamTemplates.java | 10 ++----- .../ImmutableListMultimapTemplates.java | 15 +++-------- .../refastertemplates/IntStreamTemplates.java | 10 ++----- .../LongStreamTemplates.java | 10 ++----- .../refastertemplates/OptionalTemplates.java | 4 +-- .../refastertemplates/StreamTemplates.java | 10 ++----- .../DoubleStreamTemplatesTestInput.java | 14 +++------- .../DoubleStreamTemplatesTestOutput.java | 14 +++------- ...mutableListMultimapTemplatesTestInput.java | 17 +++--------- ...utableListMultimapTemplatesTestOutput.java | 12 ++------- .../IntStreamTemplatesTestInput.java | 14 +++------- .../IntStreamTemplatesTestOutput.java | 14 +++------- .../LongStreamTemplatesTestInput.java | 14 +++------- .../LongStreamTemplatesTestOutput.java | 14 +++------- .../bugpatterns/StreamTemplatesTestInput.java | 16 +++--------- .../StreamTemplatesTestOutput.java | 17 +++--------- pom.xml | 5 +--- 18 files changed, 73 insertions(+), 163 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java index 64039866..c0de0bfc 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java @@ -401,8 +401,8 @@ final class AssertJTemplates { @BeforeTemplate void before(Iterable iterable) { Refaster.anyOf( + assertThat(iterable).hasSize(0), assertThat(iterable.iterator().hasNext()).isFalse(), - assertThat(Iterables.size(iterable)).isEqualTo(0), assertThat(Iterables.size(iterable)).isEqualTo(0L), assertThat(Iterables.size(iterable)).isNotPositive()); } @@ -411,7 +411,6 @@ final class AssertJTemplates { void before(Collection iterable) { Refaster.anyOf( assertThat(iterable.isEmpty()).isTrue(), - assertThat(iterable.size()).isEqualTo(0), assertThat(iterable.size()).isEqualTo(0L), assertThat(iterable.size()).isNotPositive()); } @@ -608,8 +607,8 @@ final class AssertJTemplates { @BeforeTemplate void before(Map map) { Refaster.anyOf( + assertThat(map).hasSize(0), assertThat(map.isEmpty()).isTrue(), - assertThat(map.size()).isEqualTo(0), assertThat(map.size()).isEqualTo(0L), assertThat(map.size()).isNotPositive()); } @@ -781,18 +780,21 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsAnyOfVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsAnyOf" /* Varargs converted to array. */) IterableAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsAnyOf(Refaster.asVarargs(elements)); } @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsAnyOf" /* Varargs converted to array. */) ListAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsAnyOf(Refaster.asVarargs(elements)); } @AfterTemplate + @SuppressWarnings("ObjectEnumerableContainsOneElement" /* Not a true singleton. */) @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) ListAssert after(Stream stream, @Repeated U elements) { return assertThat(stream).containsAnyOf(elements); @@ -844,12 +846,14 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContains" /* Varargs converted to array. */) IterableAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).contains(Refaster.asVarargs(elements)); } @BeforeTemplate + @SuppressWarnings("AssertThatStreamContains" /* Varargs converted to array. */) ListAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).contains(Refaster.asVarargs(elements)); @@ -895,6 +899,7 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsExactlyVarargs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsExactly" /* Varargs converted to array. */) ListAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsExactly(Refaster.asVarargs(elements)); @@ -953,6 +958,7 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsExactlyInAnyOrderVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsExactlyInAnyOrder" /* Varargs converted to array. */) ListAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)) @@ -960,6 +966,7 @@ final class AssertJTemplates { } @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsExactlyInAnyOrder" /* Varargs converted to array. */) IterableAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)) @@ -967,6 +974,7 @@ final class AssertJTemplates { } @AfterTemplate + @SuppressWarnings("ObjectEnumerableContainsExactlyOneElement" /* Not a true singleton. */) @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) ListAssert after(Stream stream, @Repeated U elements) { return assertThat(stream).containsExactlyInAnyOrder(elements); @@ -997,12 +1005,14 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsSequenceVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsSequence" /* Varargs converted to array. */) ListAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsSequence(Refaster.asVarargs(elements)); } @AfterTemplate + @SuppressWarnings("ObjectEnumerableContainsOneElement" /* Not a true singleton. */) @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) ListAssert after(Stream stream, @Repeated U elements) { return assertThat(stream).containsSequence(elements); @@ -1033,6 +1043,7 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsSubsequenceVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsSubsequence" /* Varargs converted to array. */) ListAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)) @@ -1040,6 +1051,7 @@ final class AssertJTemplates { } @AfterTemplate + @SuppressWarnings("ObjectEnumerableContainsOneElement" /* Not a true singleton. */) @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) ListAssert after(Stream stream, @Repeated U elements) { return assertThat(stream).containsSubsequence(elements); @@ -1091,12 +1103,14 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamDoesNotContainVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamDoesNotContain" /* Varargs converted to array. */) IterableAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).doesNotContain(Refaster.asVarargs(elements)); } @BeforeTemplate + @SuppressWarnings("AssertThatStreamDoesNotContain" /* Varargs converted to array. */) ListAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).doesNotContain(Refaster.asVarargs(elements)); @@ -1133,6 +1147,7 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamDoesNotContainSequenceVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamDoesNotContainSequence" /* Varargs converted to array. */) ListAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)) @@ -1140,6 +1155,7 @@ final class AssertJTemplates { } @AfterTemplate + @SuppressWarnings("ObjectEnumerableDoesNotContainOneElement" /* Not a true singleton. */) @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) ListAssert after(Stream stream, @Repeated U elements) { return assertThat(stream).doesNotContainSequence(elements); @@ -1191,12 +1207,14 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamContainsOnlyVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsOnly" /* Varargs converted to array. */) IterableAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsOnly(Refaster.asVarargs(elements)); } @BeforeTemplate + @SuppressWarnings("AssertThatStreamContainsOnly" /* Varargs converted to array. */) ListAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).containsOnly(Refaster.asVarargs(elements)); @@ -1245,12 +1263,14 @@ final class AssertJTemplates { // XXX: This rule assumes the `collector` doesn't completely discard certain values. static final class AssertThatStreamIsSubsetOfVarArgs { @BeforeTemplate + @SuppressWarnings("AssertThatStreamIsSubsetOf" /* Varargs converted to array. */) IterableAssert before( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).isSubsetOf(Refaster.asVarargs(elements)); } @BeforeTemplate + @SuppressWarnings("AssertThatStreamIsSubsetOf" /* Varargs converted to array. */) ListAssert before2( Stream stream, Collector> collector, @Repeated U elements) { return assertThat(stream.collect(collector)).isSubsetOf(Refaster.asVarargs(elements)); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java index 6d68d69e..32ab0fbe 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java @@ -233,10 +233,7 @@ final class DoubleStreamTemplates { static final class DoubleStreamAllMatch { @BeforeTemplate boolean before(DoubleStream stream, DoublePredicate predicate) { - return Refaster.anyOf( - stream.noneMatch(predicate.negate()), - !stream.anyMatch(predicate.negate()), - stream.filter(predicate.negate()).findAny().isEmpty()); + return stream.noneMatch(predicate.negate()); } @AfterTemplate @@ -251,10 +248,7 @@ final class DoubleStreamTemplates { @BeforeTemplate boolean before(DoubleStream stream) { - return Refaster.anyOf( - stream.noneMatch(e -> !test(e)), - !stream.anyMatch(e -> !test(e)), - stream.filter(e -> !test(e)).findAny().isEmpty()); + return stream.noneMatch(e -> !test(e)); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java index dc66a657..43b1c04c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java @@ -56,10 +56,7 @@ final class ImmutableListMultimapTemplates { static final class EmptyImmutableListMultimap { @BeforeTemplate ImmutableMultimap before() { - return Refaster.anyOf( - ImmutableListMultimap.builder().build(), - ImmutableMultimap.builder().build(), - ImmutableMultimap.of()); + return Refaster.anyOf(ImmutableListMultimap.builder().build(), ImmutableMultimap.of()); } @AfterTemplate @@ -80,7 +77,6 @@ final class ImmutableListMultimapTemplates { ImmutableMultimap before(K key, V value) { return Refaster.anyOf( ImmutableListMultimap.builder().put(key, value).build(), - ImmutableMultimap.builder().put(key, value).build(), ImmutableMultimap.of(key, value)); } @@ -99,9 +95,8 @@ final class ImmutableListMultimapTemplates { ImmutableMultimap before(Map.Entry entry) { return Refaster.anyOf( ImmutableListMultimap.builder().put(entry).build(), - Stream.of(entry).collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)), - ImmutableMultimap.builder().put(entry).build(), - ImmutableMultimap.of(entry.getKey(), entry.getValue())); + Stream.of(entry) + .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue))); } @AfterTemplate @@ -118,8 +113,7 @@ final class ImmutableListMultimapTemplates { ImmutableListMultimap.copyOf(iterable.entries()), ImmutableListMultimap.builder().putAll(iterable).build(), ImmutableMultimap.copyOf(iterable), - ImmutableMultimap.copyOf(iterable.entries()), - ImmutableMultimap.builder().putAll(iterable).build()); + ImmutableMultimap.copyOf(iterable.entries())); } @BeforeTemplate @@ -129,7 +123,6 @@ final class ImmutableListMultimapTemplates { ImmutableListMultimap.builder().putAll(iterable).build(), Streams.stream(iterable) .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)), - ImmutableMultimap.builder().putAll(iterable).build(), ImmutableMultimap.copyOf(iterable)); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java index 2cd17caf..52d8bb2d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java @@ -246,10 +246,7 @@ final class IntStreamTemplates { static final class IntStreamAllMatch { @BeforeTemplate boolean before(IntStream stream, IntPredicate predicate) { - return Refaster.anyOf( - stream.noneMatch(predicate.negate()), - !stream.anyMatch(predicate.negate()), - stream.filter(predicate.negate()).findAny().isEmpty()); + return stream.noneMatch(predicate.negate()); } @AfterTemplate @@ -264,10 +261,7 @@ final class IntStreamTemplates { @BeforeTemplate boolean before(IntStream stream) { - return Refaster.anyOf( - stream.noneMatch(e -> !test(e)), - !stream.anyMatch(e -> !test(e)), - stream.filter(e -> !test(e)).findAny().isEmpty()); + return stream.noneMatch(e -> !test(e)); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java index 8e5cbcd9..2cefe257 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java @@ -246,10 +246,7 @@ final class LongStreamTemplates { static final class LongStreamAllMatch { @BeforeTemplate boolean before(LongStream stream, LongPredicate predicate) { - return Refaster.anyOf( - stream.noneMatch(predicate.negate()), - !stream.anyMatch(predicate.negate()), - stream.filter(predicate.negate()).findAny().isEmpty()); + return stream.noneMatch(predicate.negate()); } @AfterTemplate @@ -264,10 +261,7 @@ final class LongStreamTemplates { @BeforeTemplate boolean before(LongStream stream) { - return Refaster.anyOf( - stream.noneMatch(e -> !test(e)), - !stream.anyMatch(e -> !test(e)), - stream.filter(e -> !test(e)).findAny().isEmpty()); + return stream.noneMatch(e -> !test(e)); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java index 4d70a5da..ac55ec15 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java @@ -20,10 +20,10 @@ final class OptionalTemplates { private OptionalTemplates() {} static final class OptionalOfNullable { - @BeforeTemplate // XXX: Refaster should be smart enough to also rewrite occurrences in which there are // parentheses around the null check, but that's currently not the case. Try to fix that. - // XXX: This is a special case of `TernaryOperatorOptionalNegativeFiltering`. + @BeforeTemplate + @SuppressWarnings("TernaryOperatorOptionalNegativeFiltering" /* Special case. */) Optional before(T object) { return object == null ? Optional.empty() : Optional.of(object); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java index 1a517d0a..7471ce3f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java @@ -294,10 +294,7 @@ final class StreamTemplates { static final class StreamAllMatch { @BeforeTemplate boolean before(Stream stream, Predicate predicate) { - return Refaster.anyOf( - stream.noneMatch(Refaster.anyOf(not(predicate), predicate.negate())), - !stream.anyMatch(Refaster.anyOf(not(predicate), predicate.negate())), - stream.filter(Refaster.anyOf(not(predicate), predicate.negate())).findAny().isEmpty()); + return stream.noneMatch(Refaster.anyOf(not(predicate), predicate.negate())); } @AfterTemplate @@ -312,10 +309,7 @@ final class StreamTemplates { @BeforeTemplate boolean before(Stream stream) { - return Refaster.anyOf( - stream.noneMatch(e -> !test(e)), - !stream.anyMatch(e -> !test(e)), - stream.filter(e -> !test(e)).findAny().isEmpty()); + return stream.noneMatch(e -> !test(e)); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestInput.java index e2f8a925..bc5381a7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestInput.java @@ -83,18 +83,12 @@ final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { DoubleStream.of(2).filter(n -> n > 2).findAny().isPresent()); } - ImmutableSet testDoubleStreamAllMatch() { + boolean testDoubleStreamAllMatch() { DoublePredicate pred = i -> i > 0; - return ImmutableSet.of( - DoubleStream.of(1).noneMatch(pred.negate()), - !DoubleStream.of(2).anyMatch(pred.negate()), - DoubleStream.of(3).filter(pred.negate()).findAny().isEmpty()); + return DoubleStream.of(1).noneMatch(pred.negate()); } - ImmutableSet testDoubleStreamAllMatch2() { - return ImmutableSet.of( - DoubleStream.of(1).noneMatch(n -> !(n > 1)), - !DoubleStream.of(2).anyMatch(n -> !(n > 2)), - DoubleStream.of(3).filter(n -> !(n > 3)).findAny().isEmpty()); + boolean testDoubleStreamAllMatch2() { + return DoubleStream.of(1).noneMatch(n -> !(n > 1)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestOutput.java index 41e2c2b1..8cfa897a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DoubleStreamTemplatesTestOutput.java @@ -82,18 +82,12 @@ final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { DoubleStream.of(1).anyMatch(n -> n > 1), DoubleStream.of(2).anyMatch(n -> n > 2)); } - ImmutableSet testDoubleStreamAllMatch() { + boolean testDoubleStreamAllMatch() { DoublePredicate pred = i -> i > 0; - return ImmutableSet.of( - DoubleStream.of(1).allMatch(pred), - DoubleStream.of(2).allMatch(pred), - DoubleStream.of(3).allMatch(pred)); + return DoubleStream.of(1).allMatch(pred); } - ImmutableSet testDoubleStreamAllMatch2() { - return ImmutableSet.of( - DoubleStream.of(1).allMatch(n -> n > 1), - DoubleStream.of(2).allMatch(n -> n > 2), - DoubleStream.of(3).allMatch(n -> n > 3)); + boolean testDoubleStreamAllMatch2() { + return DoubleStream.of(1).allMatch(n -> n > 1); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java index 16ce93f5..41f9156c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestInput.java @@ -33,25 +33,20 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa ImmutableSet> testEmptyImmutableListMultimap() { return ImmutableSet.of( - ImmutableListMultimap.builder().build(), - ImmutableMultimap.builder().build(), - ImmutableMultimap.of()); + ImmutableListMultimap.builder().build(), ImmutableMultimap.of()); } ImmutableSet> testPairToImmutableListMultimap() { return ImmutableSet.of( ImmutableListMultimap.builder().put("foo", 1).build(), - ImmutableMultimap.builder().put("bar", 2).build(), - ImmutableMultimap.of("baz", 3)); + ImmutableMultimap.of("bar", 2)); } ImmutableList> testEntryToImmutableListMultimap() { return ImmutableList.of( ImmutableListMultimap.builder().put(Map.entry("foo", 1)).build(), Stream.of(Map.entry("foo", 1)) - .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)), - ImmutableMultimap.builder().put(Map.entry("foo", 1)).build(), - ImmutableMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue())); + .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue))); } ImmutableList> testIterableToImmutableListMultimap() { @@ -69,12 +64,6 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa .collect(toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue)), ImmutableMultimap.copyOf(ImmutableListMultimap.of("foo", 1)), ImmutableMultimap.copyOf(ImmutableListMultimap.of("foo", 1).entries()), - ImmutableMultimap.builder() - .putAll(ImmutableListMultimap.of("foo", 1)) - .build(), - ImmutableMultimap.builder() - .putAll(ImmutableListMultimap.of("foo", 1).entries()) - .build(), ImmutableMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1)))); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java index 8bfb282f..f9ccde87 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ImmutableListMultimapTemplatesTestOutput.java @@ -32,21 +32,15 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa } ImmutableSet> testEmptyImmutableListMultimap() { - return ImmutableSet.of( - ImmutableListMultimap.of(), ImmutableListMultimap.of(), ImmutableListMultimap.of()); + return ImmutableSet.of(ImmutableListMultimap.of(), ImmutableListMultimap.of()); } ImmutableSet> testPairToImmutableListMultimap() { - return ImmutableSet.of( - ImmutableListMultimap.of("foo", 1), - ImmutableListMultimap.of("bar", 2), - ImmutableListMultimap.of("baz", 3)); + return ImmutableSet.of(ImmutableListMultimap.of("foo", 1), ImmutableListMultimap.of("bar", 2)); } ImmutableList> testEntryToImmutableListMultimap() { return ImmutableList.of( - ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()), - ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()), ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()), ImmutableListMultimap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue())); } @@ -60,8 +54,6 @@ final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCa ImmutableListMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1))), ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)), ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)), - ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1)), - ImmutableListMultimap.copyOf(ImmutableListMultimap.of("foo", 1).entries()), ImmutableListMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1)))); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestInput.java index 3cab21a9..b0a27c6e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestInput.java @@ -87,18 +87,12 @@ final class IntStreamTemplatesTest implements RefasterTemplateTestCase { IntStream.of(2).filter(n -> n > 2).findAny().isPresent()); } - ImmutableSet testIntStreamAllMatch() { + boolean testIntStreamAllMatch() { IntPredicate pred = i -> i > 0; - return ImmutableSet.of( - IntStream.of(1).noneMatch(pred.negate()), - !IntStream.of(2).anyMatch(pred.negate()), - IntStream.of(3).filter(pred.negate()).findAny().isEmpty()); + return IntStream.of(1).noneMatch(pred.negate()); } - ImmutableSet testIntStreamAllMatch2() { - return ImmutableSet.of( - IntStream.of(1).noneMatch(n -> !(n > 1)), - !IntStream.of(2).anyMatch(n -> !(n > 2)), - IntStream.of(3).filter(n -> !(n > 3)).findAny().isEmpty()); + boolean testIntStreamAllMatch2() { + return IntStream.of(1).noneMatch(n -> !(n > 1)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestOutput.java index 1ff8c50a..7e27f12b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/IntStreamTemplatesTestOutput.java @@ -86,18 +86,12 @@ final class IntStreamTemplatesTest implements RefasterTemplateTestCase { IntStream.of(1).anyMatch(n -> n > 1), IntStream.of(2).anyMatch(n -> n > 2)); } - ImmutableSet testIntStreamAllMatch() { + boolean testIntStreamAllMatch() { IntPredicate pred = i -> i > 0; - return ImmutableSet.of( - IntStream.of(1).allMatch(pred), - IntStream.of(2).allMatch(pred), - IntStream.of(3).allMatch(pred)); + return IntStream.of(1).allMatch(pred); } - ImmutableSet testIntStreamAllMatch2() { - return ImmutableSet.of( - IntStream.of(1).allMatch(n -> n > 1), - IntStream.of(2).allMatch(n -> n > 2), - IntStream.of(3).allMatch(n -> n > 3)); + boolean testIntStreamAllMatch2() { + return IntStream.of(1).allMatch(n -> n > 1); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestInput.java index 8ed197df..8d3ccd69 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestInput.java @@ -87,18 +87,12 @@ final class LongStreamTemplatesTest implements RefasterTemplateTestCase { LongStream.of(2).filter(n -> n > 2).findAny().isPresent()); } - ImmutableSet testLongStreamAllMatch() { + boolean testLongStreamAllMatch() { LongPredicate pred = i -> i > 0; - return ImmutableSet.of( - LongStream.of(1).noneMatch(pred.negate()), - !LongStream.of(2).anyMatch(pred.negate()), - LongStream.of(3).filter(pred.negate()).findAny().isEmpty()); + return LongStream.of(1).noneMatch(pred.negate()); } - ImmutableSet testLongStreamAllMatch2() { - return ImmutableSet.of( - LongStream.of(1).noneMatch(n -> !(n > 1)), - !LongStream.of(2).anyMatch(n -> !(n > 2)), - LongStream.of(3).filter(n -> !(n > 3)).findAny().isEmpty()); + boolean testLongStreamAllMatch2() { + return LongStream.of(1).noneMatch(n -> !(n > 1)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestOutput.java index 2b7063f2..f44c3281 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/LongStreamTemplatesTestOutput.java @@ -86,18 +86,12 @@ final class LongStreamTemplatesTest implements RefasterTemplateTestCase { LongStream.of(1).anyMatch(n -> n > 1), LongStream.of(2).anyMatch(n -> n > 2)); } - ImmutableSet testLongStreamAllMatch() { + boolean testLongStreamAllMatch() { LongPredicate pred = i -> i > 0; - return ImmutableSet.of( - LongStream.of(1).allMatch(pred), - LongStream.of(2).allMatch(pred), - LongStream.of(3).allMatch(pred)); + return LongStream.of(1).allMatch(pred); } - ImmutableSet testLongStreamAllMatch2() { - return ImmutableSet.of( - LongStream.of(1).allMatch(n -> n > 1), - LongStream.of(2).allMatch(n -> n > 2), - LongStream.of(3).allMatch(n -> n > 3)); + boolean testLongStreamAllMatch2() { + return LongStream.of(1).allMatch(n -> n > 1); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestInput.java index f46a8556..46175bbf 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestInput.java @@ -118,20 +118,10 @@ final class StreamTemplatesTest implements RefasterTemplateTestCase { Predicate pred = String::isBlank; return ImmutableSet.of( Stream.of("foo").noneMatch(not(String::isBlank)), - Stream.of("bar").noneMatch(pred.negate()), - !Stream.of("baz").anyMatch(not(s -> s.length() > 1)), - !Stream.of("qux").anyMatch(pred.negate()), - Stream.of("quux").filter(not(String::isEmpty)).findAny().isEmpty(), - Stream.of("quuz").filter(pred.negate()).findAny().isEmpty(), - Stream.of(Boolean.TRUE).noneMatch(b -> !b), - !Stream.of(Boolean.TRUE).anyMatch(b -> !b), - Stream.of(Boolean.TRUE).filter(b -> !b).findAny().isEmpty()); + Stream.of("bar").noneMatch(pred.negate())); } - ImmutableSet testStreamAllMatch2() { - return ImmutableSet.of( - Stream.of("foo").noneMatch(s -> !s.isBlank()), - !Stream.of("bar").anyMatch(s -> !s.isEmpty()), - Stream.of("baz").filter(s -> !s.isBlank()).findAny().isEmpty()); + boolean testStreamAllMatch2() { + return Stream.of("foo").noneMatch(s -> !s.isBlank()); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestOutput.java index 6a203047..2a224d4a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/StreamTemplatesTestOutput.java @@ -117,21 +117,10 @@ final class StreamTemplatesTest implements RefasterTemplateTestCase { ImmutableSet testStreamAllMatch() { Predicate pred = String::isBlank; return ImmutableSet.of( - Stream.of("foo").allMatch(String::isBlank), - Stream.of("bar").allMatch(pred), - Stream.of("baz").allMatch(s -> s.length() > 1), - Stream.of("qux").allMatch(pred), - Stream.of("quux").allMatch(String::isEmpty), - Stream.of("quuz").allMatch(pred), - Stream.of(Boolean.TRUE).allMatch(b -> b), - Stream.of(Boolean.TRUE).allMatch(b -> b), - Stream.of(Boolean.TRUE).allMatch(b -> b)); + Stream.of("foo").allMatch(String::isBlank), Stream.of("bar").allMatch(pred)); } - ImmutableSet testStreamAllMatch2() { - return ImmutableSet.of( - Stream.of("foo").allMatch(s -> s.isBlank()), - Stream.of("bar").allMatch(s -> s.isEmpty()), - Stream.of("baz").allMatch(s -> s.isBlank())); + boolean testStreamAllMatch2() { + return Stream.of("foo").allMatch(s -> s.isBlank()); } } diff --git a/pom.xml b/pom.xml index ae1a9f3d..66b72dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -1197,14 +1197,11 @@ - - -Xep:MethodReferenceUsage:OFF -Xep:Refaster:OFF + -Xep:MethodReferenceUsage:OFF