public static AnnotationNode getAnnotation(ASTNode node, Class<?> annotationType) {
    if (!(node instanceof AnnotatedNode)) return null;

    AnnotatedNode annotated = (AnnotatedNode)node;
    @SuppressWarnings("unchecked")
    List<AnnotationNode> annotations = annotated.getAnnotations();
    for (AnnotationNode a : annotations)
      if (a.getClassNode().getName().equals(annotationType.getName())) return a;
    return null;
  }
Tells whether the given node has an annotation of the given type.

@param node an AST node
@param annotationType an annotation type
@return <tt>true</tt> iff the given node has an annotation of the given type
spock-core/src/main/java/org/spockframework/compiler/AstUtil.java