Package: org.codehaus.groovy.ast

## [Java] Class ModifierNode

- org.codehaus.groovy.ast.ModifierNode

-     public class ModifierNode
      extends ASTNode

  Represents a modifier keyword or annotation in Groovy source code. ModifierNode wraps language modifiers (public, private, static, final, etc.) and treats annotations as pseudo-modifiers for consistent AST handling. Each modifier maps to an ASM opcode for bytecode generation.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static int` | `ANNOTATION_TYPE` | Pseudo-modifier type constant for annotations.
    `static Map<Integer, Integer>` | `MODIFIER_OPCODE_MAP` | Maps modifier types (parser token types) to their corresponding ASM opcodes.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ModifierNode(Integer type)` Creates a modifier node for the specified modifier type.
    `ModifierNode(Integer type, String text)` Creates a modifier node with a specific text representation.
    `ModifierNode(AnnotationNode annotationNode, String text)` Creates a modifier node wrapping an annotation.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `equals(Object o)` Compares this modifier with another object for equality.
    `` | `public AnnotationNode` | `getAnnotationNode()` Returns the wrapped annotation node if this modifier represents an annotation.
    `` | `public Integer` | `getOpcode()` Returns the ASM opcode corresponding to this modifier.
    `` | `public String` | `getText()` Returns the source text representation of this modifier.
    `` | `public Integer` | `getType()` Returns the modifier type constant (parser token type).
    `` | `public int` | `hashCode()` Returns the hash code for this modifier.
    `` | `public boolean` | `isAnnotation()` Checks whether this node represents an annotation (pseudo-modifier).
    `` | `public boolean` | `isDef()` Checks whether this node represents a property or variable declaration modifier (def, val, or var).
    `` | `public boolean` | `isModifier()` Checks whether this node represents a true modifier (not annotation or def).
    `` | `public boolean` | `isNonVisibilityModifier()` Checks whether this is a non-visibility modifier (static, final, abstract, etc.).
    `` | `public boolean` | `isRepeatable()` Checks whether this modifier supports repetition (stacking).
    `` | `public boolean` | `isVal()` Checks whether this node specifically represents the 'val' modifier.
    `` | `public boolean` | `isVisibilityModifier()` Checks whether this modifier controls visibility (public, protected, private).
    `` | `public String` | `toString()` Returns the string representation of this modifier.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Field Detail

    - #### public static final int ANNOTATION_TYPE

      Pseudo-modifier type constant for annotations. Annotations are treated as modifiers in the AST for unified processing, distinguished by this sentinel type.

    - #### public static final Map<Integer, Integer> MODIFIER_OPCODE_MAP

      Maps modifier types (parser token types) to their corresponding ASM opcodes. Enables conversion from source-level modifiers to bytecode-level access flags. Some modifiers (SEALED, NON_SEALED, DEFAULT, DEF, VAL, VAR) have no direct bytecode equivalent and map to 0.

  - ### Constructor Detail

    - #### public ModifierNode(Integer type)

      Creates a modifier node for the specified modifier type. The type corresponds to a parser token type and is mapped to an ASM opcode via MODIFIER_OPCODE_MAP.

      throws:
        IllegalArgumentException if the type has no valid ASM opcode mapping
      Parameters:
        `type` - the modifier type (parser token type)

    - #### public ModifierNode(Integer type, String text)

      Creates a modifier node with a specific text representation. Useful for preserving the exact source text of the modifier.

      throws:
        IllegalArgumentException if the type has no valid ASM opcode mapping
      Parameters:
        `type` - the modifier type (parser token type)
        `text` - text of the ast node (source representation)

    - #### public ModifierNode(AnnotationNode annotationNode, String text)

      Creates a modifier node wrapping an annotation. Treats annotations as pseudo-modifiers for unified AST processing.

      throws:
        IllegalArgumentException if annotationNode is null
      Parameters:
        `annotationNode` - the annotation node to wrap
        `text` - text of the ast node (source representation)

  - ### Method Detail

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

      Compares this modifier with another object for equality. Two modifiers are equal if they have the same type, text representation, and wrapped annotation. Used for deduplicating modifier nodes during AST processing.

      Parameters:
        `o` - the object to compare
      Returns:
        true if both modifiers represent the same language construct

    - #### public AnnotationNode getAnnotationNode()

      Returns the wrapped annotation node if this modifier represents an annotation. Only non-null for pseudo-modifiers created via ModifierNode(AnnotationNode, String).

      Returns:
        the AnnotationNode wrapped by this modifier, or null if this is a true modifier

    - #### public Integer getOpcode()

      Returns the ASM opcode corresponding to this modifier. Used during bytecode generation to set appropriate access flags. Returns 0 for modifiers without direct bytecode representation.

      Returns:
        the ASM Opcodes constant for this modifier

    - #### public String getText()

      Returns the source text representation of this modifier. Preserves the exact text as it appeared in the source code.

      Returns:
        the source text of this modifier, or null if not set

    - #### public Integer getType()

      Returns the modifier type constant (parser token type).

      Returns:
        the type identifier for this modifier

    - #### public int hashCode()

      Returns the hash code for this modifier. Consistent with equals(): identical modifiers have identical hash codes. Used for efficient storage in hash-based collections.

      Returns:
        hash code based on type, text, and annotation

    - #### public boolean isAnnotation()

      Checks whether this node represents an annotation (pseudo-modifier).

      Returns:
        true if this node wraps an annotation

    - #### public boolean isDef()

      Checks whether this node represents a property or variable declaration modifier (def, val, or var). These are Groovy-specific pseudo-modifiers.

      Returns:
        true if this is a def/val/var declaration modifier

    - #### public boolean isModifier()

      Checks whether this node represents a true modifier (not annotation or def). Distinguishes real modifiers (public, static, final, etc.) from pseudo-modifiers (annotations, def, val, var) that are treated as modifiers in the AST.

      Returns:
        true if this is a real modifier, false for annotations or def declarations

    - #### public boolean isNonVisibilityModifier()

      Checks whether this is a non-visibility modifier (static, final, abstract, etc.). These modifiers can coexist with visibility modifiers.

      Returns:
        true if this is a non-visibility modifier

    - #### public boolean isRepeatable()

      Checks whether this modifier supports repetition (stacking). Only annotations are repeatable in Groovy; modifiers are mutually exclusive.

      Returns:
        true if this modifier can appear multiple times (only for annotations)

    - #### public boolean isVal()

      Checks whether this node specifically represents the 'val' modifier. In Groovy, 'val' declares a final variable (shorthand for final var).

      Returns:
        true if this is the 'val' modifier
      Since:
        6.0.0

    - #### public boolean isVisibilityModifier()

      Checks whether this modifier controls visibility (public, protected, private). Visibility modifiers are mutually exclusive and determine class/member access scope.

      Returns:
        true if this is a visibility modifier

    - #### public String toString()

      Returns the string representation of this modifier. Returns the source text if available, otherwise delegates to Object.toString.

      Returns:
        the source text of this modifier