Package: org.gmetrics.util

## [Groovy] Class AstUtil

- org.gmetrics.util.AstUtil

- Contains static utility methods related to Groovy AST.

  This is an internal class and its API is subject to change.
  Authors:
    Chris Mair

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `static org.codehaus.groovy.ast.AnnotationNode` | `getAnnotation(org.codehaus.groovy.ast.AnnotatedNode node, String name)` Return the AnnotationNode for the named annotation, or else null.
    `` | `static List` | `getMethodArguments(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall)` Return the List of Arguments for the specified MethodCallExpression.
    `` | `static List` | `getVariableExpressions(org.codehaus.groovy.ast.expr.DeclarationExpression declarationExpression)` Return the List of VariableExpression objects referenced by the specified DeclarationExpression.
    `` | `static boolean` | `isBlock(org.codehaus.groovy.ast.stmt.Statement statement)` Return true if the Statement is a block
    `` | `static boolean` | `isClosureField(org.codehaus.groovy.ast.FieldNode fieldNode)` Return true only if the specified FieldNode has an initial expression that is a Closure
    `` | `static boolean` | `isEmptyBlock(org.codehaus.groovy.ast.stmt.Statement statement)` Return true if the Statement is a block and it is empty (contains no "meaningful" statements).
    `` | `static boolean` | `isEmptyMethod(org.codehaus.groovy.ast.MethodNode methodNode)`
    `` | `static boolean` | `isFinalVariable(org.codehaus.groovy.ast.expr.DeclarationExpression declarationExpression, SourceCode sourceCode)` Return true if the DeclarationExpression represents a 'final' variable declaration.
    `` | `static boolean` | `isFromGeneratedSourceCode(org.codehaus.groovy.ast.ASTNode node)` @return true if the ASTNode was generated (synthetic) rather than from the "real" input source code.
    `` | `static boolean` | `isMethodCall(org.codehaus.groovy.ast.stmt.Statement stmt, String methodObject, String methodName, int numArguments)` Return true only if the Statement represents a method call for the specified method object (receiver), method name, and with the specified number of arguments.
    `` | `static boolean` | `isMethodCall(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodObject, String methodName, int numArguments)` Return true only if the MethodCallExpression represents a method call for the specified method object (receiver), method name, and with the specified number of arguments.
    `` | `static boolean` | `isMethodCall(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodObject, String methodName)` Return true only if the MethodCallExpression represents a method call for the specified method object (receiver) and method name.
    `` | `static boolean` | `isMethodNamed(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodName)` Return true only if the MethodCallExpression represents a method call for the specified method name

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Method Detail

    - #### static org.codehaus.groovy.ast.AnnotationNode getAnnotation(org.codehaus.groovy.ast.AnnotatedNode node, String name)

      Return the AnnotationNode for the named annotation, or else null. Supports Groovy 1.5 and Groovy 1.6.

      Parameters:
        `node` - - the AnnotatedNode
        `name` - - the name of the annotation
      Returns:
        the AnnotationNode or else null

    - #### static List getMethodArguments(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall)

      Return the List of Arguments for the specified MethodCallExpression. The returned List contains either ConstantExpression or MapEntryExpression objects.

      Parameters:
        `methodCall` - - the AST MethodCallExpression
      Returns:
        the List of argument objects

    - #### static List getVariableExpressions(org.codehaus.groovy.ast.expr.DeclarationExpression declarationExpression)

      Return the List of VariableExpression objects referenced by the specified DeclarationExpression.

      Parameters:
        `declarationExpression` - - the DeclarationExpression
      Returns:
        the List of VariableExpression objects

    - #### static boolean isBlock(org.codehaus.groovy.ast.stmt.Statement statement)

      Return true if the Statement is a block

      Parameters:
        `statement` - - the Statement to check
      Returns:
        true if the Statement is a block

    - #### static boolean isClosureField(org.codehaus.groovy.ast.FieldNode fieldNode)

      Return true only if the specified FieldNode has an initial expression that is a Closure

      Parameters:
        `fieldNode` - - the FieldNode
      Returns:
        true if the field is a Closure field; otherwise return false

    - #### static boolean isEmptyBlock(org.codehaus.groovy.ast.stmt.Statement statement)

      Return true if the Statement is a block and it is empty (contains no "meaningful" statements). This implementation also addresses some "weirdness" around some statement types (specifically finally) where the BlockStatement answered false to isEmpty() even if it was.

      Parameters:
        `statement` - - the Statement to check
      Returns:
        true if the BlockStatement is empty

    - #### static boolean isEmptyMethod(org.codehaus.groovy.ast.MethodNode methodNode)

    - #### static boolean isFinalVariable(org.codehaus.groovy.ast.expr.DeclarationExpression declarationExpression, SourceCode sourceCode)

      Return true if the DeclarationExpression represents a 'final' variable declaration. NOTE: THIS IS A WORKAROUND. There does not seem to be an easy way to determine whether the 'final' modifier has been specified for a variable declaration. Return true if the 'final' is present before the variable name.

    - #### static boolean isFromGeneratedSourceCode(org.codehaus.groovy.ast.ASTNode node)

      Returns:
        true if the ASTNode was generated (synthetic) rather than from the "real" input source code.

    - #### static boolean isMethodCall(org.codehaus.groovy.ast.stmt.Statement stmt, String methodObject, String methodName, int numArguments)

      Return true only if the Statement represents a method call for the specified method object (receiver), method name, and with the specified number of arguments.

      Parameters:
        `stmt` - - the AST Statement
        `methodObject` - - the name of the method object (receiver)
        `methodName` - - the name of the method being called
        `numArguments` - - the number of arguments passed into the method
      Returns:
        true only if the Statement is a method call matching the specified criteria

    - #### static boolean isMethodCall(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodObject, String methodName, int numArguments)

      Return true only if the MethodCallExpression represents a method call for the specified method object (receiver), method name, and with the specified number of arguments.

      Parameters:
        `methodCall` - - the AST MethodCallExpression
        `methodObject` - - the name of the method object (receiver)
        `methodName` - - the name of the method being called
        `numArguments` - - the number of arguments passed into the method
      Returns:
        true only if the method call matches the specified criteria

    - #### static boolean isMethodCall(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodObject, String methodName)

      Return true only if the MethodCallExpression represents a method call for the specified method object (receiver) and method name.

      Parameters:
        `methodCall` - - the AST MethodCallExpression
        `methodObject` - - the name of the method object (receiver)
        `methodName` - - the name of the method being called
      Returns:
        true only if the method call matches the specified criteria

    - #### static boolean isMethodNamed(org.codehaus.groovy.ast.expr.MethodCallExpression methodCall, String methodName)

      Return true only if the MethodCallExpression represents a method call for the specified method name

      Parameters:
        `methodCall` - - the AST MethodCallExpression
        `methodName` - - the expected name of the method being called
      Returns:
        true only if the method call name matches