Package org.codehaus.groovy.ast

# Class FieldNode

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.FieldNode

All Implemented Interfaces:
  `GroovydocHolder<AnnotatedNode>`, `NodeMetaDataHandler`, `Variable`

public class FieldNode extends AnnotatedNode implements Variable
Represents a field (member variable)

- ## Field Summary

  ### Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder

  `DOC_COMMENT`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `FieldNode()`
  ``
  `FieldNode(String name, int modifiers, ClassNode type, ClassNode owner, Expression initialValueExpression)`
  Creates a field node representing a class member variable.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  `Expression`
  `getInitialExpression()`
  Returns the initial value expression for this field.
  `Expression`
  `getInitialValueExpression()`
  Returns the initial value expression for this field.
  `int`
  `getModifiers()`
  Returns the ASM modifier flags for this field.
  `String`
  `getName()`
  Returns the field name.
  `ClassNode`
  `getOriginType()`
  Returns the original declared type of this field before any transformations.
  `ClassNode`
  `getOwner()`
  Returns the class that declares this field.
  `ClassNode`
  `getType()`
  Returns the declared type of this field as a `ClassNode`.
  `boolean`
  `hasInitialExpression()`
  Checks whether this field has an initial value expression.
  `boolean`
  `isDynamicTyped()`
  Checks whether this field's type is dynamically typed (unresolved type).
  `boolean`
  `isEnum()`
  Checks whether this field is an enum constant.
  `boolean`
  `isHolder()`
  Checks whether this field is a holder field.
  `boolean`
  `isInStaticContext()`
  Checks whether this field is in a static context.
  `static FieldNode`
  `newStatic(Class theClass, String name)`
  Creates a new FieldNode wrapping a reflection Field from a Java class.
  `void`
  `rename(String name)`
  Renames this field within its declaring class.
  `void`
  `setHolder(boolean holder)`
  Marks this field as a holder field for internal compilation purposes.
  `void`
  `setInitialValueExpression(Expression initialValueExpression)`
  Sets the initial value expression for this field.
  `void`
  `setModifiers(int modifiers)`
  Sets the ASM modifier flags for this field.
  `void`
  `setOriginType(ClassNode cn)`
  Sets the original type information for this field.
  `void`
  `setOwner(ClassNode owner)`
  Sets the class that declares this field.
  `void`
  `setType(ClassNode type)`
  Sets the field's type.

  ### Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode

  `addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

  ### Methods inherited from interface org.codehaus.groovy.ast.Variable

  `isClosureSharedVariable, isFinal, isPrivate, isProtected, isPublic, isStatic, isVolatile, setClosureSharedVariable`

- ## Constructor Details

  - ### FieldNode

    public FieldNode(String name, int modifiers, ClassNode type, ClassNode owner, Expression initialValueExpression)
    Creates a field node representing a class member variable. The field's type can be dynamically determined based on the provided ClassNode.
    Parameters:
      `name` - the field name
      `modifiers` - ASM modifier flags (public, static, final, etc.)
      `type` - the field's `ClassNode` type
      `owner` - the `ClassNode` that declares this field
      `initialValueExpression` - optional initial value expression (null for no initializer)

  - ### FieldNode

    protected FieldNode()

- ## Method Details

  - ### newStatic

    public static FieldNode newStatic(Class theClass, String name) throws SecurityException, NoSuchFieldException
    Creates a new FieldNode wrapping a reflection Field from a Java class. Extracts type information from the reflected field and creates an AST representation with public static access modifiers matching the source field.
    Parameters:
      `theClass` - the class containing the reflected field
      `name` - the field name
    Returns:
      a new FieldNode representing the reflected field
    Throws:
      `SecurityException` - if field access is denied
      `NoSuchFieldException` - if the field does not exist

  - ### getInitialExpression

    public Expression getInitialExpression()
    Returns the initial value expression for this field. The expression is evaluated when the field is initialized. Returns null if no initializer is present.
    Specified by:
      `getInitialExpression` in interface `Variable`
    Returns:
      the `Expression` providing the initial value, or null

  - ### getName

    public String getName()
    Returns the field name.
    Specified by:
      `getName` in interface `Variable`
    Returns:
      the field's identifier

  - ### getType

    public ClassNode getType()
    Returns the declared type of this field as a `ClassNode`. The type may be dynamically determined or may reference generics.
    Specified by:
      `getType` in interface `Variable`
    Returns:
      the field's type node

  - ### setType

    public void setType(ClassNode type)
    Sets the field's type. Updates both the current type and tracks the origin type. If the type is dynamic, marks this field as dynamically typed.
    Parameters:
      `type` - the field's `ClassNode` type

  - ### getOwner

    public ClassNode getOwner()
    Returns the class that declares this field.
    Returns:
      the declaring `ClassNode`, or null if not yet set

  - ### isHolder

    public boolean isHolder()
    Checks whether this field is a holder field. Holder fields are used internally for certain compilation strategies.
    Returns:
      true if this field is marked as a holder

  - ### setHolder

    public void setHolder(boolean holder)
    Marks this field as a holder field for internal compilation purposes.
    Parameters:
      `holder` - true to mark as a holder field

  - ### isDynamicTyped

    public boolean isDynamicTyped()
    Checks whether this field's type is dynamically typed (unresolved type). Dynamic typing occurs when the exact type cannot be determined at compile time.
    Specified by:
      `isDynamicTyped` in interface `Variable`
    Returns:
      true if this field uses dynamic typing

  - ### getModifiers

    public int getModifiers()
    Returns the ASM modifier flags for this field. Flags include visibility (public/protected/private), static, final, transient, volatile, etc.
    Specified by:
      `getModifiers` in interface `Variable`
    Returns:
      ASM opcode flags representing this field's modifiers
    See Also:
      - `Opcodes`

  - ### setModifiers

    public void setModifiers(int modifiers)
    Sets the ASM modifier flags for this field. Allows updating visibility or other modifier flags during compilation.
    Parameters:
      `modifiers` - ASM opcode flags to set

  - ### hasInitialExpression

    public boolean hasInitialExpression()
    Checks whether this field has an initial value expression.
    Specified by:
      `hasInitialExpression` in interface `Variable`
    Returns:
      true if an initializer expression is present

  - ### isInStaticContext

    public boolean isInStaticContext()
    Checks whether this field is in a static context. A field is in a static context if it has the static modifier.
    Specified by:
      `isInStaticContext` in interface `Variable`
    Returns:
      true if this field is static

  - ### isEnum

    public boolean isEnum()
    Checks whether this field is an enum constant. Enum constants are fields with the ACC_ENUM access flag.
    Returns:
      true if this field is an enum constant

  - ### setOwner

    public void setOwner(ClassNode owner)
    Sets the class that declares this field. Used during AST construction to establish the ownership relationship.
    Parameters:
      `owner` - the declaring `ClassNode`

  - ### getInitialValueExpression

    public Expression getInitialValueExpression()
    Returns the initial value expression for this field. Provides direct access to the initializer expression if one is defined.
    Returns:
      the `Expression` providing initial value, or null if absent

  - ### setInitialValueExpression

    public void setInitialValueExpression(Expression initialValueExpression)
    Sets the initial value expression for this field. The expression will be evaluated during field initialization.
    Parameters:
      `initialValueExpression` - the `Expression` for initialization, or null

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### getOriginType

    public ClassNode getOriginType()
    Returns the original declared type of this field before any transformations. Useful for preserving type information through compilation phases that may modify types.
    Specified by:
      `getOriginType` in interface `Variable`
    Returns:
      the `ClassNode` representing the original type

  - ### setOriginType

    public void setOriginType(ClassNode cn)
    Sets the original type information for this field. Typically set during type transformation to preserve original type metadata.
    Parameters:
      `cn` - the original `ClassNode` type

  - ### rename

    public void rename(String name)
    Renames this field within its declaring class. Updates both the AST node and the declaring class's field registry.
    Parameters:
      `name` - the new field name