org.codehaus.groovy.ast
Class ClassNode

java.lang.Object
  extended by org.codehaus.groovy.ast.ASTNode
      extended by org.codehaus.groovy.ast.AnnotatedNode
          extended by org.codehaus.groovy.ast.ClassNode
All Implemented Interfaces:
org.objectweb.asm.Opcodes
Direct Known Subclasses:
InnerClassNode, MixinNode

public class ClassNode
extends AnnotatedNode
implements org.objectweb.asm.Opcodes

Represents a class declaration

Version:
$Revision: 1.59 $
Author:
James Strachan

Field Summary
protected  boolean resolved
           
 
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6
 
Constructor Summary
ClassNode(Class c)
           
ClassNode(String name, int modifiers, ClassNode superClass)
           
ClassNode(String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)
           
 
Method Summary
 void addConstructor(ConstructorNode node)
           
 ConstructorNode addConstructor(int modifiers, Parameter[] parameters, Statement code)
           
 void addField(FieldNode node)
           
 FieldNode addField(String name, int modifiers, ClassNode type, Expression initialValue)
           
 void addInterface(ClassNode type)
           
 void addMethod(MethodNode node)
           
 MethodNode addMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, Statement code)
          IF a method with the given name and parameters is already defined then it is returned otherwise the given method is added to this node.
 void addMixin(MixinNode mixin)
           
 void addProperty(PropertyNode node)
           
 PropertyNode addProperty(String name, int modifiers, ClassNode type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock)
           
 void addStaticInitializerStatements(List staticStatements)
           
 MethodNode addSyntheticMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, Statement code)
          Adds a synthetic method as part of the compilation process
protected  MethodNode createMethodNode(Method method)
          Factory method to create a new MethodNode via reflection
protected  Parameter createParameter(Class parameterType, int idx)
           
protected  Parameter[] createParameters(Class[] types)
           
 boolean declaresInterface(String name)
           
 boolean equals(Object o)
           
 List getAbstractMethods()
           
 List getAllDeclaredMethods()
           
 CompileUnit getCompileUnit()
           
 ClassNode getComponentType()
           
 List getDeclaredConstructors()
           
 MethodNode getDeclaredMethod(String name, Parameter[] parameters)
           
 List getDeclaredMethods(String name)
           
protected  Map getDeclaredMethodsMap()
           
 MethodNode getEnclosingMethod()
           
 FieldNode getField(String name)
           
 List getFields()
           
 MethodNode getGetterMethod(String getterName)
           
 ClassNode[] getInterfaces()
           
 List getMethods()
           
 List getMethods(String name)
           
 MixinNode[] getMixins()
           
 int getModifiers()
           
 ModuleNode getModule()
           
 String getName()
           
 String getNameWithoutPackage()
           
 ClassNode getOuterClass()
          Helper method to avoid casting to inner class
 FieldNode getOuterField(String name)
           
 String getPackageName()
           
 List getProperties()
           
 MethodNode getSetterMethod(String getterName)
           
 ClassNode getSuperClass()
           
 Class getTypeClass()
           
 boolean hasPackageName()
           
 boolean hasPossibleMethod(String name, Expression arguments)
          Returns true if the given method has a possibly matching method with the given name and arguments
 boolean implementsInteface(String name)
           
 boolean isArray()
           
 boolean isDerivedFrom(ClassNode type)
           
 boolean isDerivedFromGroovyObject()
           
 boolean isInterface()
           
 boolean isPrimaryClassNode()
           
 boolean isResolved()
           
 boolean isScript()
           
 boolean isScriptBody()
           
 boolean isStaticClass()
          Is this class delcared in a static method (such as a closure / inner class declared in a static method)
 ClassNode makeArray()
           
protected  boolean parametersEqual(Parameter[] a, Parameter[] b)
           
protected  ClassNode redirect()
           
protected  void setCompileUnit(CompileUnit cu)
           
 void setEnclosingMethod(MethodNode enclosingMethod)
           
 void setModule(ModuleNode module)
           
 String setName(String name)
           
 void setRedirect(ClassNode cn)
           
 void setScript(boolean script)
           
 void setScriptBody(boolean scriptBody)
           
 void setStaticClass(boolean staticClass)
           
 void setSuperClass(ClassNode superClass)
           
 String toString()
           
 void visitContents(GroovyClassVisitor visitor)
           
 
Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotations, addFieldsToVisitor, getAnnotationClass, getAnnotations, getAnnotations, getDeclaringClass, isSynthetic, setDeclaringClass, setSynthetic
 
Methods inherited from class org.codehaus.groovy.ast.ASTNode
getColumnNumber, getLineNumber, getText, setColumnNumber, setLineNumber, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resolved

protected boolean resolved
Constructor Detail

ClassNode

public ClassNode(Class c)

ClassNode

public ClassNode(String name,
                 int modifiers,
                 ClassNode superClass)
Parameters:
name - is the full name of the class
modifiers - the modifiers,
superClass - the base class name - use "java.lang.Object" if no direct base class
See Also:
Opcodes

ClassNode

public ClassNode(String name,
                 int modifiers,
                 ClassNode superClass,
                 ClassNode[] interfaces,
                 MixinNode[] mixins)
Parameters:
name - is the full name of the class
modifiers - the modifiers,
superClass - the base class name - use "java.lang.Object" if no direct base class
See Also:
Opcodes
Method Detail

redirect

protected ClassNode redirect()

setRedirect

public void setRedirect(ClassNode cn)

