From f9f7d25f6c49b78a8f03f1ae95a28f8301b5ab6f Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 4 Oct 2023 21:41:13 +0200 Subject: [PATCH] Suggestions --- .../refasterrules/ReactorRules.java | 24 +++++++------------ .../refasterrules/ReactorRulesTestInput.java | 12 ++++------ .../refasterrules/ReactorRulesTestOutput.java | 8 +++---- 3 files changed, 16 insertions(+), 28 deletions(-) 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 78d531fbe1a..bc5462092b6 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 @@ -988,34 +988,26 @@ Flux after(Flux flux) { /** Prefer {@link Mono#ofType(Class)} over more contrived alternatives. */ static final class MonoOfType { @BeforeTemplate - Mono before(Mono mono) { - return mono.filter( - Refaster.anyOf( - Refaster.clazz()::isInstance, - x -> Refaster.clazz().isAssignableFrom(x.getClass()))) - .cast(Refaster.clazz()); + Mono before(Mono mono, Class clazz) { + return mono.filter(clazz::isInstance).cast(clazz); } @AfterTemplate - Mono after(Mono mono) { - return mono.ofType(Refaster.clazz()); + Mono after(Mono mono, Class clazz) { + return mono.ofType(clazz); } } /** Prefer {@link Flux#ofType(Class)} over more contrived alternatives. */ static final class FluxOfType { @BeforeTemplate - Flux before(Flux flux) { - return flux.filter( - Refaster.anyOf( - Refaster.clazz()::isInstance, - x -> Refaster.clazz().isAssignableFrom(x.getClass()))) - .cast(Refaster.clazz()); + Flux before(Flux flux, Class clazz) { + return flux.filter(clazz::isInstance).cast(clazz); } @AfterTemplate - Flux after(Flux flux) { - return flux.ofType(Refaster.clazz()); + Flux after(Flux flux, Class clazz) { + return flux.ofType(clazz); } } 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 8b5a36885a7..ddb96926b6f 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 @@ -333,16 +333,12 @@ Flux testFluxCast() { return Flux.just(1).map(Number.class::cast); } - ImmutableSet> testMonoOfType() { - return ImmutableSet.of( - Mono.just(1).filter(Number.class::isInstance).cast(Number.class), - Mono.just(2).filter(n -> Number.class.isAssignableFrom(n.getClass())).cast(Number.class)); + Mono testMonoOfType() { + return Mono.just(1).filter(Number.class::isInstance).cast(Number.class); } - ImmutableSet> testFluxOfType() { - return ImmutableSet.of( - Flux.just(1).filter(Number.class::isInstance).cast(Number.class), - Flux.just(2).filter(n -> Number.class.isAssignableFrom(n.getClass())).cast(Number.class)); + Flux testFluxOfType() { + return Flux.just(1).filter(Number.class::isInstance).cast(Number.class); } Mono testMonoFlatMap() { 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 5ba505b714f..35ad88b6fe3 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 @@ -326,12 +326,12 @@ Flux testFluxCast() { return Flux.just(1).cast(Number.class); } - ImmutableSet> testMonoOfType() { - return ImmutableSet.of(Mono.just(1).ofType(Number.class), Mono.just(2).ofType(Number.class)); + Mono testMonoOfType() { + return Mono.just(1).ofType(Number.class); } - ImmutableSet> testFluxOfType() { - return ImmutableSet.of(Flux.just(1).ofType(Number.class), Flux.just(2).ofType(Number.class)); + Flux testFluxOfType() { + return Flux.just(1).ofType(Number.class); } Mono testMonoFlatMap() {