Griffon 1.2.0

org.codehaus.griffon.ast
[Java] Class GriffonASTUtils

java.lang.Object
  org.codehaus.griffon.ast.GriffonASTUtils

public class GriffonASTUtils

Helper methods for working with Groovy AST trees.

Authors:
Graeme Rocher (Grails 0.3)


Field Summary
static Token AND

static Token ASSIGN

static Token CMP

static Token EQ

static Token INSTANCEOF

static Token NE

static ArgumentListExpression NO_ARGS

static ClassNode[] NO_EXCEPTIONS

static Parameter[] NO_PARAMS

static Token OR

static Expression SUPER

static Expression THIS

 
Constructor Summary
GriffonASTUtils()

 
Method Summary
static boolean addMethod(ClassNode classNode, MethodNode methodNode)

static boolean addMethod(ClassNode classNode, MethodNode methodNode, boolean replace)

static void addReadOnlyProperty(ClassNode classNode, String propertyName, ClassNode propertyClass, Object value)

static BinaryExpression and(Expression lhv, Expression rhv)

static ArgumentListExpression args(Expression... expressions)

static ArgumentListExpression args(List expressions)

static BinaryExpression assign(Expression lhv, Expression rhv)

static Statement assigns(Expression expression, Expression value)

static BlockStatement block(Statement... stms)

static MethodCallExpression call(Expression receiver, String methodName, ArgumentListExpression args)

static StaticMethodCallExpression call(ClassNode receiver, String methodName, ArgumentListExpression args)

static ClassExpression classx(ClassNode clazz)

static ClassExpression classx(Class clazz)

static BinaryExpression cmp(Expression lhv, Expression rhv)

static ConstantExpression constx(Object val)

static ConstructorCallExpression ctor(ClassNode type, Expression args)

static Statement decls(Expression lhv, Expression rhv)

static BinaryExpression eq(Expression lhv, Expression rhv)

static FieldExpression field(FieldNode fieldNode)

static FieldExpression field(ClassNode owner, String fieldName)

static String getFullName(ClassNode classNode)

Gets the full name of a ClassNode.

static ClassNode getFurthestParent(ClassNode classNode)

static boolean hasField(ClassNode classNode, String name, int modifiers, ClassNode type)

static boolean hasOrInheritsField(ClassNode classNode, String name, int modifiers, ClassNode type)

static boolean hasOrInheritsProperty(ClassNode classNode, String propertyName)

static boolean hasProperty(ClassNode classNode, String propertyName)

Returns whether a classNode has the specified property or not

static Statement ifs(Expression cond, Expression trueExpr)

static Statement ifs(Expression cond, Expression trueExpr, Expression falseExpr)

static Statement ifs_no_return(Expression cond, Expression trueExpr)

static Statement ifs_no_return(Expression cond, Expression trueExpr, Expression falseExpr)

static Statement ifs_no_return(Expression cond, Statement trueStmnt)

static Statement ifs_no_return(Expression cond, Statement trueStmnt, Statement falseStmnt)

static boolean implementsMethod(ClassNode classNode, MethodNode methodNode)

static boolean implementsOrInheritsMethod(ClassNode classNode, MethodNode methodNode)

static boolean implementsOrInheritsZeroArgMethod(ClassNode classNode, String methodName, List ignoreClasses)

static boolean implementsZeroArgMethod(ClassNode classNode, String methodName)

Tests whether the ClasNode implements the specified method name.

static void injectConstant(ClassNode classNode, String propertyName, Class propertyClass, Object value)

static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Object value)

static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Object value, boolean deep)

static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Expression initialExpression)

static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Expression initialExpression, boolean deep)

static void injectInterface(ClassNode classNode, ClassNode type)

static void injectInterface(ClassNode classNode, ClassNode type, boolean deep)

static void injectMethod(ClassNode classNode, MethodNode methodNode)

static void injectMethod(ClassNode classNode, MethodNode methodNode, boolean deep)

static void injectProperty(ClassNode classNode, String propertyName, Class propertyClass)

static void injectProperty(ClassNode classNode, String propertyName, Class propertyClass, Object value)

