Package org.daiitech.naftah.builtin.lang
Class DeclaredParameter
java.lang.Object
org.daiitech.naftah.builtin.lang.Declaration
org.daiitech.naftah.builtin.lang.DeclaredParameter
Represents a parameter declared in a Naftah function.
A parameter can have a name, type, constant modifier, default value, and optionally a current value if it was updated after declaration.
Note: Setting a value on a constant parameter will throw an error.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanIndicates whether the parameter is a constant.private ObjectThe current value of the parameter, if explicitly set.private final ObjectThe default value assigned to the parameter.private final StringThe name of the parameter.private final NaftahParser.ParameterDeclarationContextThe original ANTLR context of the parameter declaration.private final JavaTypeThe Java class representing the type of the parameter.private booleanTracks whether the current value has been updated from the default.Fields inherited from class org.daiitech.naftah.builtin.lang.Declaration
depth -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeclaredParameter(int depth, NaftahParser.ParameterDeclarationContext originalContext, String name, boolean constant, JavaType type, Object defaultValue) Constructs a declared parameter with its definition details. -
Method Summary
Modifier and TypeMethodDescriptionReturns the default value of the parameter.getName()Returns the name of the parameter.Returns the original parse context for this parameter.getType()Returns the declared type of the parameter.getValue()Returns the current value of the parameter if set; otherwise returns the default value.booleanIndicates whether this parameter is a constant.static DeclaredParameterof(int depth, NaftahParser.ParameterDeclarationContext originalContext, String name, boolean constant, JavaType type, Object defaultValue) Factory method to create a newDeclaredParameter.voidSets the current value of the parameter.toString()Returns a string representation of the declared parameter using helper formatting.Methods inherited from class org.daiitech.naftah.builtin.lang.Declaration
getDepth
-
Field Details
-
originalContext
The original ANTLR context of the parameter declaration. -
name
The name of the parameter. -
constant
private final boolean constantIndicates whether the parameter is a constant. -
type
The Java class representing the type of the parameter. -
defaultValue
The default value assigned to the parameter. -
currentValue
The current value of the parameter, if explicitly set. -
updatedCurrentValue
private boolean updatedCurrentValueTracks whether the current value has been updated from the default.
-
-
Constructor Details
-
DeclaredParameter
private DeclaredParameter(int depth, NaftahParser.ParameterDeclarationContext originalContext, String name, boolean constant, JavaType type, Object defaultValue) Constructs a declared parameter with its definition details.- Parameters:
depth- the depth of context where declaredoriginalContext- the original parse context of the parametername- the name of the parameterconstant- whether the parameter is constanttype- the type of the parameterdefaultValue- the default value of the parameter
-
-
Method Details
-
of
public static DeclaredParameter of(int depth, NaftahParser.ParameterDeclarationContext originalContext, String name, boolean constant, JavaType type, Object defaultValue) Factory method to create a newDeclaredParameter.- Parameters:
depth- the depth of context where declaredoriginalContext- the original parse contextname- the parameter nameconstant- whether it is a constanttype- the parameter typedefaultValue- the default value- Returns:
- a new instance of
DeclaredParameter
-
getOriginalContext
Returns the original parse context for this parameter.- Returns:
- the parameter's parse context
-
getName
Returns the name of the parameter.- Returns:
- the parameter name
-
isConstant
public boolean isConstant()Indicates whether this parameter is a constant.- Returns:
- true if constant; false otherwise
-
getType
Returns the declared type of the parameter.- Returns:
- the parameter type
-
getDefaultValue
Returns the default value of the parameter.- Returns:
- the default value
-
getValue
Returns the current value of the parameter if set; otherwise returns the default value.- Returns:
- the effective value of the parameter
-
setValue
Sets the current value of the parameter. Throws an error if the parameter is constant.- Parameters:
currentValue- the new value to assign- Throws:
NaftahBugError- if attempting to modify a constant parameter
-
toString
Returns a string representation of the declared parameter using helper formatting.
-