Class DeclaredParameter

java.lang.Object
org.daiitech.naftah.builtin.lang.Declaration
org.daiitech.naftah.builtin.lang.DeclaredParameter

public final class DeclaredParameter extends Declaration
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 Details

    • originalContext

      private final NaftahParser.ParameterDeclarationContext originalContext
      The original ANTLR context of the parameter declaration.
    • name

      private final String name
      The name of the parameter.
    • constant

      private final boolean constant
      Indicates whether the parameter is a constant.
    • type

      private final JavaType type
      The Java class representing the type of the parameter.
    • defaultValue

      private final Object defaultValue
      The default value assigned to the parameter.
    • currentValue

      private Object currentValue
      The current value of the parameter, if explicitly set.
    • updatedCurrentValue

      private boolean updatedCurrentValue
      Tracks 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 declared
      originalContext - the original parse context of the parameter
      name - the name of the parameter
      constant - whether the parameter is constant
      type - the type of the parameter
      defaultValue - 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 new DeclaredParameter.
      Parameters:
      depth - the depth of context where declared
      originalContext - the original parse context
      name - the parameter name
      constant - whether it is a constant
      type - the parameter type
      defaultValue - the default value
      Returns:
      a new instance of DeclaredParameter
    • getOriginalContext

      public NaftahParser.ParameterDeclarationContext getOriginalContext()
      Returns the original parse context for this parameter.
      Returns:
      the parameter's parse context
    • getName

      public String 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

      public JavaType getType()
      Returns the declared type of the parameter.
      Returns:
      the parameter type
    • getDefaultValue

      public Object getDefaultValue()
      Returns the default value of the parameter.
      Returns:
      the default value
    • getValue

      public Object getValue()
      Returns the current value of the parameter if set; otherwise returns the default value.
      Returns:
      the effective value of the parameter
    • setValue

      public void setValue(Object currentValue)
      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

      public String toString()
      Returns a string representation of the declared parameter using helper formatting.
      Overrides:
      toString in class Object
      Returns:
      the string representation