Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move Async validation to processor module #9634

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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