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 3201a8d4ee..ef56d3a32b 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 @@ -271,11 +271,37 @@ Flux after(Flux flux) { } } + /** Prefer {@link Mono#onErrorComplete()} over more contrived alternatives. */ + static final class MonoOnErrorComplete { + @BeforeTemplate + Mono before(Mono mono) { + return mono.onErrorResume(e -> Mono.empty()); + } + + @AfterTemplate + Mono after(Mono mono) { + return mono.onErrorComplete(); + } + } + + /** Prefer {@link Flux#onErrorComplete()} over more contrived alternatives. */ + static final class FluxOnErrorComplete { + @BeforeTemplate + Flux before(Flux flux) { + return flux.onErrorResume(e -> Refaster.anyOf(Mono.empty(), Flux.empty())); + } + + @AfterTemplate + Flux after(Flux flux) { + return flux.onErrorComplete(); + } + } + /** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */ static final class PublisherProbeEmpty { @BeforeTemplate PublisherProbe before() { - return Refaster.anyOf(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty())); + return PublisherProbe.of(Refaster.anyOf(Mono.empty(), Flux.empty())); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java index bd353ed35a..4844a8dcab 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java @@ -95,6 +95,16 @@ Flux testFluxCast() { return Flux.just(1).map(Number.class::cast); } + Mono testMonoOnErrorComplete() { + return Mono.just(1).onErrorResume(e -> Mono.empty()); + } + + ImmutableSet> testFluxOnErrorComplete() { + return ImmutableSet.of( + Flux.just(1).onErrorResume(e -> Mono.empty()), + Flux.just(2).onErrorResume(e -> Flux.empty())); + } + ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty())); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java index 2116246d73..34a39c6259 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java @@ -94,6 +94,14 @@ Flux testFluxCast() { return Flux.just(1).cast(Number.class); } + Mono testMonoOnErrorComplete() { + return Mono.just(1).onErrorComplete(); + } + + ImmutableSet> testFluxOnErrorComplete() { + return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete()); + } + ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty()); }