Class BuiltinFunction

java.lang.Object
org.daiitech.naftah.builtin.lang.BuiltinFunction
All Implemented Interfaces:
Serializable, JvmExecutable

public final class BuiltinFunction extends Object implements Serializable, JvmExecutable
Representation of a builtin function.

This class wraps a Method along with additional metadata about the function's provider and function information. It supports serialization by storing the method's class and method names and restoring the Method reference upon deserialization.

Author:
Chakib Daii
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • methodName

      private final String methodName
      The name of the method.
    • methodParameterTypes

      private final Class<?>[] methodParameterTypes
      The method parameter types.
    • className

      private final String className
      The fully qualified name of the class declaring the method.
    • providerInfo

      private final NaftahFunctionProvider providerInfo
      Provider information for this function.
    • functionInfo

      private final NaftahFunction functionInfo
      Function information for this function.
    • method

      private transient Method method
      The reflected method instance. Marked transient because it is not serializable and restored after deserialization.
  • Constructor Details

    • BuiltinFunction

      public BuiltinFunction(Method method, NaftahFunctionProvider providerInfo, NaftahFunction functionInfo)
      Constructs a BuiltinFunction with the given method and metadata.
      Parameters:
      method - the reflected method representing this builtin function
      providerInfo - the provider information for the function
      functionInfo - the function-specific information
  • Method Details

    • of

      public static BuiltinFunction of(Method method, NaftahFunctionProvider providerInfo, NaftahFunction functionInfo)
      Static factory method to create a new BuiltinFunction instance.
      Parameters:
      method - the reflected method representing this builtin function
      providerInfo - the provider information for the function
      functionInfo - the function-specific information
      Returns:
      a new BuiltinFunction instance
    • getMethod

      public Method getMethod()
      Returns the reflected Method instance representing this builtin function.
      Returns:
      the method instance
    • getProviderInfo

      public NaftahFunctionProvider getProviderInfo()
      Returns the provider information associated with this function.
      Returns:
      the function provider information
    • getFunctionInfo

      public NaftahFunction getFunctionInfo()
      Returns the function-specific information associated with this function.
      Returns:
      the function information
    • getExecutable

      public Executable getExecutable()
      Returns the underlying reflective Executable instance represented by this object.

      This may correspond to a Java method, constructor, or other callable element recognized by the JVM.

      Specified by:
      getExecutable in interface JvmExecutable
      Returns:
      the associated Executable instance
    • writeObject

      private void writeObject(ObjectOutputStream oos) throws IOException
      Custom serialization logic. Writes the non-transient fields using default serialization.
      Parameters:
      oos - the output stream to write to
      Throws:
      IOException - if an I/O error occurs
    • readObject

      private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
      Custom deserialization logic. Reads the non-transient fields using default deserialization, then restores the transient method field by locating the method by name in the deserialized class.
      Parameters:
      ois - the input stream to read from
      Throws:
      IOException - if an I/O error occurs
      ClassNotFoundException - if the class for the method cannot be found
    • toString

      public String toString()
      Returns a string representation of this builtin function. The format is <دالة functionName>.
      Overrides:
      toString in class Object
      Returns:
      a string describing this builtin function
    • toDetailedString

      public String toDetailedString()