Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce StreamsConcat Refaster rule #619

Merged
merged 4 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -623,4 +625,16 @@ R after(
return stream.flatMap(mapper).collect(collector);
}
}

static final class StreamsConcat<T> {
@BeforeTemplate
Stream<T> before(@Repeated Stream<T> stream) {
return Stream.of(Refaster.asVarargs(stream)).flatMap(Refaster.anyOf(identity(), s -> s));
}

@AfterTemplate
Stream<T> after(@Repeated Stream<T> stream) {
return Streams.concat(Refaster.asVarargs(stream));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +41,7 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
counting(),
filtering(null, null),
flatMapping(null, null),
identity(),
mapping(null, null),
maxBy(null),
minBy(null),
Expand Down Expand Up @@ -250,4 +252,10 @@ ImmutableSet<Integer> testStreamMapCollect() {
ImmutableSet<Integer> testStreamFlatMapCollect() {
return Stream.of(1).collect(flatMapping(n -> Stream.of(n, n), toImmutableSet()));
}

ImmutableSet<Stream<Integer>> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +43,7 @@ public ImmutableSet<Object> elidedTypesAndStaticImports() {
counting(),
filtering(null, null),
flatMapping(null, null),
identity(),
mapping(null, null),
maxBy(null),
minBy(null),
Expand Down Expand Up @@ -251,4 +253,9 @@ ImmutableSet<Integer> testStreamMapCollect() {
ImmutableSet<Integer> testStreamFlatMapCollect() {
return Stream.of(1).flatMap(n -> Stream.of(n, n)).collect(toImmutableSet());
}

ImmutableSet<Stream<Integer>> testStreamsConcat() {
return ImmutableSet.of(
Streams.concat(Stream.of(1), Stream.of(2)), Streams.concat(Stream.of(3), Stream.of(4)));
}
}