diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java index 566248f74f..ef99623aa0 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java @@ -9,7 +9,6 @@ import io.reactivex.Maybe; import io.reactivex.Observable; import io.reactivex.Single; -import org.reactivestreams.Publisher; import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -39,12 +38,12 @@ Mono after(Completable completable) { */ static final class FlowableToFlux { @BeforeTemplate - Publisher before(Flowable flowable) { + Flux before(Flowable flowable) { return Refaster.anyOf( - flowable.compose(Flux::from), + Flux.from(flowable), flowable.to(Flux::from), flowable.as(Flux::from), - flowable.compose(RxJava2Adapter::flowableToFlux), + RxJava2Adapter.flowableToFlux(flowable), flowable.to(RxJava2Adapter::flowableToFlux)); } @@ -60,12 +59,11 @@ Flux after(Flowable flowable) { */ static final class FluxToFlowable { @BeforeTemplate - Publisher before(Flux flux) { + Flowable before(Flux flux) { return Refaster.anyOf( Flowable.fromPublisher(flux), - flux.transform(Flowable::fromPublisher), flux.as(Flowable::fromPublisher), - flux.transform(RxJava2Adapter::fluxToFlowable)); + RxJava2Adapter.fluxToFlowable(flux)); } @AfterTemplate @@ -132,12 +130,11 @@ Completable after(Mono mono) { */ static final class MonoToFlowable { @BeforeTemplate - Publisher before(Mono mono) { + Flowable before(Mono mono) { return Refaster.anyOf( Flowable.fromPublisher(mono), - mono.transform(Flowable::fromPublisher), mono.as(Flowable::fromPublisher), - mono.transform(RxJava2Adapter::monoToFlowable)); + RxJava2Adapter.monoToFlowable(mono)); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java index 42fc8b73c6..415a6954a1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java @@ -7,8 +7,6 @@ import io.reactivex.Maybe; import io.reactivex.Observable; import io.reactivex.Single; -import java.util.Arrays; -import org.reactivestreams.Publisher; import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -21,24 +19,20 @@ ImmutableSet> testCompletableToMono() { Completable.complete().to(RxJava2Adapter::completableToMono)); } - ImmutableSet> testFlowableToFlux() { - // The `Arrays.asList` is to avoid confusing `javac`; `ImmutableSet.of` uses varargs from the - // seventh parameter onwards. - return ImmutableSet.copyOf( - Arrays.asList( - Flowable.just(1).compose(Flux::from), - Flowable.just(2).to(Flux::from), - Flowable.just(3).as(Flux::from), - Flowable.just(4).compose(RxJava2Adapter::flowableToFlux), - Flowable.just(5).>to(RxJava2Adapter::flowableToFlux))); + ImmutableSet> testFlowableToFlux() { + return ImmutableSet.of( + Flux.from(Flowable.just(1)), + Flowable.just(2).to(Flux::from), + Flowable.just(3).as(Flux::from), + RxJava2Adapter.flowableToFlux(Flowable.just(4)), + Flowable.just(5).to(RxJava2Adapter::flowableToFlux)); } - ImmutableSet> testFluxToFlowable() { + ImmutableSet> testFluxToFlowable() { return ImmutableSet.of( Flowable.fromPublisher(Flux.just("foo")), - Flux.just("bar").transform(Flowable::fromPublisher), - Flux.just("baz").as(Flowable::fromPublisher), - Flux.just("qux").transform(RxJava2Adapter::fluxToFlowable)); + Flux.just("bar").as(Flowable::fromPublisher), + RxJava2Adapter.fluxToFlowable(Flux.just("baz"))); } ImmutableSet> testFluxToObservable() { @@ -61,12 +55,11 @@ ImmutableSet testMonoToCompletable() { RxJava2Adapter.monoToCompletable(Mono.empty())); } - ImmutableSet> testMonoToFlowable() { + ImmutableSet> testMonoToFlowable() { return ImmutableSet.of( Flowable.fromPublisher(Mono.just(1)), - Mono.just(2).transform(Flowable::fromPublisher), - Mono.just(3).as(Flowable::fromPublisher), - Mono.just(4).transform(RxJava2Adapter::monoToFlowable)); + Mono.just(2).as(Flowable::fromPublisher), + RxJava2Adapter.monoToFlowable(Mono.just(3))); } Maybe testMonoToMaybe() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java index 6ad2980890..ab093b0c0b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java @@ -7,8 +7,6 @@ import io.reactivex.Maybe; import io.reactivex.Observable; import io.reactivex.Single; -import java.util.Arrays; -import org.reactivestreams.Publisher; import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -21,24 +19,20 @@ ImmutableSet> testCompletableToMono() { Completable.complete().as(RxJava2Adapter::completableToMono)); } - ImmutableSet> testFlowableToFlux() { - // The `Arrays.asList` is to avoid confusing `javac`; `ImmutableSet.of` uses varargs from the - // seventh parameter onwards. - return ImmutableSet.copyOf( - Arrays.asList( - Flowable.just(1).as(RxJava2Adapter::flowableToFlux), - Flowable.just(2).as(RxJava2Adapter::flowableToFlux), - Flowable.just(3).as(RxJava2Adapter::flowableToFlux), - Flowable.just(4).as(RxJava2Adapter::flowableToFlux), - Flowable.just(5).as(RxJava2Adapter::flowableToFlux))); + ImmutableSet> testFlowableToFlux() { + return ImmutableSet.of( + Flowable.just(1).as(RxJava2Adapter::flowableToFlux), + Flowable.just(2).as(RxJava2Adapter::flowableToFlux), + Flowable.just(3).as(RxJava2Adapter::flowableToFlux), + Flowable.just(4).as(RxJava2Adapter::flowableToFlux), + Flowable.just(5).as(RxJava2Adapter::flowableToFlux)); } - ImmutableSet> testFluxToFlowable() { + ImmutableSet> testFluxToFlowable() { return ImmutableSet.of( Flux.just("foo").as(RxJava2Adapter::fluxToFlowable), Flux.just("bar").as(RxJava2Adapter::fluxToFlowable), - Flux.just("baz").as(RxJava2Adapter::fluxToFlowable), - Flux.just("qux").as(RxJava2Adapter::fluxToFlowable)); + Flux.just("baz").as(RxJava2Adapter::fluxToFlowable)); } ImmutableSet> testFluxToObservable() { @@ -61,12 +55,11 @@ ImmutableSet testMonoToCompletable() { Mono.empty().as(RxJava2Adapter::monoToCompletable)); } - ImmutableSet> testMonoToFlowable() { + ImmutableSet> testMonoToFlowable() { return ImmutableSet.of( Mono.just(1).as(RxJava2Adapter::monoToFlowable), Mono.just(2).as(RxJava2Adapter::monoToFlowable), - Mono.just(3).as(RxJava2Adapter::monoToFlowable), - Mono.just(4).as(RxJava2Adapter::monoToFlowable)); + Mono.just(3).as(RxJava2Adapter::monoToFlowable)); } Maybe testMonoToMaybe() {