Skip to content

Commit

Permalink
move Async validation to processor module (#9634)
Browse files Browse the repository at this point in the history
* move Async validation to processor module

* fix circular issue
  • Loading branch information
graemerocher authored Jul 28, 2023
1 parent 1f345cb commit f478a9a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
1 change: 0 additions & 1 deletion context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies {
api project(':aop')

compileOnly project(':core-reactive')
compileOnly project(':core-processor')
compileOnly libs.log4j
compileOnly libs.logback.classic

Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions core-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

dependencies {

api project(":inject")
api project(":aop")
api libs.asm.tree
Expand All @@ -11,6 +12,7 @@ dependencies {
exclude group:'org.javassist', module:'javassist'
exclude group:'com.google.guava', module:'guava'
}
implementation project(":core-reactive")

compileOnly libs.managed.kotlin.stdlib.jdk8
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Object, Async> {
public final class AsyncTypeElementVisitor implements TypeElementVisitor<Object, Object> {

private static final String ANN = "io.micronaut.scheduling.annotation.Async";

@Override
public Set<String> getSupportedAnnotationNames() {
return Set.of(ANN);
}

@NonNull
@Override
Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
* @author graemerocher
* @since 1.0
*/
package io.micronaut.scheduling.async.validation;
package io.micronaut.validation.visitor.async;
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f478a9a

Please sign in to comment.