Package org.codehaus.groovy.ast
Class PropertyNode
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.PropertyNode
- All Implemented Interfaces:
GroovydocHolder<AnnotatedNode>,NodeMetaDataHandler,Variable
Represents a property (member variable, a getter and setter)
-
Field Summary
Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
ConstructorsConstructorDescriptionPropertyNode(String name, int modifiers, ClassNode type, ClassNode owner, Expression initialValueExpression, Statement getterBlock, Statement setterBlock) Creates a property node representing a Java property (field + getter/setter).PropertyNode(FieldNode field, int modifiers, Statement getterBlock, Statement setterBlock) Creates a property node from an existing field and getter/setter blocks. -
Method Summary
Modifier and TypeMethodDescriptiongetField()Returns the backing field node for this property.Returns the statement block that implements the getter method.Returns the explicitly set getter method name for this property.Returns the default getter method name for this property.Returns the initial value expression for this property (delegated to backing field).intReturns the ASM modifier flags for this property.getName()Returns the property name (delegated to backing field).Returns the original property type before any transformations (delegated to backing field).Returns the statement block that implements the setter method.Returns the explicitly set setter method name for this property.Returns the default setter method name for this property.getType()Returns the property type (delegated to backing field).booleanChecks whether this property has an initial value expression (delegated to backing field).booleanChecks whether this property has dynamic typing (delegated to backing field).booleanChecks whether this property is in a static context (delegated to backing field).voidSets the backing field node for this property.voidsetGetterBlock(Statement getterBlock) Sets the statement block that implements the getter method.voidsetGetterName(String getterName) Sets an explicit getter method name for this property.voidsetModifiers(int modifiers) Sets the ASM modifier flags for this property.voidsetSetterBlock(Statement setterBlock) Sets the statement block that implements the setter method.voidsetSetterName(String setterName) Sets an explicit setter method name for this property.voidSets the property type (updates backing field's type).Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaDataMethods inherited from interface org.codehaus.groovy.ast.Variable
isClosureSharedVariable, isFinal, isPrivate, isProtected, isPublic, isStatic, isVolatile, setClosureSharedVariable
-
Constructor Details
-
PropertyNode
public PropertyNode(String name, int modifiers, ClassNode type, ClassNode owner, Expression initialValueExpression, Statement getterBlock, Statement setterBlock) Creates a property node representing a Java property (field + getter/setter). The property is synthesized from a field name, type, and optionally initial value expression, with getter and setter blocks.- Parameters:
name- the property namemodifiers- ASM modifier flags (applied to the property, with static flag removed from field)type- the property type as aClassNodeowner- theClassNodethat declares this propertyinitialValueExpression- optional initial value expressiongetterBlock- optional statement block for the getter method bodysetterBlock- optional statement block for the setter method body
-
PropertyNode
Creates a property node from an existing field and getter/setter blocks. This constructor allows properties to be built from pre-existing field definitions.- Parameters:
field- theFieldNodebacking this propertymodifiers- ASM modifier flags for the propertygetterBlock- optional statement block for the getter method bodysetterBlock- optional statement block for the setter method body
-
-
Method Details
-
getField
Returns the backing field node for this property.- Returns:
- the
FieldNodeassociated with this property
-
setField
Sets the backing field node for this property.- Parameters:
field- theFieldNodeto associate with this property
-
getModifiers
public int getModifiers()Returns the ASM modifier flags for this property.- Specified by:
getModifiersin interfaceVariable- Returns:
- ASM opcode flags representing this property's modifiers
- See Also:
-
Opcodes
-
setModifiers
public void setModifiers(int modifiers) Sets the ASM modifier flags for this property.- Parameters:
modifiers- ASM opcode flags to set
-
getGetterBlock
Returns the statement block that implements the getter method. Returns null if no explicit getter implementation is provided.- Returns:
- the getter block statement, or null
-
setGetterBlock
Sets the statement block that implements the getter method.- Parameters:
getterBlock- the getter implementation statement
-
getSetterBlock
Returns the statement block that implements the setter method. Returns null if no explicit setter implementation is provided.- Returns:
- the setter block statement, or null
-
setSetterBlock
Sets the statement block that implements the setter method.- Parameters:
setterBlock- the setter implementation statement
-
getGetterName
Returns the explicitly set getter method name for this property. Returns null if no explicit name has been set (usegetGetterNameOrDefault()instead).- Returns:
- the explicit getter name, or null if not set
- Since:
- 4.0.0
-
setGetterName
Sets an explicit getter method name for this property. Overrides the default naming convention (getFoo/isFoo). Throws IllegalArgumentException if the name is null or empty.- Parameters:
getterName- the getter method name (non-null, non-empty)- Throws:
IllegalArgumentException- if name is null or empty- Since:
- 4.0.0
-
getSetterName
Returns the explicitly set setter method name for this property. Returns null if no explicit name has been set (usegetSetterNameOrDefault()instead).- Returns:
- the explicit setter name, or null if not set
- Since:
- 4.0.0
-
setSetterName
Sets an explicit setter method name for this property. Overrides the default naming convention (setFoo). Throws IllegalArgumentException if the name is null or empty.- Parameters:
setterName- the setter method name (non-null, non-empty)- Throws:
IllegalArgumentException- if name is null or empty- Since:
- 4.0.0
-
getName
Returns the property name (delegated to backing field). -
getType
Returns the property type (delegated to backing field). -
getOriginType
Returns the original property type before any transformations (delegated to backing field).- Specified by:
getOriginTypein interfaceVariable- Returns:
- the original
ClassNodetype
-
setType
Sets the property type (updates backing field's type).- Parameters:
t- the new propertyClassNodetype
-
getInitialExpression
Returns the initial value expression for this property (delegated to backing field).- Specified by:
getInitialExpressionin interfaceVariable- Returns:
- the initial value
Expression, or null if absent
-
hasInitialExpression
public boolean hasInitialExpression()Checks whether this property has an initial value expression (delegated to backing field).- Specified by:
hasInitialExpressionin interfaceVariable- Returns:
- true if an initializer expression is present
-
isInStaticContext
public boolean isInStaticContext()Checks whether this property is in a static context (delegated to backing field).- Specified by:
isInStaticContextin interfaceVariable- Returns:
- true if the backing field is static
-
isDynamicTyped
public boolean isDynamicTyped()Checks whether this property has dynamic typing (delegated to backing field).- Specified by:
isDynamicTypedin interfaceVariable- Returns:
- true if the backing field's type is dynamically typed
-
getGetterNameOrDefault
Returns the default getter method name for this property. If an explicit name has been set, returns that; otherwise returns the conventional name. For a propertyfoo, the default name isgetFooexcept for a boolean property whereisFoois the default if nogetFoomethod exists in the declaring class.- Returns:
- the getter method name (either explicit or default)
- Since:
- 4.0.0
-
getSetterNameOrDefault
Returns the default setter method name for this property. If an explicit name has been set, returns that; otherwise returns the conventional name. For a propertyfoo, the default name issetFoo.- Returns:
- the setter method name (either explicit or default)
- Since:
- 4.0.0
-