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
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:
-
Field Summary
FieldsFields inherited from interface groovy.lang.groovydoc.GroovydocHolder
DOC_COMMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the default value expression for this parameter, or null if no default is specified.Returns the default value expression for this parameter, or null if no default is specified.intReturns the modifiers (access flags) for this parameter as perorg.objectweb.asm.Opcodes.getName()Returns the parameter name.Returns the original type of this parameter before any wrapping of primitive types.getType()Returns the type of this parameter.booleanReturns true if this parameter has been assigned a default value expression.booleanReturns true if this parameter is a closure-shared variable, meaning it is captured and accessed by nested closures.booleanReturns true if this parameter has dynamic type information, meaning its type could not be determined at compile time.booleanReturns true if this parameter is implicit in the source code, such as the receiver parameter in instance methods or parameters generated by the compiler.booleanReturns true if this parameter is declared in a static context (static method or static initializer).booleanReturns true if this parameter represents a receiver parameter (named "this") as specified by JSR 308.voidsetClosureSharedVariable(boolean inClosure) Marks this parameter as being shared with nested closures, affecting how it is handled in bytecode generation and variable access patterns.voidSets the default value expression for this optional parameter.voidsetInStaticContext(boolean inStaticContext) Marks this parameter as being declared in a static context.voidsetModifiers(int modifiers) Sets the modifiers (access flags) for this parameter.voidSets the original type of this parameter before primitive type wrapping.voidSets the type of this parameter.toString()Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSyntheticMethods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaDataMethods inherited from interface org.codehaus.groovy.ast.Variable
isFinal, isPrivate, isProtected, isPublic, isStatic, isVolatile
-
Field Details
-
EMPTY_ARRAY
-
-
Constructor Details
-
Parameter
Creates a parameter with the specified type and name.- Parameters:
type- theClassNoderepresenting the parameter's typename- the parameter name (never null)
-
Parameter
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- theClassNoderepresenting the parameter's typename- the parameter name (never null)defaultValue- anExpressionproviding the default value for this optional parameter
-
-
Method Details
-
toString
-
getName
Returns the parameter name. -
getType
Returns the type of this parameter. If the type has not been set, a dynamic type is returned. -
setType
Sets the type of this parameter. If the type is dynamically typed, the parameter is marked as dynamically typed.- Parameters:
type- theClassNoderepresenting this parameter's type- See Also:
-
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:
hasInitialExpressionin interfaceVariable- Returns:
- true if a default value is present
-
getInitialExpression
Returns the default value expression for this parameter, or null if no default is specified. This is an alias forgetDefaultValue().- Specified by:
getInitialExpressionin interfaceVariable- Returns:
- the default value
Expression, or null
-
setInitialExpression
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 valueExpression, 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:
isInStaticContextin interfaceVariable- 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:
isDynamicTypedin interfaceVariable- Returns:
- true if dynamically typed
-
getModifiers
public int getModifiers()Returns the modifiers (access flags) for this parameter as perorg.objectweb.asm.Opcodes. May include flags likeACC_FINALorACC_MANDATED.- Specified by:
getModifiersin interfaceVariable- 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 fromorg.objectweb.asm.Opcodes
-
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:
getOriginTypein interfaceVariable- Returns:
- the original
ClassNodebefore primitive wrapping
-
setOriginType
Sets the original type of this parameter before primitive type wrapping.- Parameters:
cn- the originalClassNode
-
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 theACC_MANDATEDmodifier flag as perjava.lang.reflect.Parameter#isImplicit().- Returns:
- true if this is an implicit parameter
- Since:
- 5.0.0
- See Also:
-
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
-