|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.ast.ASTNode org.codehaus.groovy.ast.AnnotatedNode org.codehaus.groovy.ast.ClassNode
public class ClassNode extends AnnotatedNode
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 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:
Field Summary | |
---|---|
static ClassNode[] |
EMPTY_ARRAY
|
static ClassNode |
SUPER
|
static ClassNode |
THIS
|
protected java.lang.Class |
clazz
|
protected java.util.List |
innerClasses
|
protected boolean |
isPrimaryNode
|
protected java.lang.Object |
lazyInitLock
|
Method Summary | |
---|---|
java.lang.Object
|
ClassNode(java.lang.Class c)
|
java.lang.Object
|
ClassNode(java.lang.String name, int modifiers, ClassNode superClass)
|
java.lang.Object
|
ClassNode(java.lang.String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)
|
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)
|
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)
|
void
|
addTransform(java.lang.Class transform, ASTNode node)
|
boolean
|
declaresInterface(ClassNode classNode)
@return the ClassNode of the super class of this type |
boolean
|
equals(java.lang.Object o)
|
java.util.List
|
getAbstractMethods()
|
java.util.List
|
getAllDeclaredMethods()
|
java.util.Set
|
getAllInterfaces()
|
java.util.List
|
getAnnotations()
|
java.util.List
|
getAnnotations(ClassNode type)
|
CompileUnit
|
getCompileUnit()
|
ClassNode
|
getComponentType()
|
java.util.List
|
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 or any parent class. |
java.util.List
|
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
|
getDeclaredMethodsMap()
|
MethodNode
|
getEnclosingMethod()
|
FieldNode
|
getField(java.lang.String name)
@return the field node on the outer class or null if this is not an inner class |
java.util.List
|
getFields()
@return the array of interfaces which this ClassNode implements |
GenericsType[]
|
getGenericsTypes()
|
MethodNode
|
getGetterMethod(java.lang.String getterName)
|
java.util.Iterator
|
getInnerClasses()
|
ClassNode[]
|
getInterfaces()
|
MethodNode
|
getMethod(java.lang.String name, Parameter[] parameters)
@param type the ClassNode of interest |
java.util.List
|
getMethods()
@return the list of abstract methods associated with this ClassNode or null if there are no such methods |
java.util.List
|
getMethods(java.lang.String name)
|
MixinNode[]
|
getMixins()
@return the list of methods associated with this ClassNode |
int
|
getModifiers()
|
ModuleNode
|
getModule()
|
java.lang.String
|
getName()
|
java.lang.String
|
getNameWithoutPackage()
|
java.util.List
|
getObjectInitializerStatements()
|
ClassNode
|
getOuterClass()
|
FieldNode
|
getOuterField(java.lang.String name)
Helper method to avoid casting to inner class |
PackageNode
|
getPackage()
|
java.lang.String
|
getPackageName()
|
ClassNode
|
getPlainNodeReference()
|
java.util.List
|
getProperties()
|
PropertyNode
|
getProperty(java.lang.String name)
|
MethodNode
|
getSetterMethod(java.lang.String setterName)
Is this class declared in a static method (such as a closure / inner class declared in a static method) |
MethodNode
|
getSetterMethod(java.lang.String setterName, boolean voidOnly)
|
ClassNode
|
getSuperClass()
|
java.lang.String
|
getText()
|
java.util.Map
|
getTransforms(CompilePhase phase)
@return iterator of inner classes defined inside this one |
java.lang.Class
|
getTypeClass()
|
ClassNode[]
|
getUnresolvedInterfaces()
|
ClassNode[]
|
getUnresolvedInterfaces(boolean useRedirect)
|
java.lang.String
|
getUnresolvedName()
|
ClassNode
|
getUnresolvedSuperClass()
|
ClassNode
|
getUnresolvedSuperClass(boolean useRedirect)
|
boolean
|
hasDeclaredMethod(java.lang.String name, Parameter[] parameters)
@see #getDeclaredMethod(String, Parameter[]) |
boolean
|
hasMethod(java.lang.String name, Parameter[] parameters)
|
boolean
|
hasPackageName()
|
boolean
|
hasPossibleMethod(java.lang.String name, Expression 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)
|
int
|
hashCode()
|
boolean
|
implementsInterface(ClassNode classNode)
|
boolean
|
isAnnotated()
|
boolean
|
isAnnotationDefinition()
|
boolean
|
isArray()
|
boolean
|
isDerivedFrom(ClassNode type)
@return true if this class is derived from a groovy object i.e. it implements GroovyObject |
boolean
|
isDerivedFromGroovyObject()
|
boolean
|
isEnum()
|
boolean
|
isGenericsPlaceHolder()
|
boolean
|
isInterface()
Returns the concrete class this classnode relates to. |
boolean
|
isPrimaryClassNode()
@return true if this instance is a primary ClassNode |
boolean
|
isRedirectNode()
|
boolean
|
isResolved()
|
boolean
|
isScript()
|
boolean
|
isScriptBody()
|
boolean
|
isStaticClass()
|
boolean
|
isSyntheticPublic()
|
boolean
|
isUsingGenerics()
|
ClassNode
|
makeArray()
|
protected boolean
|
parametersEqual(Parameter[] a, Parameter[] b)
|
void
|
positionStmtsAfterEnumInitStmts(java.util.List staticFieldStatements)
|
ClassNode
|
redirect()
Sets this instance as proxy for the given ClassNode. |
void
|
removeField(java.lang.String oldName)
|
void
|
renameField(java.lang.String oldName, java.lang.String newName)
|
void
|
setAnnotated(boolean flag)
|
protected void
|
setCompileUnit(CompileUnit cu)
|
void
|
setEnclosingMethod(MethodNode enclosingMethod)
|
void
|
setGenericsPlaceHolder(boolean b)
|
void
|
setGenericsTypes(GenericsType[] genericsTypes)
|
void
|
setInterfaces(ClassNode[] interfaces)
@return the array of mixins associated with this ClassNode |
void
|
setModifiers(int modifiers)
|
void
|
setModule(ModuleNode module)
|
java.lang.String
|
setName(java.lang.String name)
|
void
|
setRedirect(ClassNode cn)
|
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)
|
Methods inherited from class AnnotatedNode | |
---|---|
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
public static final ClassNode[] EMPTY_ARRAY
public static final ClassNode SUPER
public static final ClassNode THIS
protected java.lang.Class clazz
protected java.util.List innerClasses
protected boolean isPrimaryNode
protected java.lang.Object lazyInitLock
Method Detail |
---|
public java.lang.Object ClassNode(java.lang.Class c)
public java.lang.Object ClassNode(java.lang.String name, int modifiers, ClassNode superClass)
public java.lang.Object ClassNode(java.lang.String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)
public void addConstructor(ConstructorNode node)
public ConstructorNode addConstructor(int modifiers, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public void addField(FieldNode node)
public FieldNode addField(java.lang.String name, int modifiers, ClassNode type, Expression initialValue)
public void addFieldFirst(FieldNode node)
public FieldNode addFieldFirst(java.lang.String name, int modifiers, ClassNode type, Expression initialValue)
public void addInterface(ClassNode type)
public void addMethod(MethodNode node)
public MethodNode addMethod(java.lang.String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public void addMixin(MixinNode mixin)
public void addObjectInitializerStatements(Statement statements)
public void addProperty(PropertyNode node)
public PropertyNode addProperty(java.lang.String name, int modifiers, ClassNode type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock)
public void addStaticInitializerStatements(java.util.List staticStatements, boolean fieldInit)
public MethodNode addSyntheticMethod(java.lang.String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)
public void addTransform(java.lang.Class transform, ASTNode node)
public boolean declaresInterface(ClassNode classNode)
public boolean equals(java.lang.Object o)
public java.util.List getAbstractMethods()
public java.util.List getAllDeclaredMethods()
public java.util.Set getAllInterfaces()
public java.util.List getAnnotations()
public java.util.List getAnnotations(ClassNode type)
public CompileUnit getCompileUnit()
public ClassNode getComponentType()
public java.util.List getDeclaredConstructors()
public FieldNode getDeclaredField(java.lang.String name)
name
- the name of the field of interest
public MethodNode getDeclaredMethod(java.lang.String name, Parameter[] parameters)
public java.util.List getDeclaredMethods(java.lang.String name)
public java.util.Map getDeclaredMethodsMap()
public MethodNode getEnclosingMethod()
public FieldNode getField(java.lang.String name)
public java.util.List getFields()
public GenericsType[] getGenericsTypes()
public MethodNode getGetterMethod(java.lang.String getterName)
public java.util.Iterator getInnerClasses()
public ClassNode[] getInterfaces()
public MethodNode getMethod(java.lang.String name, Parameter[] parameters)
type
- the ClassNode of interest
public java.util.List getMethods()
public java.util.List getMethods(java.lang.String name)
public MixinNode[] getMixins()
public int getModifiers()
public ModuleNode getModule()
public java.lang.String getName()
public java.lang.String getNameWithoutPackage()
public java.util.List getObjectInitializerStatements()
public ClassNode getOuterClass()
public FieldNode getOuterField(java.lang.String name)
public PackageNode getPackage()
public java.lang.String getPackageName()
public ClassNode getPlainNodeReference()
public java.util.List getProperties()
public PropertyNode getProperty(java.lang.String name)
public MethodNode getSetterMethod(java.lang.String setterName)
public MethodNode getSetterMethod(java.lang.String setterName, boolean voidOnly)
public ClassNode getSuperClass()
public java.lang.String getText()
public java.util.Map getTransforms(CompilePhase phase)
public java.lang.Class getTypeClass()
public ClassNode[] getUnresolvedInterfaces()
public ClassNode[] getUnresolvedInterfaces(boolean useRedirect)
public java.lang.String getUnresolvedName()
public ClassNode getUnresolvedSuperClass()
public ClassNode getUnresolvedSuperClass(boolean useRedirect)
public boolean hasDeclaredMethod(java.lang.String name, Parameter[] parameters)
public boolean hasMethod(java.lang.String name, Parameter[] parameters)
public boolean hasPackageName()
public boolean hasPossibleMethod(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 against
public boolean hasProperty(java.lang.String name)
public int hashCode()
public boolean implementsInterface(ClassNode classNode)
public boolean isAnnotated()
public boolean isAnnotationDefinition()
public boolean isArray()
public boolean isDerivedFrom(ClassNode type)
public boolean isDerivedFromGroovyObject()
public boolean isEnum()
public boolean isGenericsPlaceHolder()
public boolean isInterface()
public boolean isPrimaryClassNode()
public boolean isRedirectNode()
public boolean isResolved()
public boolean isScript()
public boolean isScriptBody()
public boolean isStaticClass()
public boolean isSyntheticPublic()
public boolean isUsingGenerics()
public ClassNode makeArray()
protected boolean parametersEqual(Parameter[] a, Parameter[] b)
public void positionStmtsAfterEnumInitStmts(java.util.List staticFieldStatements)
public ClassNode redirect()
cn
- the class to redirect to. If set to null the redirect will be removed
public void removeField(java.lang.String oldName)
public void renameField(java.lang.String oldName, java.lang.String newName)
public void setAnnotated(boolean flag)
protected void setCompileUnit(CompileUnit cu)
public void setEnclosingMethod(MethodNode enclosingMethod)
public void setGenericsPlaceHolder(boolean b)
public void setGenericsTypes(GenericsType[] genericsTypes)
public void setInterfaces(ClassNode[] interfaces)
public void setModifiers(int modifiers)
public void setModule(ModuleNode module)
public java.lang.String setName(java.lang.String name)
public void setRedirect(ClassNode cn)
public void setScript(boolean script)
public void setScriptBody(boolean scriptBody)
public void setStaticClass(boolean staticClass)
public void setSuperClass(ClassNode superClass)
public void setSyntheticPublic(boolean syntheticPublic)
public void setUnresolvedSuperClass(ClassNode sn)
public void setUsingGenerics(boolean b)
public java.lang.String toString()
public java.lang.String toString(boolean showRedirect)
public MethodNode tryFindPossibleMethod(java.lang.String name, Expression arguments)
public void visitContents(GroovyClassVisitor visitor)
Groovy Documentation