use of io.micronaut.aop.InterceptorBinding in project micronaut-core by micronaut-projects.
the class AbstractInterceptorChain method resolveInterceptorValues.
/**
* Resolve interceptor binding for the given annotation metadata and kind.
* @param annotationMetadata The annotation metadata
* @param kind The kind
* @return The binding
* @since 3.3.0
*/
@NonNull
protected static Collection<AnnotationValue<?>> resolveInterceptorValues(@NonNull AnnotationMetadata annotationMetadata, @NonNull InterceptorKind kind) {
if (annotationMetadata instanceof AnnotationMetadataHierarchy) {
final List<AnnotationValue<InterceptorBinding>> declaredValues = annotationMetadata.getDeclaredMetadata().getAnnotationValuesByType(InterceptorBinding.class);
final List<AnnotationValue<InterceptorBinding>> parentValues = ((AnnotationMetadataHierarchy) annotationMetadata).getRootMetadata().getAnnotationValuesByType(InterceptorBinding.class);
if (CollectionUtils.isNotEmpty(declaredValues) || CollectionUtils.isNotEmpty(parentValues)) {
Set<AnnotationValue<?>> resolved = new HashSet<>(declaredValues.size() + parentValues.size());
Set<String> declared = new HashSet<>(declaredValues.size());
for (AnnotationValue<InterceptorBinding> declaredValue : declaredValues) {
final String annotationName = declaredValue.stringValue().orElse(null);
if (annotationName != null) {
final InterceptorKind specifiedkind = declaredValue.enumValue("kind", InterceptorKind.class).orElse(null);
if (specifiedkind == null || specifiedkind.equals(kind)) {
if (!annotationMetadata.isRepeatableAnnotation(annotationName)) {
declared.add(annotationName);
}
resolved.add(declaredValue);
}
}
}
for (AnnotationValue<InterceptorBinding> parentValue : parentValues) {
final String annotationName = parentValue.stringValue().orElse(null);
if (annotationName != null && !declared.contains(annotationName)) {
final InterceptorKind specifiedkind = parentValue.enumValue("kind", InterceptorKind.class).orElse(null);
if (specifiedkind == null || specifiedkind.equals(kind)) {
resolved.add(parentValue);
}
}
}
return resolved;
} else {
return Collections.emptyList();
}
} else {
List<AnnotationValue<InterceptorBinding>> bindings = annotationMetadata.getAnnotationValuesByType(InterceptorBinding.class);
if (CollectionUtils.isNotEmpty(bindings)) {
return bindings.stream().filter(av -> {
if (!av.stringValue().isPresent()) {
return false;
}
final InterceptorKind specifiedkind = av.enumValue("kind", InterceptorKind.class).orElse(null);
return specifiedkind == null || specifiedkind.equals(kind);
}).collect(Collectors.toSet());
} else {
return Collections.emptyList();
}
}
}
Aggregations