makeArray

public ClassNode makeArray()

isPrimaryClassNode

public boolean isPrimaryClassNode()

getEnclosingMethod

public MethodNode getEnclosingMethod()

setEnclosingMethod

public void setEnclosingMethod(MethodNode enclosingMethod)

setSuperClass

public void setSuperClass(ClassNode superClass)

getFields

public List getFields()

getInterfaces

public ClassNode[] getInterfaces()

getMixins

public MixinNode[] getMixins()

getMethods

public List getMethods()

getAbstractMethods

public List getAbstractMethods()

getAllDeclaredMethods

public List getAllDeclaredMethods()

getDeclaredMethodsMap

protected Map getDeclaredMethodsMap()

getName

public String getName()

setName

public String setName(String name)

getModifiers

public int getModifiers()

getProperties

public List getProperties()

getDeclaredConstructors

public List getDeclaredConstructors()

getModule

public ModuleNode getModule()

setModule

public void setModule(ModuleNode module)

addField

public void addField(FieldNode node)

addProperty

public void addProperty(PropertyNode node)

addProperty

public PropertyNode addProperty(String name,
                                int modifiers,
                                ClassNode type,
                                Expression initialValueExpression,
                                Statement getterBlock,
                                Statement setterBlock)

addConstructor

public void addConstructor(ConstructorNode node)

addConstructor

public ConstructorNode addConstructor(int modifiers,
                                      Parameter[] parameters,
                                      Statement code)

addMethod

public void addMethod(MethodNode node)

addMethod

public MethodNode addMethod(String name,
                            int modifiers,
                            ClassNode returnType,
                            Parameter[] parameters,
                            Statement code)
IF a method with the given name and parameters is already defined then it is returned otherwise the given method is added to this node. This method is useful for default method adding like getProperty() or invokeMethod() where there may already be a method defined in a class and so the default implementations should not be added if already present.


addSyntheticMethod

public MethodNode addSyntheticMethod(String name,
                                     int modifiers,
                                     ClassNode returnType,
                                     Parameter[] parameters,
                                     Statement code)
Adds a synthetic method as part of the compilation process


addField

public FieldNode addField(String name,
                          int modifiers,
                          ClassNode type,
                          Expression initialValue)

addInterface

public void addInterface(ClassNode type)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

addMixin

public void addMixin(MixinNode mixin)

getField

public FieldNode getField(String name)

getOuterField

public FieldNode getOuterField(String name)
Returns:
the field node on the outer class or null if this is not an inner class

getOuterClass

public ClassNode getOuterClass()
Helper method to avoid casting to inner class

Returns:

addStaticInitializerStatements

public void addStaticInitializerStatements(List staticStatements)

getDeclaredMethods

public List getDeclaredMethods(String name)
Returns:
a list of methods which match the given name

getMethods

public List getMethods(String name)
Returns:
a list of methods which match the given name

getDeclaredMethod

public MethodNode getDeclaredMethod(String name,
                                    Parameter[] parameters)
Returns:
the method matching the given name and parameters or null

isDerivedFrom

public boolean isDerivedFrom(ClassNode type)
Returns:
true if this node is derived from the given class node

isDerivedFromGroovyObject

public boolean isDerivedFromGroovyObject()
Returns:
true if this class is derived from a groovy object i.e. it implements GroovyObject

implementsInteface

public boolean implementsInteface(String name)
Parameters:
name - the fully qualified name of the interface
Returns:
true if this class or any base class implements the given interface

declaresInterface

public boolean declaresInterface(String name)
Parameters:
name - the fully qualified name of the interface
Returns:
true if this class declares that it implements the given interface

getSuperClass

public ClassNode getSuperClass()
Returns:
the ClassNode of the super class of this type

createMethodNode

protected MethodNode createMethodNode(Method method)
Factory method to create a new MethodNode via reflection


createParameters

protected Parameter[] createParameters(Class[] types)
Parameters:
types -
Returns:

createParameter

protected Parameter createParameter(Class parameterType,
                                    int idx)

getCompileUnit

public CompileUnit getCompileUnit()

setCompileUnit

protected void setCompileUnit(CompileUnit cu)

parametersEqual

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

getPackageName

public String getPackageName()
Returns:
the package name of this class

getNameWithoutPackage

public String getNameWithoutPackage()

visitContents

public void visitContents(GroovyClassVisitor visitor)

getGetterMethod

public MethodNode getGetterMethod(String getterName)

getSetterMethod

public MethodNode getSetterMethod(String getterName)

isStaticClass

public boolean isStaticClass()
Is this class delcared in a static method (such as a closure / inner class declared in a static method)

Returns:

setStaticClass

public void setStaticClass(boolean staticClass)

isScriptBody

public boolean isScriptBody()
Returns:
Returns true if this inner class or closure was declared inside a script body

setScriptBody

public void setScriptBody(boolean scriptBody)

isScript

public boolean isScript()

setScript

public void setScript(boolean script)

toString

public String toString()
Overrides:
toString in class Object

hasPossibleMethod

public boolean hasPossibleMethod(String name,
                                 Expression arguments)
Returns true if the given method has a possibly matching method with the given name and arguments


isInterface

public boolean isInterface()

isResolved

public boolean isResolved()

isArray

public boolean isArray()

getComponentType

public ClassNode getComponentType()

getTypeClass

public Class getTypeClass()

hasPackageName

public boolean hasPackageName()


Copyright © 2003-2010 The Codehaus. All Rights Reserved.