diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index d0e055d65bd..2bd38ddccda 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1206,6 +1206,21 @@ Flux after(Flux> flux, int prefetch) { } } + /** + * Don't unnecessarily convert {@link Collection} to {@link Stream} before creating {@link Flux}. + */ + static final class FluxFromIterable { + @BeforeTemplate + Flux before(Collection c) { + return Flux.fromStream(c.stream()); + } + + @AfterTemplate + Flux after(Collection c) { + return Flux.fromIterable(c); + } + } + /** * Prefer {@link Flux#count()} followed by a conversion from {@code long} to {@code int} over * collecting into a list and counting its elements. @@ -1900,19 +1915,4 @@ Duration after(StepVerifier.LastStep step, Duration duration) { return step.verifyTimeout(duration); } } - - /** - * Don't unnecessarily convert {@link Collection} to {@link Stream} before creating {@link Flux}. - */ - static final class FluxFromIterable { - @BeforeTemplate - Flux before(Collection c) { - return Flux.fromStream(c.stream()); - } - - @AfterTemplate - Flux after(Collection c) { - return Flux.fromIterable(c); - } - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index edd3a724800..f2f04dc3ed1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -432,6 +432,10 @@ ImmutableSet> testConcatMapIterableIdentityWithPrefetch() { Flux.just(ImmutableList.of("bar")).concatMap(Flux::fromIterable, 2)); } + Flux testFluxFromIterable() { + return Flux.fromStream(ImmutableList.of("foo").stream()); + } + ImmutableSet> testFluxCountMapMathToIntExact() { return ImmutableSet.of( Flux.just(1).collect(toImmutableList()).map(Collection::size), @@ -646,8 +650,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return Mono.empty().as(StepVerifier::create).expectTimeout(Duration.ZERO).verify(); } - - Flux testFluxFromIterable() { - return Flux.fromStream(ImmutableList.of("foo").stream()); - } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index f0d4bf6b2b0..6bfd98f9729 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -427,6 +427,10 @@ ImmutableSet> testConcatMapIterableIdentityWithPrefetch() { Flux.just(ImmutableList.of("bar")).concatMapIterable(identity(), 2)); } + Flux testFluxFromIterable() { + return Flux.fromIterable(ImmutableList.of("foo")); + } + ImmutableSet> testFluxCountMapMathToIntExact() { return ImmutableSet.of( Flux.just(1).count().map(Math::toIntExact), @@ -627,8 +631,4 @@ Duration testStepVerifierLastStepVerifyErrorMessage() { Duration testStepVerifierLastStepVerifyTimeout() { return Mono.empty().as(StepVerifier::create).verifyTimeout(Duration.ZERO); } - - Flux testFluxFromIterable() { - return Flux.fromIterable(ImmutableList.of("foo")); - } }