Package net.sf.saxon.expr
Class LazyExpression
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.UnaryExpression
net.sf.saxon.expr.LazyExpression
- All Implemented Interfaces:
Serializable
,SourceLocator
,LocationProvider
,SaxonLocator
,EvaluableItem
,SequenceIterable
,InstructionInfo
,Locator
A LazyExpression is an expression that forces lazy evaluation: it must not be evaluated eagerly,
because a failure must not be reported unless the value is actually referenced. This is used
for an expression that has been moved out of a loop. If the loop iterates zero times, the expression
will not be evaluated, and in particular, it will not cause a dynamic error.
Note that the LazyExpression class does not itself implement any kind of delayed evaluation: calling its evaluateItem() and iterate() methods produces an immediate result. Instead, the existence of a LazyExpression on the expression tree acts as a signal to other classes that evaluation should be delayed, typically by holding the result of the iterate() method in a Closure object.
- See Also:
-
Field Summary
Fields inherited from class net.sf.saxon.expr.UnaryExpression
operand
Fields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, staticProperties
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copy an expression.protected String
Return the element name to use in the expression treeevaluateItem
(XPathContext context) Evaluate an expression as a single item.iterate
(XPathContext context) Return an Iterator to iterate over the values of a sequence.static Expression
makeLazyExpression
(Expression operand) Create a LazyExpression (factory method)optimize
(ExpressionVisitor visitor, ItemType contextItemType) Perform optimisation of an expression and its subexpressions.void
process
(XPathContext context) Process the instruction, without returning any tail callstypeCheck
(ExpressionVisitor visitor, ItemType contextItemType) The typeCheck method suppresses compile-time evaluationMethods inherited from class net.sf.saxon.expr.UnaryExpression
computeCardinality, computeSpecialProperties, displayOperator, equals, explain, getBaseExpression, getItemType, hashCode, iterateSubExpressions, promote, replaceSubExpression, simplify, toString
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluatePendingUpdates, explain, findParentOf, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, isUpdatingExpression, iterateEvents, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, typeError
-
Constructor Details
-
LazyExpression
Create a LazyExpression- Parameters:
operand
- the expression to be evaluated lazily
-
-
Method Details
-
makeLazyExpression
Create a LazyExpression (factory method)- Parameters:
operand
- the expression to be evaluated lazily- Returns:
- the LazyExpression
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException The typeCheck method suppresses compile-time evaluation- Overrides:
typeCheck
in classUnaryExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of the context item- Returns:
- the expression after typechecking
- Throws:
XPathException
-
optimize
public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException Perform optimisation of an expression and its subexpressions. This method suppresses compile-time evaluation- Overrides:
optimize
in classUnaryExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
evaluateItem
Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.- Specified by:
evaluateItem
in interfaceEvaluableItem
- Overrides:
evaluateItem
in classExpression
- Parameters:
context
- The context in which the expression is to be evaluated- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
iterate
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.- Specified by:
iterate
in interfaceSequenceIterable
- Overrides:
iterate
in classExpression
- Parameters:
context
- supplies the context for evaluation- Returns:
- a SequenceIterator that can be used to iterate over the result of the expression
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
process
Process the instruction, without returning any tail calls- Overrides:
process
in classExpression
- Parameters:
context
- The dynamic context, giving access to the current node, the current variables, etc.- Throws:
XPathException
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Returns:
- the copy of the original expression
-
displayExpressionName
Description copied from class:UnaryExpression
Return the element name to use in the expression tree- Overrides:
displayExpressionName
in classUnaryExpression
-