|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.ClassNode
public class ClassNode
Represents a class in the AST.
A ClassNode should be created using the methods in ClassHelper.
This ClassNode may be used to represent a class declaration or
any other type. This class uses a proxy meschanism allowing to
create a class for a plain name at ast creation time. In another
phase of the compiler the real ClassNode for the plain name may be
found. To avoid the need of exchanging this ClassNode with an
instance of the correct ClassNode the correct ClassNode is set as
redirect. All method calls are then redirected to that ClassNode.
Note: the proxy mechanism is only allowed for classes being marked
as primary ClassNode which means they represent no actual class.
The redirect itself can be any type of ClassNode
ClassHelper
Field Summary | |
---|---|
protected java.lang.Class |
clazz
|
static ClassNode[] |
EMPTY_ARRAY
|
protected java.lang.Object |
lazyInitLock
|
static ClassNode |
SUPER
|
static ClassNode |
THIS
|
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(java.lang.Class c)
Creates a ClassNode from a real class. |
|
ClassNode(java.lang.String name,
int modifiers,
ClassNode superClass)
|
|
ClassNode(java.lang.String name,
int modifiers,
ClassNode superClass,
ClassNode[] interfaces,
MixinNode[] mixins)
|
Method Summary | |
---|---|
void |
addConstructor(ConstructorNode node)
|
ConstructorNode |
addConstructor(int modifiers,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code)
|
void |
addField(FieldNode node)
|
FieldNode |
addField(java.lang.String name,
int modifiers,
ClassNode type,
Expression initialValue)
|
void |
addInterface(ClassNode type)
|
void |
addMethod(MethodNode node)
|
MethodNode |
addMethod(java.lang.String name,
int modifiers,
ClassNode returnType,
Parameter[] parameters,
ClassNode[] exceptions,
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 |
addObjectInitializerStatements(Statement statements)
|
void |
addProperty(PropertyNode node)
|
PropertyNode |
addProperty(java.lang.String name,
int modifiers,
ClassNode type,
Expression initialValueExpression,
Statement getterBlock,
Statement setterBlock)
|
void |
addStaticInitializerStatements(java.util.List staticStatements,
boolean fieldInit)
|
MethodNode |
addSyntheticMethod(java.lang.String name,
int modifiers,
ClassNode returnType,
Parameter[] parameters,
ClassNode[] exceptions,
Statement code)
Adds a synthetic method as part of the compilation process |
protected MethodNode |
createMethodNode(java.lang.reflect.Method method)
Factory method to create a new MethodNode via reflection |
protected Parameter |
createParameter(java.lang.Class parameterType,
int idx)
|
protected Parameter[] |
createParameters(java.lang.Class[] types)
|
boolean |
declaresInterface(java.lang.String name)
|
boolean |
equals(java.lang.Object o)
|
java.util.List |
getAbstractMethods()
Returns a list containing MethodNode objects for each abstract method in the class represented by this ClassNode |
java.util.List |
getAllDeclaredMethods()
|
CompileUnit |
getCompileUnit()
|
ClassNode |
getComponentType()
|
java.util.List |
getDeclaredConstructors()
|
MethodNode |
getDeclaredMethod(java.lang.String name,
Parameter[] parameters)
|
java.util.List |
getDeclaredMethods(java.lang.String name)
|
protected java.util.Map |
getDeclaredMethodsMap()
|
MethodNode |
getEnclosingMethod()
|
FieldNode |
getField(java.lang.String name)
|
java.util.List |
getFields()
Returns a list containing FieldNode objects for each field in the class represented by this ClassNode |
MethodNode |
getGetterMethod(java.lang.String getterName)
|
ClassNode[] |
getInterfaces()
Returns an array of ClassNodes representing the interfaces the class implements |
java.util.List |
getMethods()
Returns a list containing MethodNode objects for each method in the class represented by this ClassNode |
java.util.List |
getMethods(java.lang.String name)
|
MixinNode[] |
getMixins()
|
int |
getModifiers()
|
ModuleNode |
getModule()
|
java.lang.String |
getName()
|
java.lang.String |
getNameWithoutPackage()
|
java.util.List |
getObjectInitializerStatements()
|
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)
|
ClassNode |
getSuperClass()
|
java.lang.Class |
getTypeClass()
|
ClassNode |
getUnresolvedSuperClass()
|
boolean |
hasPackageName()
|
boolean |
hasPossibleMethod(java.lang.String name,
Expression arguments)
Returns true if the given method has a possibly matching method with the given name and arguments |
boolean |
implementsInterface(java.lang.String name)
|
boolean |
isArray()
|
boolean |
isDerivedFrom(ClassNode type)
|
boolean |
isDerivedFromGroovyObject()
|
boolean |
isInterface()
|
boolean |
isPrimaryClassNode()
Returns if this instance is a primary ClassNode |
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()
Returns a ClassNode representing an array of the class represented by this ClassNode |
protected boolean |
parametersEqual(Parameter[] a,
Parameter[] b)
|
protected ClassNode |
redirect()
Returns the ClassNode this ClassNode is redirecting to. |
protected void |
setCompileUnit(CompileUnit cu)
|
void |
setEnclosingMethod(MethodNode enclosingMethod)
|
void |
setModule(ModuleNode module)
|
java.lang.String |
setName(java.lang.String name)
|
void |
setRedirect(ClassNode cn)
Sets this instance as proxy for the given ClassNode. |
void |
setScript(boolean script)
|
void |
setScriptBody(boolean scriptBody)
|
void |
setStaticClass(boolean staticClass)
|
void |
setSuperClass(ClassNode superClass)
Sets the superclass of this ClassNode |
java.lang.String |
toString()
|
void |
visitContents(GroovyClassVisitor visitor)
|
Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode |
---|
addAnnotation, addAnnotations, getAnnotationClass, getAnnotations, getAnnotations, getDeclaringClass, isSynthetic, setDeclaringClass, setSynthetic |
Methods inherited from class org.codehaus.groovy.ast.ASTNode |
---|
getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setSourcePosition, visit |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static ClassNode[] EMPTY_ARRAY
public static ClassNode THIS
public static ClassNode SUPER
protected java.lang.Object lazyInitLock
protected java.lang.Class clazz
Constructor Detail |
---|
public ClassNode(java.lang.Class c)
public ClassNode(java.lang.String name, int modifiers, ClassNode superClass)
name
- is the full name of the classmodifiers
- the modifiers,superClass
- the base class name - use "java.lang.Object" if no direct
base classOpcodes
public ClassNode(java.lang.String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)
name
- is the full name of the classmodifiers
- the modifiers,superClass
- the base class name - use "java.lang.Object" if no direct
base classOpcodes
Method Detail |
---|
protected ClassNode redirect()
public void setRedirect(ClassNode cn)
cn
- the class to redirect to. If set to null the redirect will be removedpublic ClassNode makeArray()
public boolean isPrimaryClassNode()
public MethodNode getEnclosingMethod()
public void setEnclosingMethod(MethodNode enclosingMethod)
public void setSuperClass(ClassNode superClass)
public java.util.List getFields()
public ClassNode[] getInterfaces()
public MixinNode[] getMixins()
public java.util.List getMethods()
public java.util.List getAbstractMethods()
public java.util.List getAllDeclaredMethods()
protected java.util.Map getDeclaredMethodsMap()
public java.lang.String getName()
public java.lang.String setName(java.lang.String name)
public int getModifiers()
public java.util.List getProperties()
public java.util.List getDeclaredConstructors()
public ModuleNode getModule()
public void setModule(ModuleNode module)
public void addField(FieldNode node)
public void addProperty(PropertyNode node)
public PropertyNode addProperty(java.lang.String name, int modifiers, ClassNode type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock)
public void addConstructor(ConstructorNode node)
public ConstructorNode addConstructor(int modifiers, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public void addMethod(MethodNode node)
public MethodNode addMethod(java.lang.String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public MethodNode addSyntheticMethod(java.lang.String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public FieldNode addField(java.lang.String name, int modifiers, ClassNode type, Expression initialValue)
public void addInterface(ClassNode type)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public void addMixin(MixinNode mixin)
public FieldNode getField(java.lang.String name)
public FieldNode getOuterField(java.lang.String name)
public ClassNode getOuterClass()
public void addObjectInitializerStatements(Statement statements)
public java.util.List getObjectInitializerStatements()
public void addStaticInitializerStatements(java.util.List staticStatements, boolean fieldInit)
public java.util.List getDeclaredMethods(java.lang.String name)
public java.util.List getMethods(java.lang.String name)
public MethodNode getDeclaredMethod(java.lang.String name, Parameter[] parameters)
public boolean isDerivedFrom(ClassNode type)
public boolean isDerivedFromGroovyObject()
public boolean implementsInterface(java.lang.String name)
name
- the fully qualified name of the interface
public boolean declaresInterface(java.lang.String name)
name
- the fully qualified name of the interface
public ClassNode getSuperClass()
public ClassNode getUnresolvedSuperClass()
protected MethodNode createMethodNode(java.lang.reflect.Method method)
protected Parameter[] createParameters(java.lang.Class[] types)
types
- protected Parameter createParameter(java.lang.Class parameterType, int idx)
public CompileUnit getCompileUnit()
protected void setCompileUnit(CompileUnit cu)
protected boolean parametersEqual(Parameter[] a, Parameter[] b)
public java.lang.String getPackageName()
public java.lang.String getNameWithoutPackage()
public void visitContents(GroovyClassVisitor visitor)
public MethodNode getGetterMethod(java.lang.String getterName)
public MethodNode getSetterMethod(java.lang.String getterName)
public boolean isStaticClass()
public void setStaticClass(boolean staticClass)
public boolean isScriptBody()
public void setScriptBody(boolean scriptBody)
public boolean isScript()
public void setScript(boolean script)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean hasPossibleMethod(java.lang.String name, Expression arguments)
public boolean isInterface()
public boolean isResolved()
public boolean isArray()
public ClassNode getComponentType()
public java.lang.Class getTypeClass()
public boolean hasPackageName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |