private static <A extends Annotation> A findAnnotation(
            AnnotatedElement element,
            Class<A> annotationType,
            boolean inherited,
            Set<Annotation> visited
    ) {
        if (element == null || annotationType == null) {
            return null;
        }

        A annotation = element.getDeclaredAnnotation(annotationType);
        if (annotation != null) {
            return annotation;
        }

        Annotation[] declaredAnnotations = element.getDeclaredAnnotations();
        A directMetaAnnotation = findMetaAnnotation(annotationType, declaredAnnotations, inherited, visited);
        if (directMetaAnnotation != null) {
            return directMetaAnnotation;
        }

        if (element instanceof Class) {
            Class<?> clazz = (Class<?>) element;

            for (Class<?> ifc : clazz.getInterfaces()) {
                if (ifc != Annotation.class) {
                    A annotationOnInterface = findAnnotation(ifc, annotationType, inherited, visited);
                    if (annotationOnInterface != null) {
                        return annotationOnInterface;
                    }
                }
            }

            if (inherited) {
                Class<?> superclass = clazz.getSuperclass();
                if (superclass != null && superclass != Object.class) {
                    A annotationOnSuperclass = findAnnotation(superclass, annotationType, true, visited);
                    if (annotationOnSuperclass != null) {
                        return annotationOnSuperclass;
                    }
                }
            }
        }

        return findMetaAnnotation(annotationType, getAnnotations(element), inherited, visited);
    }
Find the first annotation of {@code annotationType} that is either
<em>directly present</em>, <em>meta-present</em>, or <em>indirectly
present</em> on the supplied {@code element}.

<p>If the element is a class and the annotation is neither <em>directly
present</em> nor <em>meta-present</em> on the class, this method will additionally search on
interfaces implemented by the class before finding an annotation that is <em>indirectly
present</em> on the class.

@param element the element on which to search for the annotation
@param annotationType the annotation type of need to search
@param inherited whether has {@link Inherited}
@param visited this annotation whether visited
@param <A> the annotation type
@return the searched annotation
core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java