Groovy Documentation

org.gmetrics.util
Class AstUtil

java.lang.Object
  org.gmetrics.util.AstUtil

class AstUtil

Contains static utility methods related to Groovy AST.

This is an internal class and its API is subject to change.

Authors:
Chris Mair
Version:
\$Revision: 24 \$ - \$Date: 2009-12-10 21:17:05 -0500 (Thu, 10 Dec 2009) \$


Constructor Summary
private AstUtil()

Private constructor.

 
Method Summary
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 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 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

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

AstUtil

private AstUtil()
Private constructor. All methods are static.


 
Method Detail

getAnnotation

public 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


getMethodArguments

public 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


getVariableExpressions

public 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


isBlock

public 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


isEmptyBlock

public 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


isFinalVariable

public 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.


isFromGeneratedSourceCode

public 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.


isMethodCall

public 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


isMethodCall

public 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


isMethodCall

public 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


isMethodNamed

public 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


 

Groovy Documentation