Class ExtensionFunction

java.lang.Object
org.metricshub.jawk.ext.ExtensionFunction
All Implemented Interfaces:
Serializable

public final class ExtensionFunction extends Object implements Serializable
Metadata describing a single annotated extension function.
See Also:
  • Method Details

    • getKeyword

      public String getKeyword()
      Returns the Awk keyword mapped to this extension function.
      Returns:
      the keyword exposed by the annotated method
    • getDeclaringType

      public Class<? extends AbstractExtension> getDeclaringType()
      Returns the extension type that declares the underlying Java method.
      Returns:
      declaring AbstractExtension subtype
    • getExtensionClassName

      public String getExtensionClassName()
      Returns the fully-qualified class name of the declaring extension.
      Returns:
      extension class name
    • getArity

      public int getArity()
      Returns the minimum number of arguments required to invoke the function.
      Returns:
      required argument count before considering varargs
    • expectsAssocArray

      public boolean expectsAssocArray(int index)
      Indicates whether the parameter at the supplied index must be an associative array.
      Parameters:
      index - zero-based parameter index
      Returns:
      true when the parameter must be an associative array
      Throws:
      IndexOutOfBoundsException - when the index exceeds the parameter count
    • collectAssocArrayIndexes

      public int[] collectAssocArrayIndexes(int argCount)
      Collects the indexes of arguments that must be associative arrays for a call with the supplied argument count. Vararg positions are included when the vararg parameter requires associative arrays.
      Parameters:
      argCount - number of arguments supplied by the caller
      Returns:
      indexes of arguments that must be associative arrays
    • invoke

      public Object invoke(AbstractExtension target, Object[] args)
      Invokes the underlying Java method on the supplied target instance.
      Parameters:
      target - extension instance to receive the call
      args - arguments evaluated by the interpreter
      Returns:
      result of the Java invocation
      Throws:
      IllegalAwkArgumentException - when the arguments violate the metadata
      IllegalStateException - when reflection cannot invoke the method
    • verifyArgCount

      public void verifyArgCount(int argCount)
      Verifies that the provided argument count satisfies the arity constraints encoded in the metadata.
      Parameters:
      argCount - number of arguments the caller supplied
      Throws:
      IllegalAwkArgumentException - when the count violates the signature