Class AstUtil


  • public abstract class AstUtil
    extends java.lang.Object
    Utility methods for AST processing.
    Author:
    Peter Niederwieser
    • Constructor Summary

      Constructors 
      Constructor Description
      AstUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copySourcePosition​(org.codehaus.groovy.ast.ASTNode from, org.codehaus.groovy.ast.ASTNode to)  
      static org.codehaus.groovy.ast.expr.MethodCallExpression createDirectMethodCall​(org.codehaus.groovy.ast.expr.Expression target, org.codehaus.groovy.ast.MethodNode method, org.codehaus.groovy.ast.expr.Expression arguments)  
      static void deleteMethod​(org.codehaus.groovy.ast.ClassNode clazz, org.codehaus.groovy.ast.MethodNode method)  
      static org.codehaus.groovy.ast.AnnotationNode getAnnotation​(org.codehaus.groovy.ast.ASTNode node, java.lang.Class<?> annotationType)  
      static java.util.List<org.codehaus.groovy.ast.expr.Expression> getArgumentList​(org.codehaus.groovy.ast.expr.Expression invocation)  
      static org.codehaus.groovy.ast.expr.Expression getArguments​(org.codehaus.groovy.ast.expr.Expression invocation)  
      static org.codehaus.groovy.ast.expr.Expression getAssertionMessage​(org.codehaus.groovy.ast.stmt.AssertStatement stat)  
      static <T extends org.codehaus.groovy.ast.expr.Expression>
      T
      getExpression​(org.codehaus.groovy.ast.stmt.Statement stat, java.lang.Class<T> type)  
      static org.codehaus.groovy.ast.expr.Expression getImplicitParameterRef​(org.codehaus.groovy.ast.expr.ClosureExpression expr)  
      static org.codehaus.groovy.ast.expr.Expression getInvocationTarget​(org.codehaus.groovy.ast.expr.Expression expr)  
      static java.util.List<org.codehaus.groovy.ast.stmt.Statement> getStatements​(org.codehaus.groovy.ast.expr.ClosureExpression closure)  
      static java.util.List<org.codehaus.groovy.ast.stmt.Statement> getStatements​(org.codehaus.groovy.ast.MethodNode method)
      Returns a list of statements of the given method.
      static org.codehaus.groovy.ast.expr.Expression getVariableName​(org.codehaus.groovy.ast.expr.BinaryExpression assignment)  
      static org.codehaus.groovy.ast.expr.Expression getVariableType​(org.codehaus.groovy.ast.expr.BinaryExpression assignment)  
      static int getVisibility​(org.codehaus.groovy.ast.FieldNode field)  
      static boolean hasAnnotation​(org.codehaus.groovy.ast.ASTNode node, java.lang.Class<?> annotationType)
      Tells whether the given node has an annotation of the given type.
      static boolean hasImplicitParameter​(org.codehaus.groovy.ast.expr.ClosureExpression expr)  
      static boolean hasPlausibleSourcePosition​(org.codehaus.groovy.ast.ASTNode node)
      Tells if the source position for the given AST node is plausible.
      static boolean isInvocationWithImplicitThis​(org.codehaus.groovy.ast.expr.Expression invocation)  
      static boolean isJavaIdentifier​(java.lang.String id)  
      static boolean isJointCompiled​(org.codehaus.groovy.ast.ClassNode clazz)  
      static boolean isSuperExpression​(org.codehaus.groovy.ast.expr.Expression expr)  
      static boolean isSynthetic​(org.codehaus.groovy.ast.MethodNode method)  
      static boolean isThisExpression​(org.codehaus.groovy.ast.expr.Expression expr)  
      static boolean isThisOrSuperExpression​(org.codehaus.groovy.ast.expr.Expression expr)  
      static boolean isWildcardRef​(org.codehaus.groovy.ast.expr.Expression expr)  
      static void setVisibility​(org.codehaus.groovy.ast.FieldNode field, int visibility)  
      static void setVisibility​(org.codehaus.groovy.ast.MethodNode method, int visibility)  
      static org.codehaus.groovy.ast.expr.Expression toArgumentArray​(java.util.List<org.codehaus.groovy.ast.expr.Expression> argList, IRewriteResources resources)
      Turns an argument list obtained from AstUtil.getArguments() into an Object[] array suitable to be passed to InvokerHelper or SpockRuntime.
      • Methods inherited from class java.lang.Object

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

      • AstUtil

        public AstUtil()
    • Method Detail

      • hasAnnotation

        public static boolean hasAnnotation​(org.codehaus.groovy.ast.ASTNode node,
                                            java.lang.Class<?> annotationType)
        Tells whether the given node has an annotation of the given type.
        Parameters:
        node - an AST node
        annotationType - an annotation type
        Returns:
        true iff the given node has an annotation of the given type
      • getAnnotation

        public static org.codehaus.groovy.ast.AnnotationNode getAnnotation​(org.codehaus.groovy.ast.ASTNode node,
                                                                           java.lang.Class<?> annotationType)
      • getStatements

        public static java.util.List<org.codehaus.groovy.ast.stmt.Statement> getStatements​(org.codehaus.groovy.ast.MethodNode method)
        Returns a list of statements of the given method. Modifications to the returned list will affect the method's statements.
        Parameters:
        method - a method (node)
        Returns:
        a list of statements of the given method
      • getStatements

        public static java.util.List<org.codehaus.groovy.ast.stmt.Statement> getStatements​(org.codehaus.groovy.ast.expr.ClosureExpression closure)
      • isInvocationWithImplicitThis

        public static boolean isInvocationWithImplicitThis​(org.codehaus.groovy.ast.expr.Expression invocation)
      • hasImplicitParameter

        public static boolean hasImplicitParameter​(org.codehaus.groovy.ast.expr.ClosureExpression expr)
      • getImplicitParameterRef

        public static org.codehaus.groovy.ast.expr.Expression getImplicitParameterRef​(org.codehaus.groovy.ast.expr.ClosureExpression expr)
      • getInvocationTarget

        public static org.codehaus.groovy.ast.expr.Expression getInvocationTarget​(org.codehaus.groovy.ast.expr.Expression expr)
      • isWildcardRef

        public static boolean isWildcardRef​(org.codehaus.groovy.ast.expr.Expression expr)
      • isJavaIdentifier

        public static boolean isJavaIdentifier​(java.lang.String id)
      • getExpression

        public static <T extends org.codehaus.groovy.ast.expr.Expression> T getExpression​(org.codehaus.groovy.ast.stmt.Statement stat,
                                                                                          java.lang.Class<T> type)
      • isSynthetic

        public static boolean isSynthetic​(org.codehaus.groovy.ast.MethodNode method)
      • hasPlausibleSourcePosition

        public static boolean hasPlausibleSourcePosition​(org.codehaus.groovy.ast.ASTNode node)
        Tells if the source position for the given AST node is plausible. Does not imply that the source position is correct.
        Parameters:
        node - an AST node
        Returns:
        true iff the AST node has a plausible source position
      • getArguments

        public static org.codehaus.groovy.ast.expr.Expression getArguments​(org.codehaus.groovy.ast.expr.Expression invocation)
      • getArgumentList

        public static java.util.List<org.codehaus.groovy.ast.expr.Expression> getArgumentList​(org.codehaus.groovy.ast.expr.Expression invocation)
      • toArgumentArray

        public static org.codehaus.groovy.ast.expr.Expression toArgumentArray​(java.util.List<org.codehaus.groovy.ast.expr.Expression> argList,
                                                                              IRewriteResources resources)
        Turns an argument list obtained from AstUtil.getArguments() into an Object[] array suitable to be passed to InvokerHelper or SpockRuntime. The main challenge is to handle SpreadExpression's correctly.
      • copySourcePosition

        public static void copySourcePosition​(org.codehaus.groovy.ast.ASTNode from,
                                              org.codehaus.groovy.ast.ASTNode to)
      • getAssertionMessage

        public static org.codehaus.groovy.ast.expr.Expression getAssertionMessage​(org.codehaus.groovy.ast.stmt.AssertStatement stat)
      • isThisExpression

        public static boolean isThisExpression​(org.codehaus.groovy.ast.expr.Expression expr)
      • isSuperExpression

        public static boolean isSuperExpression​(org.codehaus.groovy.ast.expr.Expression expr)
      • isThisOrSuperExpression

        public static boolean isThisOrSuperExpression​(org.codehaus.groovy.ast.expr.Expression expr)
      • setVisibility

        public static void setVisibility​(org.codehaus.groovy.ast.MethodNode method,
                                         int visibility)
      • getVisibility

        public static int getVisibility​(org.codehaus.groovy.ast.FieldNode field)
      • setVisibility

        public static void setVisibility​(org.codehaus.groovy.ast.FieldNode field,
                                         int visibility)
      • isJointCompiled

        public static boolean isJointCompiled​(org.codehaus.groovy.ast.ClassNode clazz)
      • createDirectMethodCall

        public static org.codehaus.groovy.ast.expr.MethodCallExpression createDirectMethodCall​(org.codehaus.groovy.ast.expr.Expression target,
                                                                                               org.codehaus.groovy.ast.MethodNode method,
                                                                                               org.codehaus.groovy.ast.expr.Expression arguments)
      • deleteMethod

        public static void deleteMethod​(org.codehaus.groovy.ast.ClassNode clazz,
                                        org.codehaus.groovy.ast.MethodNode method)
      • getVariableName

        public static org.codehaus.groovy.ast.expr.Expression getVariableName​(org.codehaus.groovy.ast.expr.BinaryExpression assignment)
      • getVariableType

        public static org.codehaus.groovy.ast.expr.Expression getVariableType​(org.codehaus.groovy.ast.expr.BinaryExpression assignment)