From 4922869118dccab456fc065dbbae2c774d59ee8a Mon Sep 17 00:00:00 2001 From: Graeme Rocher Date: Fri, 28 Jul 2023 13:33:54 +0200 Subject: [PATCH 1/2] move Async validation to processor module --- context/build.gradle | 1 - .../services/io.micronaut.inject.visitor.TypeElementVisitor | 2 -- core-processor/build.gradle | 3 +++ .../micronaut/validation/visitor}/AsyncTypeElementVisitor.java | 2 +- .../java/io/micronaut/validation/visitor}/package-info.java | 2 +- .../services/io.micronaut.inject.visitor.TypeElementVisitor | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 context/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor rename {context/src/main/java/io/micronaut/scheduling/async/validation => core-processor/src/main/java/io/micronaut/validation/visitor}/AsyncTypeElementVisitor.java (97%) rename {context/src/main/java/io/micronaut/scheduling/async/validation => core-processor/src/main/java/io/micronaut/validation/visitor}/package-info.java (93%) diff --git a/context/build.gradle b/context/build.gradle index 8f35ca692fd..ef03012b13d 100644 --- a/context/build.gradle +++ b/context/build.gradle @@ -9,7 +9,6 @@ dependencies { api project(':aop') compileOnly project(':core-reactive') - compileOnly project(':core-processor') compileOnly libs.log4j compileOnly libs.logback.classic diff --git a/context/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor b/context/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor deleted file mode 100644 index 952c37d738d..00000000000 --- a/context/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor +++ /dev/null @@ -1,2 +0,0 @@ -io.micronaut.scheduling.async.validation.AsyncTypeElementVisitor - diff --git a/core-processor/build.gradle b/core-processor/build.gradle index 2847cdcbcca..676e82f358a 100644 --- a/core-processor/build.gradle +++ b/core-processor/build.gradle @@ -3,6 +3,7 @@ plugins { } dependencies { + api project(":inject") api project(":aop") api libs.asm.tree @@ -11,6 +12,8 @@ dependencies { exclude group:'org.javassist', module:'javassist' exclude group:'com.google.guava', module:'guava' } + implementation project(":context") + implementation project(":core-reactive") compileOnly libs.managed.kotlin.stdlib.jdk8 } diff --git a/context/src/main/java/io/micronaut/scheduling/async/validation/AsyncTypeElementVisitor.java b/core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java similarity index 97% rename from context/src/main/java/io/micronaut/scheduling/async/validation/AsyncTypeElementVisitor.java rename to core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java index b9b31eb2edf..8d4a596824e 100644 --- a/context/src/main/java/io/micronaut/scheduling/async/validation/AsyncTypeElementVisitor.java +++ b/core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micronaut.scheduling.async.validation; +package io.micronaut.validation.visitor.async; import io.micronaut.core.annotation.Internal; import io.micronaut.core.annotation.NonNull; diff --git a/context/src/main/java/io/micronaut/scheduling/async/validation/package-info.java b/core-processor/src/main/java/io/micronaut/validation/visitor/package-info.java similarity index 93% rename from context/src/main/java/io/micronaut/scheduling/async/validation/package-info.java rename to core-processor/src/main/java/io/micronaut/validation/visitor/package-info.java index 0f4e4faa0d9..b5a50a5de8a 100644 --- a/context/src/main/java/io/micronaut/scheduling/async/validation/package-info.java +++ b/core-processor/src/main/java/io/micronaut/validation/visitor/package-info.java @@ -19,4 +19,4 @@ * @author graemerocher * @since 1.0 */ -package io.micronaut.scheduling.async.validation; +package io.micronaut.validation.visitor.async; diff --git a/core-processor/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor b/core-processor/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor index 46ee8919429..fd951a13790 100644 --- a/core-processor/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor +++ b/core-processor/src/main/resources/META-INF/services/io.micronaut.inject.visitor.TypeElementVisitor @@ -4,3 +4,4 @@ io.micronaut.context.visitor.ContextConfigurerVisitor io.micronaut.context.visitor.ExecutableVisitor io.micronaut.context.visitor.InternalApiTypeElementVisitor io.micronaut.context.visitor.ConfigurationReaderVisitor +io.micronaut.validation.visitor.async.AsyncTypeElementVisitor From 37ae77aa07268155640e46a50ea1a705b36e0109 Mon Sep 17 00:00:00 2001 From: Graeme Rocher Date: Fri, 28 Jul 2023 13:40:30 +0200 Subject: [PATCH 2/2] fix circular issue --- core-processor/build.gradle | 1 - .../{ => async}/AsyncTypeElementVisitor.java | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) rename core-processor/src/main/java/io/micronaut/validation/visitor/{ => async}/AsyncTypeElementVisitor.java (67%) diff --git a/core-processor/build.gradle b/core-processor/build.gradle index 676e82f358a..4cc85ed42dc 100644 --- a/core-processor/build.gradle +++ b/core-processor/build.gradle @@ -12,7 +12,6 @@ dependencies { exclude group:'org.javassist', module:'javassist' exclude group:'com.google.guava', module:'guava' } - implementation project(":context") implementation project(":core-reactive") compileOnly libs.managed.kotlin.stdlib.jdk8 diff --git a/core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java b/core-processor/src/main/java/io/micronaut/validation/visitor/async/AsyncTypeElementVisitor.java similarity index 67% rename from core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java rename to core-processor/src/main/java/io/micronaut/validation/visitor/async/AsyncTypeElementVisitor.java index 8d4a596824e..f7b4f0e6fca 100644 --- a/core-processor/src/main/java/io/micronaut/validation/visitor/AsyncTypeElementVisitor.java +++ b/core-processor/src/main/java/io/micronaut/validation/visitor/async/AsyncTypeElementVisitor.java @@ -22,19 +22,26 @@ import io.micronaut.inject.ast.MethodElement; import io.micronaut.inject.visitor.TypeElementVisitor; import io.micronaut.inject.visitor.VisitorContext; -import io.micronaut.scheduling.annotation.Async; import org.reactivestreams.Publisher; +import java.util.Set; import java.util.concurrent.CompletionStage; /** - * A {@link TypeElementVisitor} that validates methods annotated with {@link Async} return void or futures. + * A {@link TypeElementVisitor} that validates methods annotated with {@code @ËšAsync} return void or futures. * * @author graemerocher * @since 1.0 */ @Internal -public final class AsyncTypeElementVisitor implements TypeElementVisitor { +public final class AsyncTypeElementVisitor implements TypeElementVisitor { + + private static final String ANN = "io.micronaut.scheduling.annotation.Async"; + + @Override + public Set getSupportedAnnotationNames() { + return Set.of(ANN); + } @NonNull @Override @@ -44,14 +51,16 @@ public VisitorKind getVisitorKind() { @Override public void visitMethod(MethodElement element, VisitorContext context) { - ClassElement returnType = element.getReturnType(); - boolean isValid = returnType != null && + if (element.hasDeclaredAnnotation(ANN)) { + ClassElement returnType = element.getReturnType(); + boolean isValid = returnType != null && (returnType.isAssignable(CompletionStage.class) || returnType.isAssignable(void.class) || - returnType.isAssignable(Publisher.class) || - Publishers.getKnownReactiveTypes().stream().anyMatch(returnType::isAssignable)); + returnType.isAssignable(Publisher.class) || + Publishers.getKnownReactiveTypes().stream().anyMatch(returnType::isAssignable)); - if (!isValid) { - context.fail("Method must return void, a Reactive Streams type or a subtype of CompletionStage", element); + if (!isValid) { + context.fail("Method must return void, a Reactive Streams type or a subtype of CompletionStage", element); + } } } }