Package net.sf.saxon.functions.hof
Class CoercedFunction
java.lang.Object
net.sf.saxon.functions.AbstractFunction
net.sf.saxon.functions.hof.CoercedFunction
- All Implemented Interfaces:
Callable
,Function
,GroundedValue
,Item
,Sequence
A function item obtained by coercing a supplied function; this adds a wrapper to perform dynamic
type checking of the arguments in any call, and type checking of the result.
-
Constructor Summary
ConstructorsConstructorDescriptionCoercedFunction
(Function targetFunction, SpecificFunctionType requiredType) Create a CoercedFunction as a wrapper around a target functionCoercedFunction
(SpecificFunctionType requiredType) Create a CoercedFunction whose target function is not yet known (happens during package re-loading) -
Method Summary
Modifier and TypeMethodDescriptioncall
(XPathContext context, Sequence[] args) Invoke the functionstatic CoercedFunction
coerce
(Function suppliedFunction, SpecificFunctionType requiredType, RoleDiagnostic role) Factory method to create a CoercedFunction with a given type, for a given targetFunction.void
Export information about this function item to the SEF fileGet the function annotations (as defined in XQuery).int
getArity()
Get the arity of the functionGet a description of this function for use in error messages.Get the item type of the function itemGet the name of the function, or null if it is anonymousvoid
setTargetFunction
(Function targetFunction) Set the target functionvoid
typeCheck
(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) Type check the function (may modify it by adding code for converting the arguments)Methods inherited from class net.sf.saxon.functions.AbstractFunction
atomize, deepEquals, effectiveBooleanValue, getOperandRoles, getStringValue, getStringValueCS, isArray, isMap, isTrustedResultType, makeNewContext, simplify
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.saxon.om.Function
getGenre, toShortString
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
Methods inherited from interface net.sf.saxon.om.Item
getLength, head, isStreamed, itemAt, iterate, reduce, subsequence
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Constructor Details
-
CoercedFunction
public CoercedFunction(Function targetFunction, SpecificFunctionType requiredType) throws XPathException Create a CoercedFunction as a wrapper around a target function- Parameters:
targetFunction
- the function to be wrapped by a type-checking layerrequiredType
- the type of the coerced function, that is the type required by the context in which the target function is being used- Throws:
XPathException
- if the arity of the supplied function does not match the arity of the required type
-
CoercedFunction
Create a CoercedFunction whose target function is not yet known (happens during package re-loading)- Parameters:
requiredType
- the type of the coerced function, that is the type required by the context in which the target function is being used
-
-
Method Details
-
setTargetFunction
Set the target function- Parameters:
targetFunction
- the function to be wrapped by a type-checking layer- Throws:
XPathException
- if the arity of the supplied function does not match the arity of the required type
-
typeCheck
public void typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException Type check the function (may modify it by adding code for converting the arguments)- Overrides:
typeCheck
in classAbstractFunction
- Parameters:
visitor
- the expression visitor, supplies context informationcontextItemType
- the context item type at the point where the function definition appears- Throws:
XPathException
- if type checking of the target function fails
-
getFunctionItemType
Get the item type of the function item- Returns:
- the function item's type
-
getFunctionName
Get the name of the function, or null if it is anonymous- Returns:
- null indicating that this is an anonymous inline function
-
getDescription
Get a description of this function for use in error messages. For named functions, the description is the function name (as a lexical QName). For others, it might be, for example, "inline function", or "partially-applied ends-with function".- Returns:
- a description of the function for use in error messages
-
getArity
public int getArity()Get the arity of the function- Returns:
- the number of arguments in the function signature
-
getAnnotations
Description copied from interface:Function
Get the function annotations (as defined in XQuery). Returns an empty list if there are no function annotations.- Specified by:
getAnnotations
in interfaceFunction
- Overrides:
getAnnotations
in classAbstractFunction
- Returns:
- the function annotations
-
call
Invoke the function- Parameters:
context
- the XPath dynamic evaluation contextargs
- the actual arguments to be supplied- Returns:
- the result of invoking the function
- Throws:
XPathException
- if execution of the function fails
-
coerce
public static CoercedFunction coerce(Function suppliedFunction, SpecificFunctionType requiredType, RoleDiagnostic role) throws XPathException Factory method to create a CoercedFunction with a given type, for a given targetFunction. It is assumed that we have already established that coercion is needed. Called from Bytecode compiler.- Parameters:
suppliedFunction
- the function to be coercedrequiredType
- the target type for the coercionrole
- diagnostic information about the role of the expression being coerced- Returns:
- the function after coercion
- Throws:
XPathException
- if the function cannot be coerced to the required type (for example, because it has the wrong arity)
-
export
Export information about this function item to the SEF file- Specified by:
export
in interfaceFunction
- Overrides:
export
in classAbstractFunction
- Parameters:
out
- the SEF output destination- Throws:
XPathException
-