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.
| 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 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. |
| 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. |
| Methods inherited from class | Name |
|---|---|
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Pseudo-modifier type constant for annotations. Annotations are treated as modifiers in the AST for unified processing, distinguished by this sentinel type.
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.
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.
type - the modifier type (parser token type)Creates a modifier node with a specific text representation. Useful for preserving the exact source text of the modifier.
type - the modifier type (parser token type)text - text of the ast node (source representation)Creates a modifier node wrapping an annotation. Treats annotations as pseudo-modifiers for unified AST processing.
annotationNode - the annotation node to wraptext - text of the ast node (source representation)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.
o - the object to compareReturns the wrapped annotation node if this modifier represents an annotation. Only non-null for pseudo-modifiers created via ModifierNode(AnnotationNode, String).
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 source text representation of this modifier. Preserves the exact text as it appeared in the source code.
Returns the modifier type constant (parser token type).
Returns the hash code for this modifier. Consistent with equals(): identical modifiers have identical hash codes. Used for efficient storage in hash-based collections.
Checks whether this node represents an annotation (pseudo-modifier).
Checks whether this node represents a property or variable declaration modifier (def, val, or var). These are Groovy-specific pseudo-modifiers.
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.
Checks whether this is a non-visibility modifier (static, final, abstract, etc.). These modifiers can coexist with visibility modifiers.
Checks whether this modifier supports repetition (stacking). Only annotations are repeatable in Groovy; modifiers are mutually exclusive.
Checks whether this node specifically represents the 'val' modifier. In Groovy, 'val' declares a final variable (shorthand for final var).
Checks whether this modifier controls visibility (public, protected, private). Visibility modifiers are mutually exclusive and determine class/member access scope.
Returns the string representation of this modifier. Returns the source text if available, otherwise delegates to Object.toString.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.