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:
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.
| Modifiers | Name | Description |
|---|---|---|
static ClassNode[] |
EMPTY_ARRAY |
|
static ClassNode |
SUPER |
|
static ClassNode |
THIS |
|
protected Class |
clazz |
|
protected List |
innerClasses |
|
protected boolean |
isPrimaryNode |
|
protected Object |
lazyInitLock |
| Type | Name and description |
|---|---|
def |
ClassNode(Class c) |
def |
ClassNode(String name, int modifiers, ClassNode superClass) |
def |
ClassNode(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(String name, int modifiers, ClassNode type, Expression initialValue) |
void |
addFieldFirst(FieldNode node) |
FieldNode |
addFieldFirst(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, ClassNode[] exceptions, Statement code) |
void |
addMixin(MixinNode mixin) |
void |
addObjectInitializerStatements(Statement statements) |
void |
addProperty(PropertyNode node) |
PropertyNode |
addProperty(String name, int modifiers, ClassNode type, Expression initialValueExpression, Statement getterBlock, Statement setterBlock) |
void |
addStaticInitializerStatements(List staticStatements, boolean fieldInit) |
MethodNode |
addSyntheticMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code) |
void |
addTransform(Class transform, ASTNode node) |
boolean |
declaresInterface(ClassNode classNode)@return the ClassNode of the super class of this type |
boolean |
equals(Object o) |
List |
getAbstractMethods() |
List |
getAllDeclaredMethods() |
Set |
getAllInterfaces() |
List |
getAnnotations() |
List |
getAnnotations(ClassNode type) |
CompileUnit |
getCompileUnit() |
ClassNode |
getComponentType() |
List |
getDeclaredConstructors() |
FieldNode |
getDeclaredField(String name)Finds a field matching the given name in this class. |
MethodNode |
getDeclaredMethod(String name, Parameter[] parameters)Finds a method matching the given name and parameters in this class or any parent class. |
List |
getDeclaredMethods(String name)This methods returns a list of all methods of the given name defined in the current class |
Map |
getDeclaredMethodsMap() |
MethodNode |
getEnclosingMethod() |
FieldNode |
getField(String name)@return the field node on the outer class or null if this is not an inner class |
List |
getFields()@return the array of interfaces which this ClassNode implements |
GenericsType[] |
getGenericsTypes() |
MethodNode |
getGetterMethod(String getterName) |
Iterator |
getInnerClasses() |
ClassNode[] |
getInterfaces() |
MethodNode |
getMethod(String name, Parameter[] parameters)@param type the ClassNode of interest |
List |
getMethods()@return the list of abstract methods associated with this ClassNode or null if there are no such methods |
List |
getMethods(String name) |
MixinNode[] |
getMixins()@return the list of methods associated with this ClassNode |
int |
getModifiers() |
ModuleNode |
getModule() |
String |
getName() |
String |
getNameWithoutPackage() |
List |
getObjectInitializerStatements() |
ClassNode |
getOuterClass() |
FieldNode |
getOuterField(String name)Helper method to avoid casting to inner class |
PackageNode |
getPackage() |
String |
getPackageName() |
ClassNode |
getPlainNodeReference() |
List |
getProperties() |
PropertyNode |
getProperty(String name) |
MethodNode |
getSetterMethod(String setterName)Is this class declared in a static method (such as a closure / inner class declared in a static method) |
MethodNode |
getSetterMethod(String setterName, boolean voidOnly) |
ClassNode |
getSuperClass() |
String |
getText() |
Map |
getTransforms(CompilePhase phase)@return iterator of inner classes defined inside this one |
Class |
getTypeClass() |
ClassNode[] |
getUnresolvedInterfaces() |
ClassNode[] |
getUnresolvedInterfaces(boolean useRedirect) |
String |
getUnresolvedName() |
ClassNode |
getUnresolvedSuperClass() |
ClassNode |
getUnresolvedSuperClass(boolean useRedirect) |
boolean |
hasDeclaredMethod(String name, Parameter[] parameters)@see #getDeclaredMethod(String, Parameter[]) |
boolean |
hasMethod(String name, Parameter[] parameters) |
boolean |
hasPackageName() |
boolean |
hasPossibleMethod(String name, Expression arguments) |
boolean |
hasPossibleStaticMethod(String name, Expression arguments)Returns true if the given method has a possibly matching static method with the given name and arguments. |
boolean |
hasProperty(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(List staticFieldStatements) |
ClassNode |
redirect()Sets this instance as proxy for the given ClassNode. |
void |
removeField(String oldName) |
void |
removeMethod(MethodNode node) |
void |
renameField(String oldName, 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) |
String |
setName(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) |
String |
toString() |
String |
toString(boolean showRedirect) |
MethodNode |
tryFindPossibleMethod(String name, Expression arguments) |
void |
visitContents(GroovyClassVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class AnnotatedNode |
addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getNodeMetaData, getText, putNodeMetaData, removeNodeMetaData, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setNodeMetaData, setSourcePosition, visit |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Finds a field matching the given name in this class.
name - the name of the field of interestFinds a method matching the given name and parameters in this class or any parent class.
This methods returns a list of all methods of the given name defined in the current class
type - the ClassNode of interest
Is this class declared in a static method (such as a closure / inner class declared in a static method)
Returns true if the given method has a possibly matching static method with the given name and arguments.
name - the name of the method of interestarguments - the arguments to match against
Returns the concrete class this classnode relates to. However, this method is inherently unsafe as it may return null depending on the compile phase you are using. AST transformations should never use this method directly, but rather obtain a new class node using getPlainNodeReference().
Sets this instance as proxy for the given ClassNode.
cn - the class to redirect to. If set to null the redirect will be removed
Sets the superclass of this ClassNode