static void injectProperty(ClassNode classNode, String propertyName, int modifiers, Class propertyClass)

static void injectProperty(ClassNode classNode, String propertyName, int modifiers, Class propertyClass, Object value)

static void injectProperty(ClassNode classNode, String propertyName, ClassNode propertyClass)

static void injectProperty(ClassNode classNode, String propertyName, int modifiers, ClassNode propertyClass)

static void injectProperty(ClassNode classNode, String propertyName, int modifiers, ClassNode propertyClass, Object value)

static BinaryExpression iof(Expression lhv, Expression rhv)

static BinaryExpression iof(Expression lhv, ClassNode rhv)

static boolean isEnum(ClassNode classNode)

static BinaryExpression ne(Expression lhv, Expression rhv)

static NotExpression not(Expression expr)

static BinaryExpression or(Expression lhv, Expression rhv)

static Parameter param(ClassNode type, String name)

static Parameter param(ClassNode type, String name, Expression initialExpression)

static boolean parametersEqual(Parameter[] a, Parameter[] b)

@return true if the two arrays are of the same size and have the same contents

static Parameter[] params(Parameter... params)

static Expression prop(Expression owner, String property)

static Expression prop(Expression owner, Expression property)

static Statement returns(Expression expr)

static ExpressionStatement stmnt(Expression expression)

static ClassNode[] throwing(ClassNode... exceptions)

static VariableExpression var(String name)

static VariableExpression var(String name, ClassNode type)

static ArgumentListExpression vars(String... names)

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

Field Detail

AND

public static final Token AND


ASSIGN

public static final Token ASSIGN


CMP

public static final Token CMP


EQ

public static final Token EQ


INSTANCEOF

public static final Token INSTANCEOF


NE

public static final Token NE


NO_ARGS

public static final ArgumentListExpression NO_ARGS


NO_EXCEPTIONS

public static final ClassNode[] NO_EXCEPTIONS


NO_PARAMS

public static final Parameter[] NO_PARAMS


OR

public static final Token OR


SUPER

public static final Expression SUPER


THIS

public static final Expression THIS


 
Constructor Detail

GriffonASTUtils

GriffonASTUtils()


 
Method Detail

addMethod

public static boolean addMethod(ClassNode classNode, MethodNode methodNode)


addMethod

public static boolean addMethod(ClassNode classNode, MethodNode methodNode, boolean replace)


addReadOnlyProperty

public static void addReadOnlyProperty(ClassNode classNode, String propertyName, ClassNode propertyClass, Object value)


and

public static BinaryExpression and(Expression lhv, Expression rhv)


args

public static ArgumentListExpression args(Expression... expressions)


args

public static ArgumentListExpression args(List expressions)


assign

public static BinaryExpression assign(Expression lhv, Expression rhv)


assigns

public static Statement assigns(Expression expression, Expression value)


block

public static BlockStatement block(Statement... stms)


call

public static MethodCallExpression call(Expression receiver, String methodName, ArgumentListExpression args)


call

public static StaticMethodCallExpression call(ClassNode receiver, String methodName, ArgumentListExpression args)


classx

public static ClassExpression classx(ClassNode clazz)


classx

public static ClassExpression classx(Class clazz)


cmp

public static BinaryExpression cmp(Expression lhv, Expression rhv)


constx

public static ConstantExpression constx(Object val)


ctor

public static ConstructorCallExpression ctor(ClassNode type, Expression args)


decls

public static Statement decls(Expression lhv, Expression rhv)


eq

public static BinaryExpression eq(Expression lhv, Expression rhv)


field

public static FieldExpression field(FieldNode fieldNode)


field

public static FieldExpression field(ClassNode owner, String fieldName)


getFullName

public static String getFullName(ClassNode classNode)
Gets the full name of a ClassNode.
Parameters:
classNode - The class node
Returns:
The full name


getFurthestParent

public static ClassNode getFurthestParent(ClassNode classNode)


hasField

public static boolean hasField(ClassNode classNode, String name, int modifiers, ClassNode type)


hasOrInheritsField

