public static Optional<AnnotationMirror> getAnnotationMirror(
      Element element, String annotationName) {
    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
      TypeElement annotationTypeElement = asType(annotationMirror.getAnnotationType().asElement());
      if (annotationTypeElement.getQualifiedName().contentEquals(annotationName)) {
        return Optional.of(annotationMirror);
      }
    }
    return Optional.absent();
  }
Returns an {@link AnnotationMirror} for the annotation whose type's canonical name is 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.
common/src/main/java/com/google/auto/common/MoreElements.java