Package: org.codehaus.groovy.ast

## [Java] Class FieldNode

- org.codehaus.groovy.ast.FieldNode

- All Implemented Interfaces and Traits:
    Variable

      public class FieldNode
      extends AnnotatedNode
      implements Variable

  Represents a field (member variable)

- - ### Constructor Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    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`

- - ### Constructor Detail

    - #### 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)

    - #### protected FieldNode()

  - ### Method Detail

    - #### public boolean equals(Object obj)

    - #### 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.

      Returns:
        the Expression providing the initial value, or null

    - #### 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

    - #### public int getModifiers()

      Returns the ASM modifier flags for this field. Flags include visibility (public/protected/private), static, final, transient, volatile, etc.

      Returns:
        ASM opcode flags representing this field's modifiers

    - #### public String getName()

      Returns the field name.

      Returns:
        the field's identifier

    - #### 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.

      Returns:
        the ClassNode representing the original type

    - #### public ClassNode getOwner()

      Returns the class that declares this field.

      Returns:
        the declaring ClassNode, or null if not yet set

    - #### public ClassNode getType()

      Returns the declared type of this field as a ClassNode. The type may be dynamically determined or may reference generics.

      Returns:
        the field's type node

    - #### public boolean hasInitialExpression()

      Checks whether this field has an initial value expression.

      Returns:
        true if an initializer expression is present

    - #### public int hashCode()

    - #### 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.

      Returns:
        true if this field uses dynamic typing

    - #### 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

    - #### 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

    - #### 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.

      Returns:
        true if this field is static

    - #### public static FieldNode newStatic(Class theClass, String name)

      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.

      throws:
        SecurityException if field access is denied
      throws:
        NoSuchFieldException if the field does not exist
      Parameters:
        `theClass` - the class containing the reflected field
        `name` - the field name
      Returns:
        a new FieldNode representing the reflected field

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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