public static boolean hasOrInheritsField(ClassNode classNode, String name, int modifiers, ClassNode type)


hasOrInheritsProperty

public static boolean hasOrInheritsProperty(ClassNode classNode, String propertyName)


hasProperty

public static boolean hasProperty(ClassNode classNode, String propertyName)
Returns whether a classNode has the specified property or not
Parameters:
classNode - The ClassNode
propertyName - The name of the property
Returns:
True if the property exists in the ClassNode


ifs

public static Statement ifs(Expression cond, Expression trueExpr)


ifs

public static Statement ifs(Expression cond, Expression trueExpr, Expression falseExpr)


ifs_no_return

public static Statement ifs_no_return(Expression cond, Expression trueExpr)


ifs_no_return

public static Statement ifs_no_return(Expression cond, Expression trueExpr, Expression falseExpr)


ifs_no_return

public static Statement ifs_no_return(Expression cond, Statement trueStmnt)


ifs_no_return

public static Statement ifs_no_return(Expression cond, Statement trueStmnt, Statement falseStmnt)


implementsMethod

public static boolean implementsMethod(ClassNode classNode, MethodNode methodNode)


implementsOrInheritsMethod

public static boolean implementsOrInheritsMethod(ClassNode classNode, MethodNode methodNode)


implementsOrInheritsZeroArgMethod

@SuppressWarnings("unchecked")
public static boolean implementsOrInheritsZeroArgMethod(ClassNode classNode, String methodName, List ignoreClasses)


implementsZeroArgMethod

public static boolean implementsZeroArgMethod(ClassNode classNode, String methodName)
Tests whether the ClasNode implements the specified method name.
Parameters:
classNode - The ClassNode
methodName - The method name
Returns:
True if it does implement the method


injectConstant

public static void injectConstant(ClassNode classNode, String propertyName, Class propertyClass, Object value)


injectField

public static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Object value)


injectField

public static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Object value, boolean deep)


injectField

public static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Expression initialExpression)


injectField

public static FieldNode injectField(ClassNode classNode, String name, int modifiers, ClassNode type, Expression initialExpression, boolean deep)


injectInterface

public static void injectInterface(ClassNode classNode, ClassNode type)


injectInterface

public static void injectInterface(ClassNode classNode, ClassNode type, boolean deep)


injectMethod

public static void injectMethod(ClassNode classNode, MethodNode methodNode)


injectMethod

public static void injectMethod(ClassNode classNode, MethodNode methodNode, boolean deep)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, Class propertyClass)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, Class propertyClass, Object value)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, int modifiers, Class propertyClass)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, int modifiers, Class propertyClass, Object value)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, ClassNode propertyClass)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, int modifiers, ClassNode propertyClass)


injectProperty

public static void injectProperty(ClassNode classNode, String propertyName, int modifiers, ClassNode propertyClass, Object value)


iof

public static BinaryExpression iof(Expression lhv, Expression rhv)


iof

public static BinaryExpression iof(Expression lhv, ClassNode rhv)


isEnum

public static boolean isEnum(ClassNode classNode)


ne

public static BinaryExpression ne(Expression lhv, Expression rhv)


not

public static NotExpression not(Expression expr)


or

public static BinaryExpression or(Expression lhv, Expression rhv)


param

public static Parameter param(ClassNode type, String name)


param

public static Parameter param(ClassNode type, String name, Expression initialExpression)


parametersEqual

public static boolean parametersEqual(Parameter[] a, Parameter[] b)
Returns:
true if the two arrays are of the same size and have the same contents


params

public static Parameter[] params(Parameter... params)


prop

public static Expression prop(Expression owner, String property)


prop

public static Expression prop(Expression owner, Expression property)


returns

public static Statement returns(Expression expr)


stmnt

public static ExpressionStatement stmnt(Expression expression)


throwing

public static ClassNode[] throwing(ClassNode... exceptions)


var

public static VariableExpression var(String name)


var

public static VariableExpression var(String name, ClassNode type)


vars

public static ArgumentListExpression vars(String... names)


 

Groovy Documentation