Class DeclaredImplementation

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

public final class DeclaredImplementation extends Declaration
Represents a declared implementation (similar to a class or object blueprint) in the Naftah scripting language.

A DeclaredImplementation encapsulates the original parse context, its name, object fields (variables), and the functions defined within the implementation.

This class extends Declaration and is immutable once created. It preserves the depth at which the implementation is declared, supporting scope resolution and context management.

Typical usage includes defining object fields and implementation-specific functions, and resolving them during execution or code analysis.

Author:
Chakib Daii
  • Field Details

    • originalContext

      private final NaftahParser.ImplementationDeclarationContext originalContext
      The original ANTLR parse context for the implementation declaration.
    • name

      private final String name
      The name of the implementation.
    • objectFields

      private final Map<String,DeclaredVariable> objectFields
      Map of object fields declared within this implementation. Keyed by field name.
    • implementationFunctions

      private final Map<String,DeclaredFunction<?>> implementationFunctions
      Map of functions declared within this implementation. Keyed by function name.
  • Constructor Details

    • DeclaredImplementation

      private DeclaredImplementation(int depth, NaftahParser.ImplementationDeclarationContext originalContext, Map<String,DeclaredVariable> objectFields, Map<String,DeclaredFunction<?>> implementationFunctions)
      Private constructor for creating a DeclaredImplementation.
      Parameters:
      depth - the depth in the context hierarchy where declared
      originalContext - the original ANTLR parse context
      objectFields - map of declared object fields
      implementationFunctions - map of declared functions
  • Method Details

    • of

      public static DeclaredImplementation of(int depth, NaftahParser.ImplementationDeclarationContext originalContext, Map<String,DeclaredVariable> objectFields, Map<String,DeclaredFunction<?>> implementationFunctions)
      Factory method to create a DeclaredImplementation.
      Parameters:
      depth - the depth in the context hierarchy
      originalContext - the original ANTLR parse context
      objectFields - map of object fields
      implementationFunctions - map of functions
      Returns:
      a new instance of DeclaredImplementation
    • getOriginalContext

      public NaftahParser.ImplementationDeclarationContext getOriginalContext()
      Returns the original ANTLR parse context for this implementation.
      Returns:
      the original implementation declaration context
    • getName

      public String getName()
      Returns the name of this implementation.
      Returns:
      the implementation name
    • getObjectFields

      public Map<String,DeclaredVariable> getObjectFields()
      Returns the map of object fields declared in this implementation.
      Returns:
      the object fields map
    • getImplementationFunctions

      public Map<String,DeclaredFunction<?>> getImplementationFunctions()
      Returns the map of functions declared in this implementation.
      Returns:
      the implementation functions map
    • toString

      public String toString()
      Returns a string representation of the declared implementation in Arabic.
      Overrides:
      toString in class Object
      Returns:
      a formatted string representing the implementation