Package org.codehaus.groovy.ast

# Class ModifierNode

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.ModifierNode

All Implemented Interfaces:
  `NodeMetaDataHandler`

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
  Modifier and Type
  Field
  Description
  `static final int`
  `ANNOTATION_TYPE`
  Pseudo-modifier type constant for annotations.
  `static final Map<Integer,Integer>`
  `MODIFIER_OPCODE_MAP`
  Maps modifier types (parser token types) to their corresponding ASM opcodes.

- ## Constructor Summary

  Constructors
  Constructor
  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.

- ## Method Summary

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

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

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

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

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

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

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

- ## Field Details

  - ### ANNOTATION_TYPE

    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.
    See Also:
      - Constant Field Values

  - ### MODIFIER_OPCODE_MAP

    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 Details

  - ### ModifierNode

    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`.
    Parameters:
      `type` - the modifier type (parser token type)
    Throws:
      `IllegalArgumentException` - if the type has no valid ASM opcode mapping

  - ### ModifierNode

    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.
    Parameters:
      `type` - the modifier type (parser token type)
      `text` - text of the ast node (source representation)
    Throws:
      `IllegalArgumentException` - if the type has no valid ASM opcode mapping

  - ### ModifierNode

    public ModifierNode(AnnotationNode annotationNode, String text)
    Creates a modifier node wrapping an annotation. Treats annotations as pseudo-modifiers for unified AST processing.
    Parameters:
      `annotationNode` - the annotation node to wrap
      `text` - text of the ast node (source representation)
    Throws:
      `IllegalArgumentException` - if annotationNode is null

- ## Method Details

  - ### isModifier

    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

  - ### isVisibilityModifier

    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

  - ### isNonVisibilityModifier

    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

  - ### isAnnotation

    public boolean isAnnotation()
    Checks whether this node represents an annotation (pseudo-modifier).
    Returns:
      true if this node wraps an annotation

  - ### isDef

    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

  - ### isVal

    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

  - ### getType

    public Integer getType()
    Returns the modifier type constant (parser token type).
    Returns:
      the type identifier for this modifier

  - ### getOpcode

    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

  - ### isRepeatable

    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)

  - ### getText

    public String getText()
    Returns the source text representation of this modifier. Preserves the exact text as it appeared in the source code.
    Overrides:
      `getText` in class `ASTNode`
    Returns:
      the source text of this modifier, or null if not set

  - ### getAnnotationNode

    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

  - ### equals

    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.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `o` - the object to compare
    Returns:
      true if both modifiers represent the same language construct

  - ### hashCode

    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.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      hash code based on type, text, and annotation

  - ### toString

    public String toString()
    Returns the string representation of this modifier. Returns the source text if available, otherwise delegates to `Object.toString()`.
    Overrides:
      `toString` in class `Object`
    Returns:
      the source text of this modifier