Package net.sf.saxon.functions.hof

## Class FunctionLiteral

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.Literal
    - - net.sf.saxon.functions.hof.FunctionLiteral

- All Implemented Interfaces:
    `ExportAgent`, `Locatable`, `IdentityComparable`, `Traceable`

      public class FunctionLiteral
      extends Literal

  A FunctionLiteral is a wrapper around a FunctionItem; it is an expression, whose value is the function that it wraps. Note that a FunctionLiteral can be used only where the binding to a specific function is statically known. This works for constructor functions, for system functions that have no context dependency, and for references to user function (my:f#2) in XQuery, but not in XSLT where the reference cannot be fully resolved until separately-compiled packages are linked. In other cases a `UserFunctionReference` is used.

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FunctionLiteral​(Function value)` | Create a literal as a wrapper around a Value

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `computeCardinality()` | Determine the cardinality
    `int` | `computeHashCode()` | Return a hash code to support the equals() function
    `int` | `computeSpecialProperties()` | Compute the static properties of this expression (other than its type).
    `Expression` | `copy​(RebindingMap rebindings)` | Copy an expression.
    `boolean` | `equals​(java.lang.Object obj)` | Determine whether two literals are equal, when considered as expressions.
    `void` | `export​(ExpressionPresenter out)` | Diagnostic print of expression structure.
    `java.lang.String` | `getExpressionName()` | Get a name identifying the kind of expression, in terms meaningful to a user.
    `FunctionItemType` | `getItemType()` | Determine the data type of the items in the expression, if possible
    `Function` | `getValue()` | Get the value represented by this Literal
    `boolean` | `isVacuousExpression()` | Determine whether this is a vacuous expression as defined in the XQuery update specification
    `void` | `setRetainedStaticContext​(RetainedStaticContext rsc)` | Set the retained static context
    `Expression` | `simplify()` | Simplify an expression
    `Expression` | `typeCheck​(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)` | TypeCheck an expression

    - ### Methods inherited from class net.sf.saxon.expr.Literal

      `addToPathMap, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, exportAtomicValue, exportValue, getDependencies, getImplementationMethod, getIntegerBounds, getNetCost, getStaticUType, getStreamerName, hasEffectiveBooleanValue, isAtomic, isConstantBoolean, isConstantOne, isEmptySequence, isSubtreeExpression, iterate, iterate, makeEmptySequence, makeLiteral, makeLiteral, makeStringsLiteral, optimize, process, toPattern, toShortString, toString`

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, explain, getCardinality, getConfiguration, getCost, getEvaluationMethod, getExtraProperty, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isUpdatingExpression, markTailFunctionCalls, operandList, operands, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, typeCheckChildren, typeError, unordered, verifyParentPointers`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.trace.Traceable

      `gatherProperties`

- - ### Constructor Detail

    - #### FunctionLiteral

          public FunctionLiteral​(Function value)

      Create a literal as a wrapper around a Value
      Parameters:
        `value` - the value of this literal

  - ### Method Detail

    - #### getValue

          public Function getValue()

      Get the value represented by this Literal
      Overrides:
        `getValue` in class `Literal`
      Returns:
        the constant value

    - #### simplify

          public Expression simplify()
                              throws XPathException

      Simplify an expression
      Overrides:
        `simplify` in class `Expression`
      Returns:
        for a Value, this always returns the value unchanged
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### typeCheck

          public Expression typeCheck​(ExpressionVisitor visitor,
                                      ContextItemStaticInfo contextInfo)
                               throws XPathException

      TypeCheck an expression
      Overrides:
        `typeCheck` in class `Literal`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.
      Returns:
        for a Value, this always returns the value unchanged
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### getItemType

          public FunctionItemType getItemType()

      Determine the data type of the items in the expression, if possible
      Overrides:
        `getItemType` in class `Literal`
      Returns:
        for the default implementation: AnyItemType (not known)

    - #### computeCardinality

          public int computeCardinality()

      Determine the cardinality
      Overrides:
        `computeCardinality` in class `Literal`
      Returns:
        the computed cardinality, as one of the values `StaticProperty.ALLOWS_ZERO_OR_ONE`, `StaticProperty.EXACTLY_ONE`, `StaticProperty.ALLOWS_ONE_OR_MORE`, `StaticProperty.ALLOWS_ZERO_OR_MORE`. May also return `StaticProperty.ALLOWS_ZERO` if the result is known to be an empty sequence, or `StaticProperty.ALLOWS_MANY` if if is known to return a sequence of length two or more.

    - #### computeSpecialProperties

          public int computeSpecialProperties()

      Compute the static properties of this expression (other than its type). For a Value, the only special property is `StaticProperty.NO_NODES_NEWLY_CREATED`.
      Overrides:
        `computeSpecialProperties` in class `Literal`
      Returns:
        the value `StaticProperty.NO_NODES_NEWLY_CREATED`

    - #### isVacuousExpression

          public boolean isVacuousExpression()

      Determine whether this is a vacuous expression as defined in the XQuery update specification
      Overrides:
        `isVacuousExpression` in class `Literal`
      Returns:
        true if this expression is vacuous

    - #### copy

          public Expression copy​(RebindingMap rebindings)

      Copy an expression. This makes a deep copy.
      Overrides:
        `copy` in class `Literal`
      Parameters:
        `rebindings` -
      Returns:
        the copy of the original expression

    - #### setRetainedStaticContext

          public void setRetainedStaticContext​(RetainedStaticContext rsc)

      Set the retained static context
      Overrides:
        `setRetainedStaticContext` in class `Expression`
      Parameters:
        `rsc` - the static context to be retained

    - #### equals

          public boolean equals​(java.lang.Object obj)

      Determine whether two literals are equal, when considered as expressions.
      Overrides:
        `equals` in class `Literal`
      Parameters:
        `obj` - the other expression
      Returns:
        true if the two literals are equal. The test here requires (a) identity in the sense defined by XML Schema (same value in the same value space), and (b) identical type annotations. For example the literal xs:int(3) is not equal (as an expression) to xs:short(3), because the two expressions are not interchangeable.

    - #### computeHashCode

          public int computeHashCode()

      Return a hash code to support the equals() function
      Overrides:
        `computeHashCode` in class `Literal`
      Returns:
        a computed hash code

    - #### getExpressionName

          public java.lang.String getExpressionName()

      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
        `getExpressionName` in class `Literal`
      Returns:
        a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.

    - #### export

          public void export​(ExpressionPresenter out)
                      throws XPathException

      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
        `export` in interface `ExportAgent`
      Overrides:
        `export` in class `Literal`
      Parameters:
        `out` - the expression presenter used to display the structure
      Throws:
        `XPathException` - if the export fails, for example if an expression is found that won't work in the target environment.