Class AstUtils


  • public abstract class AstUtils
    extends java.lang.Object
    General purpose AST utilities.
    Since:
    1.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      AstUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.codehaus.groovy.ast.expr.ClosureExpression getClosure​(org.codehaus.groovy.ast.stmt.BlockStatement block, java.lang.String name)  
      static org.codehaus.groovy.ast.expr.ClosureExpression getClosure​(org.codehaus.groovy.ast.stmt.BlockStatement block, java.lang.String name, boolean remove)
      Extract a top-level name closure from inside this block if there is one, optionally removing it from the block at the same time.
      static boolean hasAtLeastOneAnnotation​(org.codehaus.groovy.ast.AnnotatedNode node, java.lang.String... annotations)
      Determine if an AnnotatedNode has one or more of the specified annotations.
      static boolean hasAtLeastOneAnnotation​(org.codehaus.groovy.ast.ClassNode node, java.lang.String... annotations)
      Determine if a ClassNode has one or more of the specified annotations on the class or any of its methods.
      static boolean hasAtLeastOneFieldOrMethod​(org.codehaus.groovy.ast.ClassNode node, java.lang.String... types)
      Determine if a ClassNode has one or more fields of the specified types or method returning one or more of the specified types.
      static boolean hasAtLeastOneInterface​(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String... types)  
      static boolean subclasses​(org.codehaus.groovy.ast.ClassNode node, java.lang.String... types)
      Determine if a ClassNode subclasses any of the specified types N.B.
      • Methods inherited from class java.lang.Object

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

      • AstUtils

        public AstUtils()
    • Method Detail

      • hasAtLeastOneAnnotation

        public static boolean hasAtLeastOneAnnotation​(org.codehaus.groovy.ast.ClassNode node,
                                                      java.lang.String... annotations)
        Determine if a ClassNode has one or more of the specified annotations on the class or any of its methods. N.B. the type names are not normally fully qualified.
        Parameters:
        node - the class to examine
        annotations - the annotations to look for
        Returns:
        true if at least one of the annotations is found, otherwise false
      • hasAtLeastOneAnnotation

        public static boolean hasAtLeastOneAnnotation​(org.codehaus.groovy.ast.AnnotatedNode node,
                                                      java.lang.String... annotations)
        Determine if an AnnotatedNode has one or more of the specified annotations. N.B. the annotation type names are not normally fully qualified.
        Parameters:
        node - the node to examine
        annotations - the annotations to look for
        Returns:
        true if at least one of the annotations is found, otherwise false
      • hasAtLeastOneFieldOrMethod

        public static boolean hasAtLeastOneFieldOrMethod​(org.codehaus.groovy.ast.ClassNode node,
                                                         java.lang.String... types)
        Determine if a ClassNode has one or more fields of the specified types or method returning one or more of the specified types. N.B. the type names are not normally fully qualified.
        Parameters:
        node - the class to examine
        types - the types to look for
        Returns:
        true if at least one of the types is found, otherwise false
      • subclasses

        public static boolean subclasses​(org.codehaus.groovy.ast.ClassNode node,
                                         java.lang.String... types)
        Determine if a ClassNode subclasses any of the specified types N.B. the type names are not normally fully qualified.
        Parameters:
        node - the class to examine
        types - the types that may have been sub-classed
        Returns:
        true if the class subclasses any of the specified types, otherwise false
      • hasAtLeastOneInterface

        public static boolean hasAtLeastOneInterface​(org.codehaus.groovy.ast.ClassNode classNode,
                                                     java.lang.String... types)
      • getClosure

        public static org.codehaus.groovy.ast.expr.ClosureExpression getClosure​(org.codehaus.groovy.ast.stmt.BlockStatement block,
                                                                                java.lang.String name,
                                                                                boolean remove)
        Extract a top-level name closure from inside this block if there is one, optionally removing it from the block at the same time.
        Parameters:
        block - a block statement (class definition)
        name - the name to look for
        remove - whether the extracted closure should be removed
        Returns:
        a beans Closure if one can be found, null otherwise
      • getClosure

        public static org.codehaus.groovy.ast.expr.ClosureExpression getClosure​(org.codehaus.groovy.ast.stmt.BlockStatement block,
                                                                                java.lang.String name)