Package: org.codehaus.groovy.ast

## [Java] Class Parameter

- org.codehaus.groovy.ast.Parameter

- All Implemented Interfaces and Traits:
    Variable

      public class Parameter
      extends AnnotatedNode
      implements Variable

  Represents a parameter in a method or constructor declaration. Parameters support optional type information (defaults to `java.lang.Object` if not specified), default values for optional parameters, and closure variable sharing. Parameters implement the Variable interface to integrate with variable scope tracking.

  See Also:
    Variable
    MethodNode
    ConstructorNode

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static Parameter[]` | `EMPTY_ARRAY` |

  - ### Constructor Summary

    Constructors
    Constructor and description
    `Parameter(ClassNode type, String name)` Creates a parameter with the specified type and name.
    `Parameter(ClassNode type, String name, Expression defaultValue)` Creates a parameter with a type, name, and default value expression.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Expression` | `getDefaultValue()` Returns the default value expression for this parameter, or null if no default is specified.
    `` | `public Expression` | `getInitialExpression()` Returns the default value expression for this parameter, or null if no default is specified.
    `` | `public int` | `getModifiers()` Returns the modifiers (access flags) for this parameter as per `org.objectweb.asm.Opcodes`.
    `` | `public String` | `getName()` Returns the parameter name.
    `` | `public ClassNode` | `getOriginType()` Returns the original type of this parameter before any wrapping of primitive types.
    `` | `public ClassNode` | `getType()` Returns the type of this parameter.
    `` | `public boolean` | `hasInitialExpression()` Returns true if this parameter has been assigned a default value expression.
    `` | `public boolean` | `isClosureSharedVariable()` Returns true if this parameter is a closure-shared variable, meaning it is captured and accessed by nested closures.
    `` | `public boolean` | `isDynamicTyped()` Returns true if this parameter has dynamic type information, meaning its type could not be determined at compile time.
    `` | `public boolean` | `isImplicit()` Returns true if this parameter is implicit in the source code, such as the receiver parameter in instance methods or parameters generated by the compiler.
    `` | `public boolean` | `isInStaticContext()` Returns true if this parameter is declared in a static context (static method or static initializer).
    `` | `public boolean` | `isReceiver()` Returns true if this parameter represents a receiver parameter (named "this") as specified by JSR 308.
    `` | `public void` | `setClosureSharedVariable(boolean inClosure)` Marks this parameter as being shared with nested closures, affecting how it is handled in bytecode generation and variable access patterns.
    `` | `public void` | `setInStaticContext(boolean inStaticContext)` Marks this parameter as being declared in a static context.
    `` | `public void` | `setInitialExpression(Expression init)` Sets the default value expression for this optional parameter.
    `` | `public void` | `setModifiers(int modifiers)` Sets the modifiers (access flags) for this parameter.
    `` | `public void` | `setOriginType(ClassNode cn)` Sets the original type of this parameter before primitive type wrapping.
    `` | `public void` | `setType(ClassNode type)` Sets the type of this parameter.
    `` | `public String` | `toString()`

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

- - ### Field Detail

    - #### public static final Parameter[] EMPTY_ARRAY

  - ### Constructor Detail

    - #### public Parameter(ClassNode type, String name)

      Creates a parameter with the specified type and name.

      Parameters:
        `type` - the ClassNode representing the parameter's type
        `name` - the parameter name (never null)

    - #### public Parameter(ClassNode type, String name, Expression defaultValue)

      Creates a parameter with a type, name, and default value expression. The parameter is marked as having a default value which makes it optional.

      Parameters:
        `type` - the ClassNode representing the parameter's type
        `name` - the parameter name (never null)
        `defaultValue` - an Expression providing the default value for this optional parameter

  - ### Method Detail

    - #### public Expression getDefaultValue()

      Returns the default value expression for this parameter, or null if no default is specified.

      Returns:
        the default value Expression, or null

    - #### public Expression getInitialExpression()

      Returns the default value expression for this parameter, or null if no default is specified. This is an alias for getDefaultValue().

      Returns:
        the default value Expression, or null

    - #### public int getModifiers()

      Returns the modifiers (access flags) for this parameter as per `org.objectweb.asm.Opcodes`. May include flags like `ACC_FINAL` or `ACC_MANDATED`.

      Returns:
        the modifier flags
      See Also:
        org.objectweb.asm.Opcodes

    - #### public String getName()

      Returns the parameter name.

      Returns:
        the name of this parameter

    - #### public ClassNode getOriginType()

      Returns the original type of this parameter before any wrapping of primitive types. This preserves the distinction between primitive and boxed types.

      Returns:
        the original ClassNode before primitive wrapping

    - #### public ClassNode getType()

      Returns the type of this parameter. If the type has not been set, a dynamic type is returned.

      Returns:
        the ClassNode representing this parameter's type

    - #### public boolean hasInitialExpression()

      Returns true if this parameter has been assigned a default value expression.

      Returns:
        true if a default value is present

    - #### public boolean isClosureSharedVariable()

      Returns true if this parameter is a closure-shared variable, meaning it is captured and accessed by nested closures.

      Returns:
        true if shared with closures

    - #### public boolean isDynamicTyped()

      Returns true if this parameter has dynamic type information, meaning its type could not be determined at compile time.

      Returns:
        true if dynamically typed

    - #### public boolean isImplicit()

      Returns true if this parameter is implicit in the source code, such as the receiver parameter in instance methods or parameters generated by the compiler. This is determined by the `ACC_MANDATED` modifier flag as per `java.lang.reflect.Parameter#isImplicit()`.

      Returns:
        true if this is an implicit parameter
      See Also:
        Parameter.isImplicit
      Since:
        5.0.0

    - #### public boolean isInStaticContext()

      Returns true if this parameter is declared in a static context (static method or static initializer).

      Returns:
        true if in a static context

    - #### public boolean isReceiver()

      Returns true if this parameter represents a receiver parameter (named "this") as specified by JSR 308. Receiver parameters allow annotations on instance method receivers.

      Returns:
        true if this is a receiver parameter
      Since:
        5.0.0

    - #### public void setClosureSharedVariable(boolean inClosure)

      Marks this parameter as being shared with nested closures, affecting how it is handled in bytecode generation and variable access patterns.

      Parameters:
        `inClosure` - true if this parameter is shared with closures

    - #### public void setInStaticContext(boolean inStaticContext)

      Marks this parameter as being declared in a static context.

      Parameters:
        `inStaticContext` - true if this parameter is in a static context

    - #### public void setInitialExpression(Expression init)

      Sets the default value expression for this optional parameter. If the expression is null, the parameter is marked as not having a default value.

      Parameters:
        `init` - the default value Expression, or null to remove a default value

    - #### public void setModifiers(int modifiers)

      Sets the modifiers (access flags) for this parameter.

      Parameters:
        `modifiers` - the modifier flags from `org.objectweb.asm.Opcodes`

    - #### public void setOriginType(ClassNode cn)

      Sets the original type of this parameter before primitive type wrapping.

      Parameters:
        `cn` - the original ClassNode

    - #### public void setType(ClassNode type)

      Sets the type of this parameter. If the type is dynamically typed, the parameter is marked as dynamically typed.

      Parameters:
        `type` - the ClassNode representing this parameter's type
      See Also:
        ClassHelper.isDynamicTyped

    - #### public String toString()