code: public static Optional<AnnotationMirror> getAnnotationMirror(Element element,
        Class<? extends Annotation> annotationClass) {
      String annotationClassName = annotationClass.getCanonicalName();
      for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        TypeElement annotationTypeElement = asType(annotationMirror.getAnnotationType().asElement());
        if (annotationTypeElement.getQualifiedName().contentEquals(annotationClassName)) {
          return Optional.of(annotationMirror);
        }
      }
      return Optional.absent();
    }
docs: Returns an {@link AnnotationMirror} for the annotation of type {@code annotationClass} on
  {@code element}, or {@link Optional#absent()} if no such annotation exists. This method is a
  safer alternative to calling {@link Element#getAnnotation} as it avoids any interaction with
  annotation proxies.