in core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/aot/ReflectionHelper.java [76:124]
public static <A extends Annotation, T> void applyIfMatch(Class<?> c, Class<A> a, Function<A, T> getter,
Consumer<T> onMatch) {
Set<ElementType> targets = null;
if (a.isAnnotationPresent(Target.class)) {
targets = Collections.newSetFromMap(new EnumMap<>(ElementType.class));
targets.addAll(Arrays.asList(a.getAnnotation(Target.class).value()));
}
if ((targets == null || targets.contains(ElementType.TYPE)) && c.isAnnotationPresent(a)) {
onMatch.accept(getter.apply(c.getAnnotation(a)));
}
boolean checkConstructors = targets == null || targets.contains(ElementType.CONSTRUCTOR);
boolean checkParameters = targets == null || targets.contains(ElementType.PARAMETER);
if (checkConstructors || checkParameters) {
for (Constructor<?> constructor : c.getDeclaredConstructors()) {
if (checkConstructors && constructor.isAnnotationPresent(a)) {
onMatch.accept(getter.apply(constructor.getAnnotation(a)));
}
if (checkParameters) {
for (Parameter parameter : constructor.getParameters()) {
if (parameter.isAnnotationPresent(a)) {
onMatch.accept(getter.apply(parameter.getAnnotation(a)));
}
}
}
}
}
if (targets == null || targets.contains(ElementType.FIELD)) {
ReflectionUtils.doWithFields(c,
field -> onMatch.accept(getter.apply(field.getAnnotation(a))), field -> field.isAnnotationPresent(a));
}
boolean checkMethods = targets == null || targets.contains(ElementType.METHOD);
if (checkMethods || checkParameters) {
ReflectionUtils.doWithMethods(
c,
method -> {
if (checkMethods && method.isAnnotationPresent(a)) {
onMatch.accept(getter.apply(method.getAnnotation(a)));
}
if (checkParameters) {
for (Parameter parameter : method.getParameters()) {
if (parameter.isAnnotationPresent(a)) {
onMatch.accept(getter.apply(parameter.getAnnotation(a)));
}
}
}
}
);
}
}