diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java index f4ad0d81b6..b70f1c75d6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java @@ -161,6 +161,32 @@ Flux after(Mono mono) { } } + /** Prefer {@link Mono#flux()}} over more contrived alternatives. */ + static final class MonoFlux { + @BeforeTemplate + Flux before(Mono mono) { + return Flux.concat(mono); + } + + @AfterTemplate + Flux after(Mono mono) { + return mono.flux(); + } + } + + /** Don't unnecessarily invoke {@link Flux#concat(Publisher)}. */ + static final class FluxIdentity { + @BeforeTemplate + Flux before(Flux flux) { + return Flux.concat(flux); + } + + @AfterTemplate + Flux after(Flux flux) { + return flux; + } + } + /** * Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives. */ diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java index 818b6d6372..16a3351dd9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestInput.java @@ -49,6 +49,14 @@ Flux testMonoFlatMapToFlux() { return Mono.just("foo").flatMapMany(s -> Mono.just(s + s)); } + Flux testMonoFlux() { + return Flux.concat(Mono.just("foo")); + } + + Flux testFluxIdentity() { + return Flux.concat(Flux.just("foo")); + } + ImmutableSet>> testMonoCollectToOptional() { return ImmutableSet.of( Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java index b144223c61..38911f6fa1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/ReactorTemplatesTestOutput.java @@ -50,6 +50,14 @@ Flux testMonoFlatMapToFlux() { return Mono.just("foo").flatMap(s -> Mono.just(s + s)).flux(); } + Flux testMonoFlux() { + return Mono.just("foo").flux(); + } + + Flux testFluxIdentity() { + return Flux.just("foo"); + } + ImmutableSet>> testMonoCollectToOptional() { return ImmutableSet.of( Mono.just("foo").flux().collect(toOptional()),