org.codehaus.groovy.ast
Class ClassNode

java.lang.Object
  extended byorg.codehaus.groovy.ast.ASTNode
      extended byorg.codehaus.groovy.ast.MetadataNode
          extended byorg.codehaus.groovy.ast.ClassNode
All Implemented Interfaces:
org.objectweb.asm.Constants
Direct Known Subclasses:
InnerClassNode, MixinNode

public class ClassNode
extends MetadataNode
implements org.objectweb.asm.Constants

Represents a class declaration

Version:
$Revision: 1.31 $
Author:
James Strachan

Field Summary
 
Fields inherited from class org.codehaus.groovy.ast.ASTNode
EMPTY_STRING_ARRAY
 
Fields inherited from interface org.objectweb.asm.Constants
AALOAD, AASTORE, ACC_ABSTRACT, 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
 
Constructor Summary
ClassNode(java.lang.String name, int modifiers, java.lang.String superClass)
           
ClassNode(java.lang.String name, int modifiers, java.lang.String superClass, java.lang.String[] interfaces, MixinNode[] mixins)
           
 
Method Summary
 void addConstructor(ConstructorNode node)
           
 ConstructorNode addConstructor(int modifiers, Parameter[] parameters, Statement code)
           
 void addField(FieldNode node)
           
 FieldNode addField(java.lang.String name, int modifiers, java.lang.String type, Expression initialValue)
           
 void addInterface(java.lang.String name)
           
 void addMethod(MethodNode node)
           
 MethodNode addMethod(java.lang.String name, int modifiers, java.lang.String 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(java.lang.String name, int modifiers, java.lang.String type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock)
           
 void addStaticInitializerStatements(java.util.List staticStatements)
           
 MethodNode addSyntheticMethod(java.lang.String name, int modifiers, java.lang.String returnType, Parameter[] parameters, Statement code)
          Adds a synthetic method as part of the compilation process
protected  ClassNode createClassNode(java.lang.Class theClass)
           
 boolean declaresInterface(java.lang.String name)
           
 ClassNode findClassNode(java.lang.String type)
          Attempts to lookup the fully qualified class name in the compile unit or classpath
 java.lang.String getClassNameForExpression(java.lang.String identifier)
           
 CompileUnit getCompileUnit()
           
 java.util.List getConstructors()
           
 FieldNode getField(java.lang.String name)
           
 java.util.List getFields()
           
 MethodNode getGetterMethod(java.lang.String getterName)
           
 java.lang.String[] getInterfaces()
           
 MethodNode getMethod(java.lang.String name)
           
 MethodNode getMethod(java.lang.String name, Parameter[] parameters)
           
 java.util.List getMethods()
           
 MixinNode[] getMixins()
           
 int getModifiers()
           
 ModuleNode getModule()
           
 java.lang.String getName()
           
 java.lang.String getNameWithoutPackage()
           
 ClassNode getOuterClass()
          Helper method to avoid casting to inner class
 FieldNode getOuterField(java.lang.String name)
           
 java.lang.String getPackageName()
           
 java.util.List getProperties()
           
 MethodNode getSetterMethod(java.lang.String getterName)
           
 java.lang.String getSuperClass()
           
 ClassNode getSuperClassNode()
           
 boolean implementsInteface(java.lang.String name)
           
 boolean isDerivedFrom(java.lang.String name)
           
 boolean isDerivedFromGroovyObject()
           
 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)
protected  boolean parametersEqual(Parameter[] a, Parameter[] b)
           
 java.lang.String resolveClassName(java.lang.String type)
          Tries to create a Class node for the given type name
 void setModule(ModuleNode module)
           
 void setScript(boolean script)
           
 void setScriptBody(boolean scriptBody)
           
 void setStaticClass(boolean staticClass)
           
 java.lang.String toString()
           
protected  java.lang.String tryResolveClassFromCompileUnit(java.lang.String type)
           
 void visitContents(GroovyClassVisitor visitor)
           
 
Methods inherited from class org.codehaus.groovy.ast.MetadataNode
addAttribute, getAttributes, getAttributes, isSynthetic, setAttribute, setSynthetic
 
Methods inherited from class org.codehaus.groovy.ast.ASTNode
getColumnNumber, getLineNumber, getText, setColumnNumber, setCSTNode, setLineNumber, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassNode

public ClassNode(java.lang.String name,
                 int modifiers,
                 java.lang.String 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:
Constants

ClassNode

public ClassNode(java.lang.String name,
                 int modifiers,
                 java.lang.String superClass,
                 java.lang.String[] 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:
Constants
Method Detail

getSuperClass

public java.lang.String getSuperClass()

getFields

public java.util.List getFields()

getInterfaces

public java.lang.String[] getInterfaces()

getMixins

public MixinNode[] getMixins()

getMethods

public java.util.List getMethods()

getName

public java.lang.String getName()

getModifiers

public int getModifiers()

getProperties

public java.util.List getProperties()

getConstructors

public java.util.List getConstructors()

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(java.lang.String name,
                                int modifiers,
                                java.lang.String 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(java.lang.String name,
                            int modifiers,
                            java.lang.String 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(java.lang.String name,
                                     int modifiers,
                                     java.lang.String returnType,
                                     Parameter[] parameters,
                                     Statement code)
Adds a synthetic method as part of the compilation process


addField

public FieldNode addField(java.lang.String name,
                          int modifiers,
                          java.lang.String type,
                          Expression initialValue)

addInterface

public void addInterface(java.lang.String name)

addMixin

public void addMixin(MixinNode mixin)

getField

public FieldNode getField(java.lang.String name)

getOuterField

public FieldNode getOuterField(java.lang.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(java.util.List staticStatements)

getMethod

public MethodNode getMethod(java.lang.String name)

getMethod

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

isDerivedFrom

public boolean isDerivedFrom(java.lang.String name)
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(java.lang.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(java.lang.String name)
Parameters:
name - the fully qualified name of the interface
Returns:
true if this class declares that it implements the given interface

getSuperClassNode

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

findClassNode

public ClassNode findClassNode(java.lang.String type)
Attempts to lookup the fully qualified class name in the compile unit or classpath

Parameters:
type - fully qulified type name
Returns:
the ClassNode for this type or null if it could not be found

createClassNode

protected ClassNode createClassNode(java.lang.Class theClass)

resolveClassName

public java.lang.String resolveClassName(java.lang.String type)
Tries to create a Class node for the given type name

Parameters:
type -
Returns:

tryResolveClassFromCompileUnit

protected java.lang.String tryResolveClassFromCompileUnit(java.lang.String type)
Parameters:
type -
Returns:

getCompileUnit

public CompileUnit getCompileUnit()

parametersEqual

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

getClassNameForExpression

public java.lang.String getClassNameForExpression(java.lang.String identifier)
Returns:
the name of the class for the given identifier if it is a class otherwise return null

getPackageName

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

getNameWithoutPackage

public java.lang.String getNameWithoutPackage()

visitContents

public void visitContents(GroovyClassVisitor visitor)

getGetterMethod

public MethodNode getGetterMethod(java.lang.String getterName)

getSetterMethod

public MethodNode getSetterMethod(java.lang.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 java.lang.String toString()


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