Class AnnotationUtility


  • public final class AnnotationUtility
    extends java.lang.Object
    Contains utility methods designed to work with annotations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String THE_AST_IS_NULL
      Common message.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private AnnotationUtility()
      Private utility constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsAnnotation​(DetailAST ast)
      Checks to see if the AST is annotated with any annotation.
      static boolean containsAnnotation​(DetailAST ast, java.lang.String annotation)
      Checks to see if the AST is annotated with the passed in annotation.
      static DetailAST getAnnotation​(DetailAST ast, java.lang.String annotation)
      Checks to see if the AST is annotated with the passed in annotation and return the AST representing that annotation.
      static DetailAST getAnnotationHolder​(DetailAST ast)
      Gets the AST that holds a series of annotations for the potentially annotated AST.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • THE_AST_IS_NULL

        private static final java.lang.String THE_AST_IS_NULL
        Common message.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AnnotationUtility

        private AnnotationUtility()
        Private utility constructor.
        Throws:
        java.lang.UnsupportedOperationException - if called
    • Method Detail

      • containsAnnotation

        public static boolean containsAnnotation​(DetailAST ast,
                                                 java.lang.String annotation)
        Checks to see if the AST is annotated with the passed in annotation.

        This method will not look for imports or package statements to detect the passed in annotation.

        To check if an AST contains a passed in annotation taking into account fully-qualified names (ex: java.lang.Override, Override) this method will need to be called twice. Once for each name given.

        Parameters:
        ast - the current node
        annotation - the annotation name to check for
        Returns:
        true if contains the annotation
      • containsAnnotation

        public static boolean containsAnnotation​(DetailAST ast)
        Checks to see if the AST is annotated with any annotation.
        Parameters:
        ast - the current node
        Returns:
        true if contains an annotation
      • getAnnotationHolder

        public static DetailAST getAnnotationHolder​(DetailAST ast)
        Gets the AST that holds a series of annotations for the potentially annotated AST. Returns null the passed in AST is not have an Annotation Holder.
        Parameters:
        ast - the current node
        Returns:
        the Annotation Holder
      • getAnnotation

        public static DetailAST getAnnotation​(DetailAST ast,
                                              java.lang.String annotation)
        Checks to see if the AST is annotated with the passed in annotation and return the AST representing that annotation.

        This method will not look for imports or package statements to detect the passed in annotation.

        To check if an AST contains a passed in annotation taking into account fully-qualified names (ex: java.lang.Override, Override) this method will need to be called twice. Once for each name given.

        Parameters:
        ast - the current node
        annotation - the annotation name to check for
        Returns:
        the AST representing that annotation