public static Optional<AnnotationMirror> getAnnotationMirror(
      Element element, TypeElement annotation) {
    for (AnnotationMirror elementAnnotation : element.getAnnotationMirrors()) {
      if (elementAnnotation.getAnnotationType().asElement().equals(annotation)) {
        return Optional.of(elementAnnotation);
      }
    }
    return Optional.absent();
  }
Returns an {@link AnnotationMirror} for the annotation of type {@code annotation} 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