Package io.jawk.ext

Class ExtensionFunction

java.lang.Object
io.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 Summary

    Modifier and Type
    Method
    Description
    int[]
    Collects the indexes of arguments that must be associative arrays for a call with the supplied argument count.
    int[]
    collectRawValueIndexes(int argCount)
    Collects the indexes of arguments that should be evaluated without autoconverting untyped values to assigned scalar blanks.
    int[]
    collectRegexpIndexes(int argCount)
    Collects the indexes of arguments where a regexp literal keeps its precompiled pattern instead of being evaluated as $0 ~ /re/.
    boolean
    expectsAssocArray(int index)
    Indicates whether the parameter at the supplied index must be an associative array.
    int
    Returns the minimum number of arguments required to invoke the function.
    Returns the extension type that declares the underlying Java method.
    Returns the fully-qualified class name of the declaring extension.
    Returns the Awk keyword mapped to this extension function.
    invoke(AbstractExtension target, Object[] args)
    Invokes the underlying Java method on the supplied target instance.
    void
    verifyArgCount(int argCount)
    Verifies that the provided argument count satisfies the arity constraints encoded in the metadata.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • collectRawValueIndexes

      public int[] collectRawValueIndexes(int argCount)
      Collects the indexes of arguments that should be evaluated without autoconverting untyped values to assigned scalar blanks.
      Parameters:
      argCount - number of arguments supplied by the caller
      Returns:
      indexes requiring raw value evaluation
    • collectRegexpIndexes

      public int[] collectRegexpIndexes(int argCount)
      Collects the indexes of arguments where a regexp literal keeps its precompiled pattern instead of being evaluated as $0 ~ /re/.
      Parameters:
      argCount - number of arguments supplied by the caller
      Returns:
      indexes keeping regexp literals raw
    • 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