public class ClassNode extends AnnotatedNode implements org.objectweb.asm.Opcodes
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 mechanism 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. Most method calls are then redirected to that ClassNode.
There are three types of ClassNodes:
To describe generic type signature see getGenericsTypes()
and
setGenericsTypes(GenericsType[])
. These methods are not proxied,
they describe the type signature used at the point of declaration or the
type signatures provided by the class. If the type signatures provided
by the class are needed, then a call to redirect()
will help.
ClassHelper
Modifier and Type | Field and Description |
---|---|
protected java.lang.Class |
clazz |
static ClassNode[] |
EMPTY_ARRAY |
protected java.util.List<InnerClassNode> |
innerClasses |
protected boolean |
isPrimaryNode |
protected java.lang.Object |
lazyInitLock |
static ClassNode |
SUPER |
static ClassNode |
THIS |
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, ASM4, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, 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, INTEGER, INVOKEDYNAMIC, 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, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, 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, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
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 |
addFieldFirst(FieldNode node) |
FieldNode |
addFieldFirst(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)
Adds a statement to the object initializer.
|
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<Statement> 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
|
void |
addTransform(java.lang.Class<? extends ASTTransformation> transform,
ASTNode node) |
boolean |
declaresInterface(ClassNode classNode) |
boolean |
equals(java.lang.Object o) |
java.util.List<MethodNode> |
getAbstractMethods() |
java.util.List<MethodNode> |
getAllDeclaredMethods() |
java.util.Set<ClassNode> |
getAllInterfaces() |
java.util.List<AnnotationNode> |
getAnnotations() |
java.util.List<AnnotationNode> |
getAnnotations(ClassNode type) |
CompileUnit |
getCompileUnit() |
ClassNode |
getComponentType() |
java.util.List<ConstructorNode> |
getDeclaredConstructors() |
FieldNode |
getDeclaredField(java.lang.String name)
Finds a field matching the given name in this class.
|
MethodNode |
getDeclaredMethod(java.lang.String name,
Parameter[] parameters)
Finds a method matching the given name and parameters in this class.
|
java.util.List<MethodNode> |
getDeclaredMethods(java.lang.String name)
This methods returns a list of all methods of the given name
defined in the current class
|
java.util.Map<java.lang.String,MethodNode> |
getDeclaredMethodsMap() |
MethodNode |
getEnclosingMethod() |
FieldNode |
getField(java.lang.String name)
Finds a field matching the given name in this class or a parent class.
|
java.util.List<FieldNode> |
getFields() |
GenericsType[] |
getGenericsTypes() |
MethodNode |
getGetterMethod(java.lang.String getterName) |
java.util.Iterator<InnerClassNode> |
getInnerClasses() |
ClassNode[] |
getInterfaces() |
MethodNode |
getMethod(java.lang.String name,
Parameter[] parameters)
Finds a method matching the given name and parameters in this class
or any parent class.
|
java.util.List<MethodNode> |
getMethods() |
java.util.List<MethodNode> |
getMethods(java.lang.String name)
This methods creates a list of all methods with this name of the
current class and of all super classes
|
MixinNode[] |
getMixins() |
int |
getModifiers() |
ModuleNode |
getModule() |
java.lang.String |
getName() |
java.lang.String |
getNameWithoutPackage() |
java.util.List<Statement> |
getObjectInitializerStatements() |
ClassNode |
getOuterClass()
Helper method to avoid casting to inner class
|
FieldNode |
getOuterField(java.lang.String name) |
PackageNode |
getPackage() |
java.lang.String |
getPackageName() |
ClassNode |
getPlainNodeReference() |
java.util.List<PropertyNode> |
getProperties() |
PropertyNode |
getProperty(java.lang.String name) |
MethodNode |
getSetterMethod(java.lang.String setterName) |
MethodNode |
getSetterMethod(java.lang.String setterName,
boolean voidOnly) |
ClassNode |
getSuperClass() |
java.lang.String |
getText() |
java.util.Map<java.lang.Class<? extends ASTTransformation>,java.util.Set<ASTNode>> |
getTransforms(CompilePhase phase) |
java.lang.Class |
getTypeClass()
Returns the concrete class this classnode relates to.
|
ClassNode[] |
getUnresolvedInterfaces() |
ClassNode[] |
getUnresolvedInterfaces(boolean useRedirect) |
java.lang.String |
getUnresolvedName() |
ClassNode |
getUnresolvedSuperClass() |
ClassNode |
getUnresolvedSuperClass(boolean useRedirect) |
boolean |
hasDeclaredMethod(java.lang.String name,
Parameter[] parameters) |
int |
hashCode() |
boolean |
hasMethod(java.lang.String name,
Parameter[] parameters) |
boolean |
hasPackageName() |
boolean |
hasPossibleMethod(java.lang.String name,
Expression arguments)
Returns true if the given method has a possibly matching instance method with the given name and arguments.
|
boolean |
hasPossibleStaticMethod(java.lang.String name,
Expression arguments)
Returns true if the given method has a possibly matching static method with the given name and arguments.
|
boolean |
hasProperty(java.lang.String name) |
boolean |
implementsInterface(ClassNode classNode) |
boolean |
isAnnotated() |
boolean |
isAnnotationDefinition() |
boolean |
isArray() |
boolean |
isDerivedFrom(ClassNode type) |
boolean |
isDerivedFromGroovyObject() |
boolean |
isEnum() |
boolean |
isGenericsPlaceHolder() |
boolean |
isInterface() |
boolean |
isPrimaryClassNode() |
boolean |
isRedirectNode() |
boolean |
isResolved() |
boolean |
isScript() |
boolean |
isScriptBody() |
boolean |
isStaticClass()
Is this class declared in a static method (such as a closure / inner class declared in a static method)
|
boolean |
isSyntheticPublic()
Indicates that this class has been "promoted" to public by
Groovy when in fact there was no public modifier explicitly
in the source code.
|
boolean |
isUsingGenerics() |
ClassNode |
makeArray()
Returns a ClassNode representing an array of the class
represented by this ClassNode
|
protected boolean |
parametersEqual(Parameter[] a,
Parameter[] b) |
void |
positionStmtsAfterEnumInitStmts(java.util.List<Statement> staticFieldStatements) |
ClassNode |
redirect()
Returns the ClassNode this ClassNode is redirecting to.
|
void |
removeField(java.lang.String oldName) |
void |
renameField(java.lang.String oldName,
java.lang.String newName) |
void |
setAnnotated(boolean flag)
Marks if the current class uses annotations or not
|
protected void |
setCompileUnit(CompileUnit cu) |
void |
setEnclosingMethod(MethodNode enclosingMethod) |
void |
setGenericsPlaceHolder(boolean b) |
void |
setGenericsTypes(GenericsType[] genericsTypes) |
void |
setInterfaces(ClassNode[] interfaces) |
void |
setModifiers(int modifiers) |
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
|
void |
setSyntheticPublic(boolean syntheticPublic) |
void |
setUnresolvedSuperClass(ClassNode sn) |
void |
setUsingGenerics(boolean b) |
java.lang.String |
toString() |
java.lang.String |
toString(boolean showRedirect) |
MethodNode |
tryFindPossibleMethod(java.lang.String name,
Expression arguments) |
void |
visitContents(GroovyClassVisitor visitor) |
addAnnotation, addAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getNodeMetaData, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition, visit
public static final ClassNode[] EMPTY_ARRAY
public static final ClassNode THIS
public static final ClassNode SUPER
protected boolean isPrimaryNode
protected java.util.List<InnerClassNode> innerClasses
protected java.lang.Object lazyInitLock
protected java.lang.Class clazz
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 classinterfaces
- the interfaces for this classmixins
- the mixins for this classOpcodes
public 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 boolean isSyntheticPublic()
public void setSyntheticPublic(boolean syntheticPublic)
public void setSuperClass(ClassNode superClass)
public java.util.List<FieldNode> getFields()
public ClassNode[] getInterfaces()
public void setInterfaces(ClassNode[] interfaces)
public MixinNode[] getMixins()
public java.util.List<MethodNode> getMethods()
public java.util.List<MethodNode> getAbstractMethods()
public java.util.List<MethodNode> getAllDeclaredMethods()
public java.util.Set<ClassNode> getAllInterfaces()
public java.util.Map<java.lang.String,MethodNode> getDeclaredMethodsMap()
public java.lang.String getName()
public java.lang.String getUnresolvedName()
public java.lang.String setName(java.lang.String name)
public int getModifiers()
public void setModifiers(int modifiers)
public java.util.List<PropertyNode> getProperties()
public java.util.List<ConstructorNode> getDeclaredConstructors()
public ModuleNode getModule()
public PackageNode getPackage()
public void setModule(ModuleNode module)
public void addField(FieldNode node)
public void addFieldFirst(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 boolean hasProperty(java.lang.String name)
public PropertyNode getProperty(java.lang.String name)
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 boolean hasDeclaredMethod(java.lang.String name, Parameter[] parameters)
public boolean hasMethod(java.lang.String name, Parameter[] parameters)
getMethod(String, Parameter[])
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 FieldNode addFieldFirst(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 int hashCode()
hashCode
in class java.lang.Object
public void addMixin(MixinNode mixin)
public FieldNode getDeclaredField(java.lang.String name)
name
- the name of the field of interestpublic FieldNode getField(java.lang.String name)
name
- the name of the field of interestpublic FieldNode getOuterField(java.lang.String name)
public ClassNode getOuterClass()
public void addObjectInitializerStatements(Statement statements)
statements
- the statement to be addedpublic java.util.List<Statement> getObjectInitializerStatements()
public void addStaticInitializerStatements(java.util.List<Statement> staticStatements, boolean fieldInit)
public void positionStmtsAfterEnumInitStmts(java.util.List<Statement> staticFieldStatements)
public java.util.List<MethodNode> getDeclaredMethods(java.lang.String name)
getMethods(String)
public java.util.List<MethodNode> getMethods(java.lang.String name)
getDeclaredMethods(String)
public MethodNode getDeclaredMethod(java.lang.String name, Parameter[] parameters)
public MethodNode getMethod(java.lang.String name, Parameter[] parameters)
public boolean isDerivedFrom(ClassNode type)
type
- the ClassNode of interestpublic boolean isDerivedFromGroovyObject()
public boolean implementsInterface(ClassNode classNode)
classNode
- the class node for the interfacepublic boolean declaresInterface(ClassNode classNode)
classNode
- the class node for the interfacepublic ClassNode getSuperClass()
public ClassNode getUnresolvedSuperClass()
public ClassNode getUnresolvedSuperClass(boolean useRedirect)
public void setUnresolvedSuperClass(ClassNode sn)
public ClassNode[] getUnresolvedInterfaces()
public ClassNode[] getUnresolvedInterfaces(boolean useRedirect)
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 setterName)
public MethodNode getSetterMethod(java.lang.String setterName, boolean voidOnly)
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 java.lang.String toString(boolean showRedirect)
public boolean hasPossibleMethod(java.lang.String name, Expression arguments)
name
- the name of the method of interestarguments
- the arguments to match againstpublic MethodNode tryFindPossibleMethod(java.lang.String name, Expression arguments)
public boolean hasPossibleStaticMethod(java.lang.String name, Expression arguments)
name
- the name of the method of interestarguments
- the arguments to match againstpublic boolean isInterface()
public boolean isResolved()
public boolean isArray()
public ClassNode getComponentType()
public java.lang.Class getTypeClass()
getPlainNodeReference()
.public boolean hasPackageName()
public void setAnnotated(boolean flag)
flag
- public boolean isAnnotated()
public GenericsType[] getGenericsTypes()
public void setGenericsTypes(GenericsType[] genericsTypes)
public void setGenericsPlaceHolder(boolean b)
public boolean isGenericsPlaceHolder()
public boolean isUsingGenerics()
public void setUsingGenerics(boolean b)
public ClassNode getPlainNodeReference()
public boolean isAnnotationDefinition()
public java.util.List<AnnotationNode> getAnnotations()
getAnnotations
in class AnnotatedNode
public java.util.List<AnnotationNode> getAnnotations(ClassNode type)
getAnnotations
in class AnnotatedNode
public void addTransform(java.lang.Class<? extends ASTTransformation> transform, ASTNode node)
public java.util.Map<java.lang.Class<? extends ASTTransformation>,java.util.Set<ASTNode>> getTransforms(CompilePhase phase)
public void renameField(java.lang.String oldName, java.lang.String newName)
public void removeField(java.lang.String oldName)
public boolean isEnum()
public java.util.Iterator<InnerClassNode> getInnerClasses()
public boolean isRedirectNode()