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 boolean |
isPrimaryNode |
|
protected Object |
lazyInitLock |
| Constructor and description |
|---|
ClassNode(String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins)Constructs a primary ClassNode representing a class declaration with all components.
|
ClassNode(String name, int modifiers, ClassNode superClass)Constructs a primary ClassNode representing a class declaration with superclass.
|
ClassNode(Class<?> c)Constructs a non-primary ClassNode from a real Java class.
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addConstructor(ConstructorNode node) |
|
public ConstructorNode |
addConstructor(int modifiers, Parameter[] parameters, ClassNode[] exceptions, Statement code) |
|
public void |
addField(FieldNode node)Adds a FieldNode to this ClassNode. |
|
public FieldNode |
addField(String name, int modifiers, ClassNode type, Expression initialValue)Creates and adds a FieldNode to this ClassNode with the specified properties. |
|
public void |
addFieldFirst(FieldNode node)Adds a FieldNode to this ClassNode at the beginning of the field list. |
|
public FieldNode |
addFieldFirst(String name, int modifiers, ClassNode type, Expression initialValue)Creates and adds a FieldNode to the beginning of this ClassNode's field list with the specified properties. |
|
public void |
addInterface(ClassNode node)Adds an interface to the list of interfaces implemented by this ClassNode. |
|
public void |
addMethod(MethodNode node)Adds a MethodNode to this ClassNode. |
|
public MethodNode |
addMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)Creates and adds a MethodNode to this ClassNode with the specified properties, but only if a method with the same name and parameter signature does not already exist. |
|
public void |
addMixin(MixinNode node) |
|
public void |
addObjectInitializerStatements(Statement statement)Adds a statement to the object initializer. |
|
public void |
addProperty(PropertyNode node)Adds a PropertyNode to this ClassNode. |
|
public PropertyNode |
addProperty(String name, int modifiers, ClassNode type, Expression initialValue, Statement getterBlock, Statement setterBlock)Creates and adds a PropertyNode to this ClassNode with the specified properties, or returns an existing property with the same name if one is already present. |
|
public void |
addStaticInitializerStatements(List<Statement> statements, boolean fieldInit) |
|
public MethodNode |
addSyntheticMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code)Adds a synthetic method as part of the compilation process. |
|
public void |
addTransform(Class<? extends ASTTransformation> transform, ASTNode node) |
|
public void |
addTypeAnnotation(AnnotationNode annotation) |
|
public void |
addTypeAnnotations(List<AnnotationNode> annotations) |
|
public GenericsType |
asGenericsType() |
|
public boolean |
declaresAnyInterfaces(ClassNode classNodes)
|
|
public boolean |
declaresInterface(ClassNode classNode)
|
|
public boolean |
equals(Object that)Compares this ClassNode with another object for equality. |
|
public List<MethodNode> |
getAbstractMethods()Returns a list of all abstract MethodNodes declared in this ClassNode. |
|
public List<MethodNode> |
getAllDeclaredMethods()Returns all declared MethodNodes from this ClassNode and its superclasses and interfaces as a list. |
|
public Set<ClassNode> |
getAllInterfaces() |
|
public List<AnnotationNode> |
getAnnotations() |
|
public List<AnnotationNode> |
getAnnotations(ClassNode type) |
|
public CompileUnit |
getCompileUnit() |
|
public ClassNode |
getComponentType()Returns the component type of this array ClassNode. |
|
public ConstructorNode |
getDeclaredConstructor(Parameter[] parameters)
|
|
public List<ConstructorNode> |
getDeclaredConstructors() |
|
public FieldNode |
getDeclaredField(String name)Finds a FieldNode matching the given name declared directly in this class. |
|
public MethodNode |
getDeclaredMethod(String name, Parameter[] parameters)Finds a MethodNode matching the given name and parameter signature declared directly in this class. |
|
public List<MethodNode> |
getDeclaredMethods(String name)Returns a list of all MethodNodes with the given name declared directly in this class. |
|
public Map<String, MethodNode> |
getDeclaredMethodsMap()Returns all declared MethodNodes from this ClassNode and its superclasses and interfaces. |
|
public MethodNode |
getEnclosingMethod()Returns the enclosing MethodNode of this local inner class, or null
if this is not a local inner class. |
|
public FieldNode |
getField(String name)Finds a FieldNode matching the given name in this class or any of its superclasses. |
|
public Map<String, FieldNode> |
getFieldIndex()Returns the internal field index map for fast field lookup by name. |
|
public List<FieldNode> |
getFields()Returns all FieldNodes declared in this ClassNode, including inherited fields. |
|
public GenericsType[] |
getGenericsTypes()Returns the generic type parameters for this ClassNode, or null if none are defined.
|
|
public MethodNode |
getGetterMethod(String getterName)Finds a getter MethodNode matching the given name, optionally searching superclasses. |
|
public MethodNode |
getGetterMethod(String getterName, boolean searchSupers)Finds a getter MethodNode matching the given name, optionally searching superclasses and interfaces. |
|
public Iterator<InnerClassNode> |
getInnerClasses()Returns an iterator over the inner classes defined within this ClassNode. |
|
public ClassNode[] |
getInterfaces()
|
|
public MethodNode |
getMethod(String name, Parameter[] parameters)Finds a MethodNode matching the given name and parameter signature in this class or any of its superclasses. |
|
public List<MethodNode> |
getMethods()Returns all MethodNodes declared in this ClassNode, including inherited and synthetic methods. |
|
public List<MethodNode> |
getMethods(String name)Returns a list of all MethodNodes with the given name from this class and its superclasses. |
|
public MixinNode[] |
getMixins()
|
|
public int |
getModifiers()Returns the modifier flags for this ClassNode, combining visibility and behavioral modifiers. |
|
public ModuleNode |
getModule() |
|
public String |
getName()Returns the fully-qualified name of this class after following any redirects. |
|
public String |
getNameWithoutPackage() |
|
public List<Statement> |
getObjectInitializerStatements() |
|
public ClassNode |
getOuterClass()Returns the outer class of this ClassNode, or null if this is not an inner class.
|
|
public List<ClassNode> |
getOuterClasses()Returns a list of all outer classes enclosing this ClassNode in hierarchical order. |
|
public FieldNode |
getOuterField(String name)
|
|
public PackageNode |
getPackage() |
|
public String |
getPackageName() |
|
public List<ClassNode> |
getPermittedSubclasses()
|
|
public ClassNode |
getPlainNodeReference() |
|
public ClassNode |
getPlainNodeReference(boolean skipPrimitives) |
|
public List<PropertyNode> |
getProperties()Returns all PropertyNodes declared in this ClassNode. |
|
public PropertyNode |
getProperty(String name)Finds a PropertyNode matching the given name in this ClassNode. |
|
public List<RecordComponentNode> |
getRecordComponents()Gets the record components of record type. |
|
public MethodNode |
getSetterMethod(String setterName)Finds a setter MethodNode matching the given name, optionally searching superclasses. |
|
public MethodNode |
getSetterMethod(String setterName, boolean voidOnly)Finds a setter MethodNode matching the given name. |
|
public ClassNode |
getSuperClass()
|
|
public String |
getText() |
|
public Map<Class<? extends ASTTransformation>, Set<ASTNode>> |
getTransforms(CompilePhase phase) |
|
public List<AnnotationNode> |
getTypeAnnotations() |
|
public List<AnnotationNode> |
getTypeAnnotations(ClassNode type) |
|
public Class |
getTypeClass()Returns the concrete class this classnode relates to. |
|
public ClassNode[] |
getUnresolvedInterfaces()Returns the unresolved interfaces implemented by this ClassNode, using redirect resolution by default. |
|
public ClassNode[] |
getUnresolvedInterfaces(boolean deref)Returns the unresolved interfaces implemented by this ClassNode with optional redirect resolution. |
|
public String |
getUnresolvedName() |
|
public ClassNode |
getUnresolvedSuperClass()Returns the unresolved super class of this ClassNode, using redirect resolution by default. |
|
public ClassNode |
getUnresolvedSuperClass(boolean deref)Returns the unresolved super class of this ClassNode with optional redirect resolution. |
|
public boolean |
hasDeclaredMethod(String name, Parameter[] parameters)Tests whether a method with the given name and parameter signature is declared directly in this class (not inherited from a superclass). |
|
public boolean |
hasMethod(String name, Parameter[] parameters)Tests whether a method with the given name and parameter signature exists in this class or any of its superclasses. |
|
public boolean |
hasPackageName() |
|
public boolean |
hasPossibleMethod(String name, Expression arguments)Determines if the type has a possibly-matching instance method with the given name and arguments. |
|
public boolean |
hasPossibleStaticMethod(String name, Expression arguments)Checks if the given method has a possibly matching static method with the given name and arguments. |
|
public boolean |
hasProperty(String name)Tests whether a property with the given name exists in this ClassNode. |
|
public int |
hashCode()Returns the hash code for this ClassNode. |
|
public boolean |
implementsAnyInterfaces(ClassNode classNodes)
|
|
public boolean |
implementsInterface(ClassNode classNode)
|
|
public boolean |
isAbstract()Returns whether this ClassNode represents an abstract class. |
|
public boolean |
isAnnotated()Returns whether this ClassNode has been marked as annotated. |
|
public boolean |
isAnnotationDefinition()Returns whether this ClassNode represents an annotation type (annotation definition). |
|
public boolean |
isArray()Determines whether this ClassNode represents an array type. |
|
public boolean |
isDerivedFrom(ClassNode type)
|
|
public boolean |
isDerivedFromGroovyObject()Returns whether this ClassNode represents a type that implements the GroovyObject interface.
|
|
public boolean |
isEnum()Returns whether this ClassNode represents an enumeration type. |
|
public boolean |
isGenericsPlaceHolder() |
|
public boolean |
isInterface()Returns whether this ClassNode represents an interface type. |
|
public boolean |
isPrimaryClassNode()Determines whether this ClassNode is a primary node or redirects to one. |
|
public boolean |
isRecord()Checks if the ClassNode instance represents a native record.
|
|
public boolean |
isRedirectNode()Returns whether this ClassNode is a redirect (proxy) node for another ClassNode. |
|
public boolean |
isResolved()Determines whether this ClassNode has been resolved to an actual Java class. |
|
public boolean |
isScript()Returns whether this ClassNode represents a Groovy script body. |
|
public boolean |
isScriptBody()Returns whether this inner class or closure was declared inside a script body. |
|
public boolean |
isSealed()
|
|
public boolean |
isStaticClass()Returns whether this inner class or closure was declared inside a static method context. |
|
public 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. |
|
public boolean |
isUsingGenerics() |
|
public ClassNode |
makeArray()Returns a ClassNode representing an array of the type represented by this. |
|
protected boolean |
parametersEqual(Parameter[] a, Parameter[] b) |
|
public void |
positionStmtsAfterEnumInitStmts(List<Statement> staticFieldInitializerStatements) |
|
public ClassNode |
redirect()Returns the ClassNode this node is a proxy for or the node itself.
|
|
public void |
removeConstructor(ConstructorNode node) |
|
public void |
removeField(String oldName)Removes the FieldNode with the given name from this ClassNode. |
|
public void |
removeMethod(MethodNode node)Removes the given MethodNode from this ClassNode. |
|
public void |
renameField(String oldName, String newName) |
|
public void |
setAnnotated(boolean annotated)Marks this ClassNode as having annotations attached to it. |
|
protected void |
setCompileUnit(CompileUnit cu) |
|
public void |
setEnclosingMethod(MethodNode enclosingMethod)Sets the enclosing MethodNode for this local inner class. |
|
public void |
setGenericsPlaceHolder(boolean placeholder) |
|
public void |
setGenericsTypes(GenericsType[] genericsTypes)Sets the generic type parameters for this ClassNode. |
|
public void |
setInterfaces(ClassNode[] interfaces)Sets the interfaces implemented by this ClassNode. |
|
public void |
setMixins(MixinNode[] mixins) |
|
public void |
setModifiers(int modifiers)Sets the modifier flags for this ClassNode. |
|
public void |
setModule(ModuleNode module) |
|
public String |
setName(String name)Sets the fully-qualified name of this class, delegating to the redirect if one exists. |
|
public void |
setPermittedSubclasses(List<ClassNode> permittedSubclasses) |
|
public void |
setRecordComponents(List<RecordComponentNode> recordComponents)Sets the record components for record type. |
|
public void |
setRedirect(ClassNode node)Sets this instance as a proxy for the given ClassNode, enabling deferred class resolution.
|
|
public void |
setScript(boolean script)Marks this ClassNode as a script or removes the script flag. |
|
public void |
setScriptBody(boolean scriptBody)Marks this inner class or closure as being declared inside a script body. |
|
public void |
setStaticClass(boolean staticClass)Marks this inner class or closure as being declared in a static method context. |
|
public void |
setSuperClass(ClassNode superClass)Sets the super class of this ClassNode. |
|
public void |
setSyntheticPublic(boolean syntheticPublic)Marks this ClassNode as having synthetic public visibility. |
|
public void |
setUnresolvedSuperClass(ClassNode superClass)Sets the unresolved super class for this ClassNode. |
|
public void |
setUsingGenerics(boolean usesGenerics) |
|
public String |
toString()Returns a string representation of this ClassNode for debugging and display purposes. |
|
public String |
toString(boolean showRedirect)Returns a string representation of this ClassNode with optional redirect information. |
|
public MethodNode |
tryFindPossibleMethod(String name, Expression arguments) |
|
public void |
visitContents(GroovyClassVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Constructs a primary ClassNode representing a class declaration with all components.
This constructor creates a new ClassNode that will be compiled by Groovy. The node represents
an actual source class definition with specified interfaces and mixins.
name - the fully-qualified name of the class (e.g., "com.example.MyClass")modifiers - the bytecode modifiers (flags from Modifier or org.objectweb.asm.Opcodes)superClass - the base class (ClassNode representing the parent type); use ClassHelper.OBJECT_TYPE if no direct base classinterfaces - array of ClassNode instances for interfaces implemented by this class; may be emptymixins - array of MixinNode instances to be mixed into this class; may be empty Constructs a primary ClassNode representing a class declaration with superclass.
This is a convenience constructor for creating classes with a single superclass and no interfaces or mixins.
It delegates to the full constructor with empty interface and mixin arrays.
name - the fully-qualified name of the class (e.g., "com.example.MyClass")modifiers - the bytecode modifiers (flags from Modifier or org.objectweb.asm.Opcodes)superClass - the base class (ClassNode representing the parent type); use ClassHelper.OBJECT_TYPE if no direct base class Constructs a non-primary ClassNode from a real Java class.
This constructor creates a ClassNode that represents an actual Java class loaded at runtime (not a Groovy source class).
The class information is lazily initialized from reflection, and the node will not be compiled by Groovy.
c - the Java class (Class) to wrap; must not be nullAdds a FieldNode to this ClassNode. The field is added to the end of the field list and its declaring class is set to this node's redirect target. The field is registered in the internal field index for fast lookup by name.
node - the FieldNode to add, must not be nullCreates and adds a FieldNode to this ClassNode with the specified properties. The field is initialized with the given name, modifiers, type, and optional initial value expression. This is a convenience method that creates a FieldNode and adds it via addField(FieldNode).
name - the name of the fieldmodifiers - the access modifiers for the field (e.g., ACC_PUBLIC, ACC_PRIVATE)type - the ClassNode representing the field's typeinitialValue - the initial value Expression, or null if no initializerAdds a FieldNode to this ClassNode at the beginning of the field list. This method is similar to addField(FieldNode) but prepends the field instead of appending it, which can be useful when field declaration order matters.
node - the FieldNode to add first, must not be nullCreates and adds a FieldNode to the beginning of this ClassNode's field list with the specified properties. This is a convenience method for adding fields where declaration order is significant.
name - the name of the fieldmodifiers - the access modifiers for the field (e.g., ACC_PUBLIC, ACC_PRIVATE)type - the ClassNode representing the field's typeinitialValue - the initial value Expression, or null if no initializerAdds an interface to the list of interfaces implemented by this ClassNode. If the interface is already implemented, this method has no effect. The interface is appended to the end of the current interfaces array.
node - the ClassNode representing the interface to addAdds a MethodNode to this ClassNode. The method is added to the internal methods list and registered by name in the methods map for fast lookup. The method's declaring class is set to this node's redirect target. This method does not check for duplicates.
node - the MethodNode to add, must not be null Creates and adds a MethodNode to this ClassNode with the specified properties,
but only if a method with the same name and parameter signature does not already exist.
If a matching method is already declared in this class, it is returned without adding a new one.
This method is useful for adding default method implementations (e.g., getProperty(),
invokeMethod()) where the class may already have a user-defined version.
name - the name of the methodmodifiers - the access modifiers (e.g., ACC_PUBLIC, ACC_STATIC)returnType - the ClassNode representing the return typeparameters - array of Parameters, or an empty array for no parametersexceptions - array of exception ClassNodes that the method declares, or an empty arraycode - the method body as a Statement, or nullAdds a statement to the object initializer.
statement - the statement to be addedAdds a PropertyNode to this ClassNode. The property's associated field is also added to the field list, and the property itself is registered in the properties list. The property's declaring class is set to this node's redirect target.
node - the PropertyNode to add, must not be null Creates and adds a PropertyNode to this ClassNode with the specified properties,
or returns an existing property with the same name if one is already present. If a property
with the given name exists, the method updates its getter block, setter block, and initial
value expression if they are currently null. This prevents duplicate properties while
allowing partial initialization across multiple calls.
name - the name of the propertymodifiers - the access modifiers for the property (e.g., ACC_PUBLIC, ACC_PRIVATE)type - the ClassNode representing the property's typeinitialValue - the initial value Expression, or null if no initializergetterBlock - the getter method's Statement body, or nullsetterBlock - the setter method's Statement body, or nullAdds a synthetic method as part of the compilation process.
classNodes - the class nodes for the interfacestrue if this type declares that it implements any of the
given interfaces or if one of its interfaces extends directly/indirectly
any of the given interfaces
classNode - the class node for the interfacetrue if this class declares that it implements the given
interface or if one of its interfaces extends directly/indirectly the interface
NOTE: Doesn't consider an interface to implement itself.
I think this is intended to be called on ClassNodes representing
classes, not interfaces.Compares this ClassNode with another object for equality. Two ClassNodes are considered equal if:
that - the object to compare with this ClassNodetrue if the objects represent the same class; false otherwiseReturns a list of all abstract MethodNodes declared in this ClassNode. Abstract methods are obtained from the declared methods map and filtered to return only those with the abstract modifier set. This includes abstract methods from superclasses and implemented interfaces.
Returns all declared MethodNodes from this ClassNode and its superclasses and interfaces as a list. This is a convenience method that collects all values from the declared methods map into a single list.
Returns the component type of this array ClassNode.
If this ClassNode does not represent an array type, returns null.
For array types, this returns the ClassNode representing the element type
(e.g., for "String[]", returns the ClassNode for "String").
null if not an array
nullFinds a FieldNode matching the given name declared directly in this class. This method does not search superclasses; to include inherited fields, use getField(String). If this node is a proxy (has a redirect), the call is forwarded to the redirect target.
name - the name of the field to findnull if not foundFinds a MethodNode matching the given name and parameter signature declared directly in this class. This method does not search superclasses; to include inherited methods, use getMethod(String, Parameter[]). Parameter matching is done by comparing parameter types using the parametersEqual(Parameter[], Parameter[]) method.
name - the name of the method to findparameters - an array of Parameters representing the method signature,
or null/empty for methods with no parametersnull if not foundReturns a list of all MethodNodes with the given name declared directly in this class. This method does not search superclasses; to include inherited methods, use getMethods(String). If this node is a proxy (has a redirect), the call is forwarded to the redirect target. The list may be empty if no methods with the given name are declared in this class.
name - the name of the methods to findReturns all declared MethodNodes from this ClassNode and its superclasses and interfaces. The methods are collected in a single map with method type descriptors as keys, allowing resolution of method overrides across the inheritance hierarchy. This method provides a complete view of all accessible methods.
Returns the enclosing MethodNode of this local inner class, or null
if this is not a local inner class. Local inner classes are those declared within method bodies.
If this ClassNode has a redirect, returns the enclosing method from the redirect.
nullFinds a FieldNode matching the given name in this class or any of its superclasses. This method searches the inheritance hierarchy starting from this ClassNode and moving up through superclasses until a field with the matching name is found.
name - the name of the field to findnull if not found in this class
or any superclassReturns the internal field index map for fast field lookup by name. This method is deprecated as field access should go through getField(String) or getDeclaredField(String). The field index is an internal implementation detail and may change in future versions.
null if no field index existsReturns all FieldNodes declared in this ClassNode, including inherited fields. If this node is a proxy (has a redirect), the call is forwarded to the redirect target. The returned list includes fields from this class only, not from super classes.
Returns the generic type parameters for this ClassNode, or null if none are defined.
Generic types represent type parameters and their bounds as declared in class definitions.
For example, in class List<T>, the GenericsType array would contain a single
element representing the type parameter T.
nullFinds a getter MethodNode matching the given name, optionally searching superclasses. A getter method is defined as a method with no parameters that returns a non-void type. For methods starting with "is", the return type must be boolean. Synthetic and bridge methods are disregarded in favor of the most specific real getter.
getterName - the name of the getter method to findnull if not foundFinds a getter MethodNode matching the given name, optionally searching superclasses and interfaces. A getter method is defined as a method with no parameters that returns a non-void type. For methods starting with "is", the return type must be boolean. Synthetic and bridge methods are disregarded in favor of the most specific real getter.
getterName - the name of the getter method to findsearchSupers - if true, searches superclasses and interfaces for the getter;
if false, searches only methods declared in this classnull if not foundReturns an iterator over the inner classes defined within this ClassNode. The iterator is backed by an unmodifiable view of the inner classes list. Returns an empty iterator if this class has no inner classes defined.
null
ClassNodeFinds a MethodNode matching the given name and parameter signature in this class or any of its superclasses. This method searches the inheritance hierarchy starting from this ClassNode. Parameter matching is done by comparing parameter types using the parametersEqual(Parameter[], Parameter[]) method.
name - the name of the method to findparameters - an array of Parameters representing the method signature,
or null/empty for methods with no parametersnull if not found
in this class or any superclassReturns all MethodNodes declared in this ClassNode, including inherited and synthetic methods. If this node is a proxy (has a redirect), the call is forwarded to the redirect target. This list includes constructors and all instance and static methods defined for this class.
Returns a list of all MethodNodes with the given name from this class and its superclasses. This method searches the inheritance hierarchy starting from this ClassNode and moving up through superclasses, collecting all methods with matching names. The list may be empty if no methods with the given name are found in the class hierarchy.
name - the name of the methods to find
ClassNode Returns the modifier flags for this ClassNode, combining visibility and behavioral modifiers.
The flags are represented as a bitmask using ASM/bytecode conventions (e.g., ACC_PUBLIC,
ACC_ABSTRACT, ACC_INTERFACE, ACC_ENUM). This method follows redirects
if present, ensuring the modifiers of the actual target ClassNode are returned.
Individual modifiers can be tested using bitwise AND operations with the ASM Opcodes constants.
Returns the fully-qualified name of this class after following any redirects. If this ClassNode is a proxy for another ClassNode, the name of the target is returned. The name remains consistent across all compilation phases for the redirected type.
Returns the outer class of this ClassNode, or null if this is not an inner class.
If this ClassNode has a redirect, returns the outer class from the redirect.
This method traverses the class hierarchy upward to find the immediately enclosing class.
null if not an inner classReturns a list of all outer classes enclosing this ClassNode in hierarchical order. The innermost outer class appears first in the list. Returns an empty list if this is not an inner class. If this ClassNode has a redirect, the list is derived from the redirect.
null if this is not an inner class
Returns all PropertyNodes declared in this ClassNode. If this node is a proxy (has a redirect), the call is forwarded to the redirect target. Properties are distinct from fields and represent a higher-level abstraction with getter/setter semantics.
Finds a PropertyNode matching the given name in this ClassNode. This method searches through the properties list, comparing by name. Only direct properties of this class are searched, not inherited ones.
name - the name of the property to findnull if not foundGets the record components of record type.
RecordComponentNode instancesFinds a setter MethodNode matching the given name, optionally searching superclasses. A setter method is defined as a method with exactly one parameter that returns void. This method searches from this class up the inheritance hierarchy until a matching setter is found.
setterName - the name of the setter method to findnull if not found Finds a setter MethodNode matching the given name. A setter method is defined as a method
with exactly one parameter. If voidOnly is true, the method must also return void.
The method searches this class and superclasses for the first matching setter.
setterName - the name of the setter method to findvoidOnly - if true, only returns setter methods that return void;
if false, accepts setters that return any typenull if not found
ClassNode of the super class of this typeReturns 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().
Returns the unresolved interfaces implemented by this ClassNode, using redirect resolution by default. The unresolved interfaces represent the raw interface hierarchy without applying redirect resolution. Returns an empty array if this class implements no interfaces.
null Returns the unresolved interfaces implemented by this ClassNode with optional redirect resolution.
When deref is true, resolves redirects recursively; otherwise returns the
raw interfaces stored in this ClassNode. Resolving may trigger lazy class initialization.
deref - true to apply redirect resolution, false to return raw interfacesnull Returns the unresolved super class of this ClassNode, using redirect resolution by default.
The unresolved super class represents the raw class hierarchy without applying redirect
resolution. Returns null if this class has no explicit superclass.
null Returns the unresolved super class of this ClassNode with optional redirect resolution.
When deref is true, resolves redirects recursively; otherwise returns the
raw superclass stored in this ClassNode. Resolving may trigger lazy class initialization.
deref - true to apply redirect resolution, false to return raw superclassnullTests whether a method with the given name and parameter signature is declared directly in this class (not inherited from a superclass). This is a convenience method for checking method existence.
name - the name of the method to checkparameters - an array of Parameters representing the method signature,
or null/empty for methods with no parameterstrue if a method with the given name and parameters is declared in this class,
false otherwiseTests whether a method with the given name and parameter signature exists in this class or any of its superclasses. This is a convenience method for checking method existence.
name - the name of the method to checkparameters - an array of Parameters representing the method signature,
or null/empty for methods with no parameterstrue if a method with the given name and parameters exists, false otherwiseDetermines if the type has a possibly-matching instance method with the given name and arguments.
name - the name of the method of interestarguments - the arguments to match againstChecks 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 againsttrue if a matching method was foundTests whether a property with the given name exists in this ClassNode. This method searches through the properties list, comparing by name.
name - the name of the property to checktrue if a property with the given name exists, false otherwiseReturns the hash code for this ClassNode. The hash code is based on the redirect's hash code if a redirect exists, or the text representation's hash code if this is a primary or array ClassNode. This ensures that equal ClassNodes (by equals(Object)) have equal hash codes, maintaining the hash code contract for use in hash-based collections.
classNodes - the class nodes for the interfacestrue if this type implements any of the given interfaces
classNode - the class node for the interfacetrue if this type implements the given interface Returns whether this ClassNode represents an abstract class.
A class is abstract if the ACC_ABSTRACT modifier flag is set in its modifiers.
Abstract classes cannot be instantiated directly; they serve as base types for subclasses.
This method checks the actual modifier bits, independent of the source code syntax.
true if this class has the abstract modifier set; false otherwise Returns whether this ClassNode has been marked as annotated.
This flag is set to true when annotations are added to the class via
addAnnotation(AnnotationNode) or related methods. It serves as a quick
indicator that the class carries metadata annotations, without requiring iteration
through the full annotations list. The flag does not distinguish between different
types of annotations (type annotations, method annotations, etc.).
true if this class has been marked as having annotations; false otherwise Returns whether this ClassNode represents an annotation type (annotation definition).
Annotation types are always interfaces with both the ACC_INTERFACE and ACC_ANNOTATION
modifier flags set. They define metadata that can be attached to program elements.
All annotation types are interfaces but not all interfaces are annotations.
true if this class is an annotation type; false otherwiseDetermines whether this ClassNode represents an array type. A ClassNode is an array if its component type has been set. The component type represents the element type of the array (e.g., "int" for "int[]", or "String" for "String[]").
true if this ClassNode represents an array type; false if it represents a scalar type
type - the ClassNode of interest Returns whether this ClassNode represents a type that implements the GroovyObject interface.
GroovyObject is the core interface that all Groovy objects implement, providing methods like
getProperty(), setProperty(), and invokeMethod() for dynamic behavior.
This method checks the class hierarchy to determine if GroovyObject is in the list of implemented interfaces.
true if this type directly or indirectly implements GroovyObject; false otherwise Returns whether this ClassNode represents an enumeration type.
An enum class has the ACC_ENUM modifier flag set in its modifiers.
Enumerations define a fixed set of named constants that can be iterated over at compile time.
true if this class is an enumeration; false otherwise Returns whether this ClassNode represents an interface type.
A class is an interface if the ACC_INTERFACE modifier flag is set in its modifiers.
Interfaces define contracts for implementing classes without providing implementation details.
Note that annotations are also interfaces (with the ACC_ANNOTATION flag also set).
true if this class is an interface; false if it is a regular class Determines whether this ClassNode is a primary node or redirects to one.
A primary ClassNode represents actual Groovy source code that will be compiled into bytecode.
Returns true if this node is primary or if its redirect target (or array component type)
is a primary ClassNode. Non-primary nodes are typically loaded via reflection.
true if this is a primary ClassNode or redirects to one; false if it only represents a reflected class Checks if the ClassNode instance represents a native record.
Check instead for the RecordBase annotation if looking for records and
record-like classes currently being compiled.
true if the instance represents a native recordReturns whether this ClassNode is a redirect (proxy) node for another ClassNode. A redirect node acts as a placeholder that forwards most method calls to its target ClassNode. This mechanism is used during compilation to defer class resolution until the actual target class is available. The actual target can be found using redirect().
true if this node redirects to another ClassNode; false if it is a standalone nodeDetermines whether this ClassNode has been resolved to an actual Java class. A ClassNode is considered resolved if it represents a real Class object loaded at runtime, or if it has been redirected to a resolved ClassNode, or if it represents an array of resolved component types. During early compilation phases, unresolved ClassNodes may reference types that haven't been loaded yet.
true if this ClassNode has been resolved to a real class; false if it still represents an unresolved reference Returns whether this ClassNode represents a Groovy script body.
A script is a special class that executes at the top level rather than requiring instantiation.
This method checks both the direct flag and whether the class derives from Script.
During compilation, script bodies are compiled into classes that extend the Script base class.
true if this class represents a script; false otherwiseReturns whether this inner class or closure was declared inside a script body. This flag distinguishes between inner classes/closures defined within a script's top-level code versus those defined within regular class methods. Script body context affects how local variable access and scoping rules are applied. This method follows redirects if present.
true if this inner class or closure is inside a script body; false otherwise
true for native and emulated (annotation based) sealed classesReturns whether this inner class or closure was declared inside a static method context. This flag identifies classes that are nested within static methods (as opposed to instance methods or top-level definitions). Inner classes in static contexts have different scoping rules and cannot access instance variables of the enclosing class. This method follows redirects if present.
true if this class is declared in a static method; false otherwiseIndicates that this class has been "promoted" to public by Groovy when in fact there was no public modifier explicitly in the source code. That is, it remembers that it has applied Groovy's "public classes by default" rule. This property is typically only of interest to AST transform writers.
true if node is public but had no explicit public modifier Returns a ClassNode representing an array of the type represented by this.
Returns the ClassNode this node is a proxy for or the node itself.
If this ClassNode has been set as a proxy to another ClassNode via setRedirect(ClassNode),
recursively follows the redirect chain to return the ultimate target ClassNode. If no redirect is set,
returns this. This mechanism allows lazy resolution of class references during compilation.
nullRemoves the FieldNode with the given name from this ClassNode. This method removes the field from the internal field list and index. If this node is a proxy (has a redirect), the operation is performed on the redirect target.
oldName - the name of the field to removeRemoves the given MethodNode from this ClassNode. The method is removed from the internal methods list and the methods map. If this node is a proxy (has a redirect), the operation is performed on the redirect target.
node - the MethodNode to remove Marks this ClassNode as having annotations attached to it.
This flag is used internally by the compiler to track whether annotations have been added
to the class. It should be set to true when annotations are added and may be used
as an optimization to avoid scanning the annotations list for empty cases.
annotated - true to mark as having annotations; false to clear the flagSets the enclosing MethodNode for this local inner class. This is typically called when processing classes declared within method bodies.
enclosingMethod - the MethodNode enclosing this class, or nullSets the generic type parameters for this ClassNode. Setting generics types updates the generics usage indicator for this class. This method is typically called during compiler phases when type information becomes available.
genericsTypes - an array of GenericsType representing the type parameters, or nullSets the interfaces implemented by this ClassNode. If this ClassNode has a redirect, the interfaces are set on the redirect instead. Updates the generics usage indicator if any interface uses generics and this is a primary ClassNode.
interfaces - an array of ClassNode representing the interfaces, or null Sets the modifier flags for this ClassNode.
The modifiers are a bitmask of ASM/bytecode convention flags (e.g., ACC_PUBLIC,
ACC_ABSTRACT, ACC_INTERFACE, ACC_ENUM). Calling this method
directly on a redirect node updates the redirect's modifiers instead of this node's.
Use this method to control visibility and structural attributes like abstractness or finality.
modifiers - the new modifier flags as a bitmaskSets the fully-qualified name of this class, delegating to the redirect if one exists. Allows the class name to be updated after construction, which is occasionally used during AST transformation phases. Changes are propagated to the redirect target if present.
name - the new fully-qualified class name to setSets the record components for record type.
Sets this instance as a proxy for the given ClassNode, enabling deferred class resolution.
After calling this method, most operations on this ClassNode are forwarded to the target ClassNode.
Redirect is only allowed for non-primary ClassNodes (see isPrimaryClassNode()).
If the target is null, the redirect is removed, making this node standalone again.
node - the ClassNode to redirect to; if null the redirect is cleared Marks this ClassNode as a script or removes the script flag.
Setting this to true indicates that this class represents a Groovy script
that should be executed at the top level. This is used internally during compilation
to identify script classes that need special treatment (e.g., extending the Script base class).
script - true to mark as a script; false to unmark Marks this inner class or closure as being declared inside a script body.
When set to true, indicates that the class definition occurs at the top level
of a Groovy script (outside of any method or class definition). This affects variable
scoping and how the compiler generates code for accessing enclosing scope variables.
Typically used by the compiler during script class generation.
scriptBody - true to mark as defined in script body; false otherwise Marks this inner class or closure as being declared in a static method context.
When set to true, indicates that this class definition occurs within a static method,
affecting how the compiler generates access to enclosing class members. Static inner classes
have restricted access to the enclosing class (only to static members).
staticClass - true to mark as defined in a static context; false otherwiseSets the super class of this ClassNode. If this ClassNode has a redirect, the super class is set on the redirect instead. Updates the generics usage indicator if the super class uses generics and this is a primary ClassNode.
superClass - the ClassNode representing the super class, or null Marks this ClassNode as having synthetic public visibility.
When set to true, indicates that this class was implicitly made public by Groovy's
default visibility rule rather than having an explicit public modifier in the source code.
This distinction is important for AST transformations that need to preserve the original intent
regarding visibility and access control.
syntheticPublic - true if public was added by the compiler; false if explicitly declaredSets the unresolved super class for this ClassNode. This method sets the raw superclass without applying any redirect resolution.
superClass - the ClassNode representing the super class, or null Returns a string representation of this ClassNode for debugging and display purposes.
For array types, appends "[]" to the component type's string representation.
For generic types, includes generic type parameters (e.g., "List
Returns a string representation of this ClassNode with optional redirect information.
For array types, appends "[]" to the component type's string representation.
For generic types, includes generic type parameters (e.g., "ListshowRedirect is true and this is a redirect node, includes arrow notation
showing the redirect target; otherwise the redirect information is omitted.
showRedirect - if true, includes redirect information in the output; if false, omits it
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.