Package org.codehaus.groovy.ast
Class InnerClassNode
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.ClassNode
org.codehaus.groovy.ast.InnerClassNode
- All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>,NodeMetaDataHandler
- Direct Known Subclasses:
EnumConstantClassNode,InterfaceHelperClassNode
Represents a nested (inner) class definition within an outer class.
Inner classes maintain a reference to their enclosing
ClassNode and support Groovy-specific
features such as variable scoping and anonymous class detection. Automatically marks inner classes
as static when defined in interfaces per JLS specifications.- See Also:
-
Field Summary
Fields inherited from class org.codehaus.groovy.ast.ClassNode
clazz, EMPTY_ARRAY, isPrimaryNode, lazyInitLock, SUPER, THISFields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
ConstructorsConstructorDescriptionInnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass) Creates an inner class with the specified outer class, name, modifiers, and superclass.InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins) Creates an inner class with the specified outer class, name, modifiers, superclass, interfaces, and mixins. -
Method Summary
Modifier and TypeMethodDescriptionReturns the class that encloses this inner class, or null if this is a top-level class.getOuterField(String name) Retrieves a field from the enclosing class by name, enabling access to outer class fields from within the inner class scope.Returns the outermost class in the nesting hierarchy by recursively traversing outer class references until reaching a class that has no outer class.Returns the variable scope associated with this inner class, tracking declarations and references for closure and method boundary analysis.booleanReturns whether this inner class represents an anonymous class (created with inline expressions).booleanisSealed()Checks if this inner class is sealed per JLS 15.9.5, returning false for anonymous classes since they cannot be further subclassed.voidsetAnonymous(boolean anonymous) Marks this inner class as anonymous if not already set.voidsetVariableScope(VariableScope scope) Sets the variable scope that manages variables declared and referenced within this inner class.Methods inherited from class org.codehaus.groovy.ast.ClassNode
addConstructor, addConstructor, addField, addField, addFieldFirst, addFieldFirst, addInterface, addMethod, addMethod, addMixin, addObjectInitializerStatements, addProperty, addProperty, addStaticInitializerStatements, addSyntheticMethod, addTransform, addTypeAnnotation, addTypeAnnotations, asGenericsType, declaresAnyInterfaces, declaresInterface, equals, getAbstractMethods, getAllDeclaredMethods, getAllInterfaces, getAnnotations, getAnnotations, getCompileUnit, getComponentType, getDeclaredConstructor, getDeclaredConstructors, getDeclaredField, getDeclaredMethod, getDeclaredMethods, getDeclaredMethodsMap, getEnclosingMethod, getField, getFieldIndex, getFields, getGenericsTypes, getGetterMethod, getGetterMethod, getInnerClasses, getInterfaces, getMethod, getMethods, getMethods, getMixins, getModifiers, getModule, getName, getNameWithoutPackage, getObjectInitializerStatements, getOuterClasses, getPackage, getPackageName, getPermittedSubclasses, getPlainNodeReference, getPlainNodeReference, getProperties, getProperty, getRecordComponents, getSetterMethod, getSetterMethod, getSuperClass, getText, getTransforms, getTypeAnnotations, getTypeAnnotations, getTypeClass, getUnresolvedInterfaces, getUnresolvedInterfaces, getUnresolvedName, getUnresolvedSuperClass, getUnresolvedSuperClass, hasDeclaredMethod, hashCode, hasMethod, hasPackageName, hasPossibleMethod, hasPossibleStaticMethod, hasProperty, implementsAnyInterfaces, implementsInterface, isAbstract, isAnnotated, isAnnotationDefinition, isArray, isDerivedFrom, isDerivedFromGroovyObject, isEnum, isGenericsPlaceHolder, isInterface, isPrimaryClassNode, isRecord, isRedirectNode, isResolved, isScript, isScriptBody, isStaticClass, isSyntheticPublic, isUsingGenerics, makeArray, parametersEqual, positionStmtsAfterEnumInitStmts, redirect, removeConstructor, removeField, removeMethod, renameField, setAnnotated, setCompileUnit, setEnclosingMethod, setGenericsPlaceHolder, setGenericsTypes, setInterfaces, setMixins, setModifiers, setModule, setName, setPermittedSubclasses, setRecordComponents, setRedirect, setScript, setScriptBody, setStaticClass, setSuperClass, setSyntheticPublic, setUnresolvedSuperClass, setUsingGenerics, toString, toString, tryFindPossibleMethod, visitContentsMethods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
InnerClassNode
Creates an inner class with the specified outer class, name, modifiers, and superclass.- Parameters:
outerClass- the enclosing class, or null for top-level classesname- the fully qualified name of the inner classmodifiers- theorg.objectweb.asm.Opcodesmodifiers for this classsuperClass- the superclass of this inner class, orClassNode.EMPTY_ARRAYfor Object- See Also:
-
Opcodes
-
InnerClassNode
public InnerClassNode(ClassNode outerClass, String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins) Creates an inner class with the specified outer class, name, modifiers, superclass, interfaces, and mixins. If the outer class is an interface, the inner class is automatically marked as static.- Parameters:
outerClass- the enclosing class, or null for top-level classesname- the fully qualified name of the inner classmodifiers- theorg.objectweb.asm.Opcodesmodifiers for this classsuperClass- the superclass of this inner classinterfaces- the interfaces implemented by this inner classmixins- the mixins applied to this inner class- See Also:
-
Opcodes
-
-
Method Details
-
getOuterClass
Returns the class that encloses this inner class, or null if this is a top-level class.- Overrides:
getOuterClassin classClassNode- Returns:
- the enclosing
ClassNode, or null - See Also:
-
getOuterMostClass
Returns the outermost class in the nesting hierarchy by recursively traversing outer class references until reaching a class that has no outer class.- Returns:
- the topmost
ClassNodein the nesting chain
-
getOuterField
Retrieves a field from the enclosing class by name, enabling access to outer class fields from within the inner class scope.- Overrides:
getOuterFieldin classClassNode- Parameters:
name- the field name to retrieve from the outer class- Returns:
- the
FieldNodefrom the outer class, or null if not found - See Also:
-
getVariableScope
Returns the variable scope associated with this inner class, tracking declarations and references for closure and method boundary analysis.- Returns:
- the
VariableScope, or null if not set - See Also:
-
setVariableScope
Sets the variable scope that manages variables declared and referenced within this inner class.- Parameters:
scope- theVariableScopeto associate with this inner class
-
isSealed
public boolean isSealed()Checks if this inner class is sealed per JLS 15.9.5, returning false for anonymous classes since they cannot be further subclassed. -
isAnonymous
public boolean isAnonymous()Returns whether this inner class represents an anonymous class (created with inline expressions).- Returns:
- true if this is an anonymous inner class
-
setAnonymous
public void setAnonymous(boolean anonymous) Marks this inner class as anonymous if not already set. Anonymous classes have restricted modifiers: static and abstract modifiers are removed, and final is removed for enums per JLS 15.9.5. Once set to anonymous, this state cannot be reverted.- Parameters:
anonymous- true to mark this inner class as anonymous- Throws:
IllegalArgumentException- if attempting to demote from anonymous to non-anonymous
-