Package org.codehaus.groovy.ast

# Class Parameter

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.Parameter

All Implemented Interfaces:
  `GroovydocHolder<AnnotatedNode>`, `NodeMetaDataHandler`, `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
  Modifier and Type
  Field
  Description
  `static final Parameter[]`
  `EMPTY_ARRAY`

  ### Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder

  `DOC_COMMENT`

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Expression`
  `getDefaultValue()`
  Returns the default value expression for this parameter, or null if no default is specified.
  `Expression`
  `getInitialExpression()`
  Returns the default value expression for this parameter, or null if no default is specified.
  `int`
  `getModifiers()`
  Returns the modifiers (access flags) for this parameter as per `org.objectweb.asm.Opcodes`.
  `String`
  `getName()`
  Returns the parameter name.
  `ClassNode`
  `getOriginType()`
  Returns the original type of this parameter before any wrapping of primitive types.
  `ClassNode`
  `getType()`
  Returns the type of this parameter.
  `boolean`
  `hasInitialExpression()`
  Returns true if this parameter has been assigned a default value expression.
  `boolean`
  `isClosureSharedVariable()`
  Returns true if this parameter is a closure-shared variable, meaning it is captured and accessed by nested closures.
  `boolean`
  `isDynamicTyped()`
  Returns true if this parameter has dynamic type information, meaning its type could not be determined at compile time.
  `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.
  `boolean`
  `isInStaticContext()`
  Returns true if this parameter is declared in a static context (static method or static initializer).
  `boolean`
  `isReceiver()`
  Returns true if this parameter represents a receiver parameter (named "this") as specified by JSR 308.
  `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.
  `void`
  `setInitialExpression(Expression init)`
  Sets the default value expression for this optional parameter.
  `void`
  `setInStaticContext(boolean inStaticContext)`
  Marks this parameter as being declared in a static context.
  `void`
  `setModifiers(int modifiers)`
  Sets the modifiers (access flags) for this parameter.
  `void`
  `setOriginType(ClassNode cn)`
  Sets the original type of this parameter before primitive type wrapping.
  `void`
  `setType(ClassNode type)`
  Sets the type of this parameter.
  `String`
  `toString()`

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

  `addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic`

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

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

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

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

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

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

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

  `isFinal, isPrivate, isProtected, isPublic, isStatic, isVolatile`

- ## Field Details

  - ### EMPTY_ARRAY

    public static final Parameter[] EMPTY_ARRAY

- ## Constructor Details

  - ### Parameter

    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)

  - ### Parameter

    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 Details

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getName

    public String getName()
    Returns the parameter name.
    Specified by:
      `getName` in interface `Variable`
    Returns:
      the name of this parameter

  - ### getType

    public ClassNode getType()
    Returns the type of this parameter. If the type has not been set, a dynamic type is returned.
    Specified by:
      `getType` in interface `Variable`
    Returns:
      the `ClassNode` representing this parameter's type

  - ### setType

    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(ClassNode)`

  - ### getDefaultValue

    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

  - ### hasInitialExpression

    public boolean hasInitialExpression()
    Returns true if this parameter has been assigned a default value expression.
    Specified by:
      `hasInitialExpression` in interface `Variable`
    Returns:
      true if a default value is present

  - ### getInitialExpression

    public Expression getInitialExpression()
    Returns the default value expression for this parameter, or null if no default is specified. This is an alias for `getDefaultValue()`.
    Specified by:
      `getInitialExpression` in interface `Variable`
    Returns:
      the default value `Expression`, or null

  - ### setInitialExpression

    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

  - ### isInStaticContext

    public boolean isInStaticContext()
    Returns true if this parameter is declared in a static context (static method or static initializer).
    Specified by:
      `isInStaticContext` in interface `Variable`
    Returns:
      true if in a static context

  - ### setInStaticContext

    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

  - ### isDynamicTyped

    public boolean isDynamicTyped()
    Returns true if this parameter has dynamic type information, meaning its type could not be determined at compile time.
    Specified by:
      `isDynamicTyped` in interface `Variable`
    Returns:
      true if dynamically typed

  - ### isClosureSharedVariable

    public boolean isClosureSharedVariable()
    Returns true if this parameter is a closure-shared variable, meaning it is captured and accessed by nested closures.
    Specified by:
      `isClosureSharedVariable` in interface `Variable`
    Returns:
      true if shared with closures

  - ### setClosureSharedVariable

    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.
    Specified by:
      `setClosureSharedVariable` in interface `Variable`
    Parameters:
      `inClosure` - true if this parameter is shared with closures

  - ### getModifiers

    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`.
    Specified by:
      `getModifiers` in interface `Variable`
    Returns:
      the modifier flags
    See Also:
      - `Opcodes`

  - ### setModifiers

    public void setModifiers(int modifiers)
    Sets the modifiers (access flags) for this parameter.
    Parameters:
      `modifiers` - the modifier flags from `org.objectweb.asm.Opcodes`

  - ### getOriginType

    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.
    Specified by:
      `getOriginType` in interface `Variable`
    Returns:
      the original `ClassNode` before primitive wrapping

  - ### setOriginType

    public void setOriginType(ClassNode cn)
    Sets the original type of this parameter before primitive type wrapping.
    Parameters:
      `cn` - the original `ClassNode`

  - ### isImplicit

    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
    Since:
      5.0.0
    See Also:
      - `Parameter.isImplicit()`

  - ### isReceiver

    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