Package org.metricshub.jawk.ext
Class ExtensionFunction
java.lang.Object
org.metricshub.jawk.ext.ExtensionFunction
- All Implemented Interfaces:
Serializable
Metadata describing a single annotated extension function.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionint[]collectAssocArrayIndexes(int argCount) Collects the indexes of arguments that must be associative arrays for a call with the supplied argument count.booleanexpectsAssocArray(int index) Indicates whether the parameter at the supplied index must be an associative array.intgetArity()Returns the minimum number of arguments required to invoke the function.Class<? extends AbstractExtension>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.voidverifyArgCount(int argCount) Verifies that the provided argument count satisfies the arity constraints encoded in the metadata.
-
Method Details
-
getKeyword
Returns the Awk keyword mapped to this extension function.- Returns:
- the keyword exposed by the annotated method
-
getDeclaringType
Returns the extension type that declares the underlying Java method.- Returns:
- declaring
AbstractExtensionsubtype
-
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:
truewhen 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
Invokes the underlying Java method on the supplied target instance.- Parameters:
target- extension instance to receive the callargs- arguments evaluated by the interpreter- Returns:
- result of the Java invocation
- Throws:
IllegalAwkArgumentException- when the arguments violate the metadataIllegalStateException- 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
-