diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 04499a86f7..fdd5f2e77f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -3,6 +3,7 @@ import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; +import static java.util.function.Function.identity; import static java.util.function.Predicate.not; import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.filtering; @@ -27,6 +28,7 @@ import com.google.errorprone.refaster.annotation.MayOptionallyUse; import com.google.errorprone.refaster.annotation.NotMatches; import com.google.errorprone.refaster.annotation.Placeholder; +import com.google.errorprone.refaster.annotation.Repeated; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Collection; @@ -623,4 +625,16 @@ R after( return stream.flatMap(mapper).collect(collector); } } + + static final class StreamsConcat { + @BeforeTemplate + Stream before(@Repeated Stream stream) { + return Stream.of(Refaster.asVarargs(stream)).flatMap(Refaster.anyOf(identity(), s -> s)); + } + + @AfterTemplate + Stream after(@Repeated Stream stream) { + return Streams.concat(Refaster.asVarargs(stream)); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 48f0de13a7..a9ec0e4ca1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -3,6 +3,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static java.util.Comparator.comparingInt; import static java.util.Comparator.reverseOrder; +import static java.util.function.Function.identity; import static java.util.function.Predicate.not; import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.filtering; @@ -40,6 +41,7 @@ public ImmutableSet elidedTypesAndStaticImports() { counting(), filtering(null, null), flatMapping(null, null), + identity(), mapping(null, null), maxBy(null), minBy(null), @@ -250,4 +252,10 @@ ImmutableSet testStreamMapCollect() { ImmutableSet testStreamFlatMapCollect() { return Stream.of(1).collect(flatMapping(n -> Stream.of(n, n), toImmutableSet())); } + + ImmutableSet> testStreamsConcat() { + return ImmutableSet.of( + Stream.of(Stream.of(1), Stream.of(2)).flatMap(identity()), + Stream.of(Stream.of(3), Stream.of(4)).flatMap(v -> v)); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index 7ed6bbd4ae..ab69c763bc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -4,6 +4,7 @@ import static java.util.Comparator.comparingInt; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; +import static java.util.function.Function.identity; import static java.util.function.Predicate.not; import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.filtering; @@ -42,6 +43,7 @@ public ImmutableSet elidedTypesAndStaticImports() { counting(), filtering(null, null), flatMapping(null, null), + identity(), mapping(null, null), maxBy(null), minBy(null), @@ -251,4 +253,9 @@ ImmutableSet testStreamMapCollect() { ImmutableSet testStreamFlatMapCollect() { return Stream.of(1).flatMap(n -> Stream.of(n, n)).collect(toImmutableSet()); } + + ImmutableSet> testStreamsConcat() { + return ImmutableSet.of( + Streams.concat(Stream.of(1), Stream.of(2)), Streams.concat(Stream.of(3), Stream.of(4))); + } }