Class AnnotationUtils

java.lang.Object
org.apache.groovy.contracts.util.AnnotationUtils

public class AnnotationUtils extends Object

Helper methods for reading/getting AnnotationNode instances.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<org.codehaus.groovy.ast.AnnotationNode>
    getAnnotationNodeInHierarchyWithMetaAnnotation(org.codehaus.groovy.ast.ClassNode type, org.codehaus.groovy.ast.ClassNode anno)
    Gets the next AnnotationNode instance in the inheritance line which is annotated with the given Annotation class anno.
    static List<org.codehaus.groovy.ast.AnnotationNode>
    getAnnotationNodeInHierarchyWithMetaAnnotation(org.codehaus.groovy.ast.ClassNode type, org.codehaus.groovy.ast.MethodNode originMethodNode, org.codehaus.groovy.ast.ClassNode metaAnnotationClassNode)
    Checks whether there exists a MethodNode up the inheritance tree where exists an annotation which is annotated with metaAnnotationClassNode.
    static boolean
    hasAnnotationOfType(org.codehaus.groovy.ast.AnnotatedNode annotatedNode, String typeOrPackageName)
    Checks whether the given ClassNode is annotated with an annotations of the given package or full annotatedNode name.
    static List<org.codehaus.groovy.ast.AnnotationNode>
    hasMetaAnnotations(org.codehaus.groovy.ast.AnnotatedNode annotatedNode, String metaAnnotationClassName)
    Loads all annotation nodes of the given AnnotatedNode instance which are marked with the annotation metaAnnotationClassName.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AnnotationUtils

      public AnnotationUtils()
  • Method Details

    • hasAnnotationOfType

      public static boolean hasAnnotationOfType(org.codehaus.groovy.ast.AnnotatedNode annotatedNode, String typeOrPackageName)
      Checks whether the given ClassNode is annotated with an annotations of the given package or full annotatedNode name.
      Parameters:
      annotatedNode - the AnnotatedNode to search for the given annotation
      typeOrPackageName - can either be a part of the package or the complete annotation class name
      Returns:
      true if an annotation was found, false otherwise
    • getAnnotationNodeInHierarchyWithMetaAnnotation

      public static List<org.codehaus.groovy.ast.AnnotationNode> getAnnotationNodeInHierarchyWithMetaAnnotation(org.codehaus.groovy.ast.ClassNode type, org.codehaus.groovy.ast.ClassNode anno)
      Gets the next AnnotationNode instance in the inheritance line which is annotated with the given Annotation class anno.
      Parameters:
      type - the ClassNode to check for the annotation
      anno - the annotation to watch out for
      Returns:
      the next AnnotationNode in the inheritance line, or null
    • getAnnotationNodeInHierarchyWithMetaAnnotation

      public static List<org.codehaus.groovy.ast.AnnotationNode> getAnnotationNodeInHierarchyWithMetaAnnotation(org.codehaus.groovy.ast.ClassNode type, org.codehaus.groovy.ast.MethodNode originMethodNode, org.codehaus.groovy.ast.ClassNode metaAnnotationClassNode)

      Checks whether there exists a MethodNode up the inheritance tree where exists an annotation which is annotated with metaAnnotationClassNode.

      Parameters:
      type - the origin ClassNode
      originMethodNode - the origin MethodNode
      metaAnnotationClassNode - the ClassNode of the meta-annotation
      Returns:
      a list of AnnotationNode all annotated with metaAnnotationClassNode
    • hasMetaAnnotations

      public static List<org.codehaus.groovy.ast.AnnotationNode> hasMetaAnnotations(org.codehaus.groovy.ast.AnnotatedNode annotatedNode, String metaAnnotationClassName)
      Loads all annotation nodes of the given AnnotatedNode instance which are marked with the annotation metaAnnotationClassName.
      Parameters:
      annotatedNode - an AnnotatedNode from which the annotations are checked
      metaAnnotationClassName - the name of the meta annotation
      Returns:
      a list of AnnotationNode instances which implement the given metaAnnotationClass