code: public static <T extends Annotation> T[] getDirectOrIndirectAnnotationsByType(
          AnnotatedElement element, Class<T> annotationClass) {
      if (annotationClass == null) {
        throw new NullPointerException("annotationClass");
      }
  
      Annotation[] annotations = element.getDeclaredAnnotations();
  
      // Store a list of repeatable annotations that have been extracted from their container.
      ArrayList<T> unfoldedAnnotations = new ArrayList<T>();
  
      Class<? extends Annotation> repeatableAnnotationClass =
          getRepeatableAnnotationContainerClassFor(annotationClass);
  
      for (int i = 0; i < annotations.length; ++i) {
        if (annotationClass.isInstance(annotations[i])) {
          // Is it directly present?
          unfoldedAnnotations.add((T)annotations[i]);  // Safe, guarded by above check.
        } else if (repeatableAnnotationClass != null &&
            repeatableAnnotationClass.isInstance(annotations[i])) {
          // Is it repeatably (indirectly) present?
          insertAnnotationValues(annotations[i], annotationClass, unfoldedAnnotations);
        }
      }
  
      return unfoldedAnnotations.toArray((T[])Array.newInstance(annotationClass, 0));
    }
docs: Default implementation of {@link AnnotatedElement#getDeclaredAnnotationsByType}, and
  {@link AnnotatedElement#getAnnotationsByType} for elements that do not support annotation
  inheritance.
  
  @return Directly/indirectly present list of annotations of type {@code annotationClass} for
  {@code element}, or an empty array if none were found.