Search in sources :

Example 1 with ConstructorInterceptor

use of io.micronaut.aop.ConstructorInterceptor in project micronaut-core by micronaut-projects.

the class DefaultInterceptorRegistry method resolveInterceptors.

@Override
@NonNull
public <T> Interceptor<T, ?>[] resolveInterceptors(@NonNull Executable<T, ?> method, @NonNull Collection<BeanRegistration<Interceptor<T, ?>>> interceptors, @NonNull InterceptorKind interceptorKind) {
    final AnnotationMetadata annotationMetadata = method.getAnnotationMetadata();
    if (interceptors.isEmpty()) {
        return resolveToNone((ExecutableMethod<?, ?>) method, interceptorKind, annotationMetadata);
    } else {
        instrumentAnnotationMetadata(beanContext, method);
        final Collection<AnnotationValue<?>> applicableBindings = AbstractInterceptorChain.resolveInterceptorValues(annotationMetadata, interceptorKind);
        if (applicableBindings.isEmpty()) {
            return resolveToNone((ExecutableMethod<?, ?>) method, interceptorKind, annotationMetadata);
        } else {
            @SuppressWarnings({ "unchecked", "rawtypes" }) final Interceptor[] resolvedInterceptors = (Interceptor[]) interceptorStream(method.getDeclaringType(), (Collection) interceptors, interceptorKind, applicableBindings).filter(bean -> (bean instanceof MethodInterceptor) || !(bean instanceof ConstructorInterceptor)).toArray(Interceptor[]::new);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Resolved {} {} interceptors out of a possible {} for method: {} - {}", resolvedInterceptors.length, interceptorKind, interceptors.size(), method.getDeclaringType(), method instanceof Described ? ((Described) method).getDescription(true) : method.toString());
                for (int i = 0; i < resolvedInterceptors.length; i++) {
                    Interceptor<?, ?> resolvedInterceptor = resolvedInterceptors[i];
                    LOG.trace("Interceptor {} - {}", i, resolvedInterceptor);
                }
            }
            // noinspection unchecked
            return resolvedInterceptors;
        }
    }
}
Also used : Described(io.micronaut.core.naming.Described) MethodInterceptor(io.micronaut.aop.MethodInterceptor) ConstructorInterceptor(io.micronaut.aop.ConstructorInterceptor) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Collection(java.util.Collection) MethodInterceptor(io.micronaut.aop.MethodInterceptor) ConstructorInterceptor(io.micronaut.aop.ConstructorInterceptor) Interceptor(io.micronaut.aop.Interceptor) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) NonNull(io.micronaut.core.annotation.NonNull)

Aggregations

ConstructorInterceptor (io.micronaut.aop.ConstructorInterceptor)1 Interceptor (io.micronaut.aop.Interceptor)1 MethodInterceptor (io.micronaut.aop.MethodInterceptor)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 NonNull (io.micronaut.core.annotation.NonNull)1 Described (io.micronaut.core.naming.Described)1 Collection (java.util.Collection)1