use of io.micronaut.aop.Around in project helidon by oracle.
the class MicronautCdiExtension method processTypes.
/**
* Construct a list of Micronaut interceptors to execute on each CDI method.
* In case a Micronaut bean definition is available for the CDI bean (which should be for application, as
* the CDI annotation processor should be used, and it adds CDI beans as Micronaut beans), the information
* is combined from Micronaut and CDI bean definitions.
*
* @param event CDI event
*/
@SuppressWarnings("unchecked")
void processTypes(@Priority(PLATFORM_AFTER) @Observes ProcessAnnotatedType<?> event) {
Set<Class<?>> classInterceptors = new HashSet<>();
Map<Method, Set<Class<?>>> allMethodInterceptors = new HashMap<>();
List<MicronautBean> miBeans = unprocessedBeans.remove(event.getAnnotatedType().getJavaClass());
if (miBeans != null && miBeans.size() > 0) {
BeanDefinitionReference<?> miBean = findMicronautBeanDefinition(miBeans);
// add all interceptors that are seen based on Micronaut
findMicronautInterceptors(classInterceptors, allMethodInterceptors, miBean);
}
// find all annotations that have meta annotation Around and collect their Type list to add as interceptors
addMicronautInterceptors(classInterceptors, event.getAnnotatedType().getAnnotations());
// for each method, find the same (Around, collect Type), and add the interceptor binding for Micronaut interceptors
// CDI interceptors will be automatic
event.configureAnnotatedType().methods().forEach(method -> {
Method javaMethod = method.getAnnotated().getJavaMember();
Set<Class<?>> methodInterceptors = allMethodInterceptors.computeIfAbsent(javaMethod, it -> new HashSet<>());
methodInterceptors.addAll(classInterceptors);
addMicronautInterceptors(methodInterceptors, method.getAnnotated().getAnnotations());
if (!methodInterceptors.isEmpty()) {
// now I have a set of micronaut interceptors that are needed for this method
method.add(MicronautIntercepted.Literal.INSTANCE);
Set<Class<? extends MethodInterceptor<?, ?>>> interceptors = new HashSet<>();
methodInterceptors.forEach(it -> interceptors.add((Class<? extends MethodInterceptor<?, ?>>) it));
methods.computeIfAbsent(javaMethod, theMethod -> MethodInterceptorMetadata.create(method.getAnnotated(), executableMethodCache.get(theMethod))).addInterceptors(interceptors);
}
});
}
Aggregations