Package net.sf.saxon.expr
Class SingletonAtomizer
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.UnaryExpression
net.sf.saxon.expr.SingletonAtomizer
- All Implemented Interfaces:
ExportAgent,Locatable,IdentityComparable,Traceable
A SingletonAtomizer combines the functions of an Atomizer and a CardinalityChecker: it is used to
atomize a sequence of nodes, checking that the result of the atomization contains zero or one atomic
values. Note that the input may be a sequence of nodes or atomic values, even though the result must
contain at most one atomic value.
-
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, UPDATE_METHOD, WATCH_METHOD -
Constructor Summary
ConstructorsConstructorDescriptionSingletonAtomizer(Expression sequence, Supplier<RoleDiagnostic> role, boolean allowEmpty) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected intDetermine the static cardinality of the expressionprotected intDetermine the special properties of this expressioncopy(RebindingMap rebindings) Copy an expression.evaluateItem(XPathContext context) Evaluate as an Item.voidDiagnostic print of expression structure.Make an elaborator for this expressionGive a string representation of the expression name for use in diagnosticsintAn implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().Determine the data type of the items returned by the expression, if possibleprotected OperandRoleGet the usage (in terms of streamability analysis) of the single operandgetRole()Get the RoleLocator (used to construct error messages)Get the (partial) name of a class that supports streaming of this kind of expressionbooleanAsk if the expression is allowed to return an empty sequenceoptimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Perform optimisation of an expression and its subexpressions.simplify()Simplify an expressionProduce a short string identifying the expression for use in error messagestypeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Type-check the expressionMethods inherited from class net.sf.saxon.expr.UnaryExpression
computeHashCode, displayOperator, emitExtraAttributes, equals, getBaseExpression, getOperand, operands, setBaseExpression, toStringMethods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, evaluateAsString, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers, warning, withLocationMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
Constructor Details
-
SingletonAtomizer
Constructor- Parameters:
sequence- the sequence to be atomizedrole- contains information about where the expression appears, for use in any error messageallowEmpty- true if the result sequence is allowed to be empty.
-
-
Method Details
-
getOperandRole
Description copied from class:UnaryExpressionGet the usage (in terms of streamability analysis) of the single operand- Specified by:
getOperandRolein classUnaryExpression- Returns:
- the operand usage
-
isAllowEmpty
public boolean isAllowEmpty()Ask if the expression is allowed to return an empty sequence- Returns:
- true if the expected cardinality is zero-or-one, false if it is exactly-one
-
simplify
Simplify an expression- Overrides:
simplifyin classExpression- Returns:
- the simplified expression (or the original if unchanged, or if modified in-situ)
- Throws:
XPathException- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Type-check the expression- Overrides:
typeCheckin classUnaryExpression- Parameters:
visitor- an expression visitorcontextInfo- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException- if an error is discovered during this phase (typically a type error)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Description copied from class:UnaryExpressionPerform optimisation of an expression and its subexpressions.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimizein classUnaryExpression- Parameters:
visitor- an expression visitorcontextInfo- 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)
-
computeSpecialProperties
protected int computeSpecialProperties()Determine the special properties of this expression- Overrides:
computeSpecialPropertiesin classUnaryExpression- Returns:
StaticProperty.NO_NODES_NEWLY_CREATED.
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copyin classExpression- Parameters:
rebindings- variables that need to be re-bound- Returns:
- the copy of the original expression
-
getImplementationMethod
public int getImplementationMethod()An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.- Specified by:
getImplementationMethodin classExpression- Returns:
- the implementation method, for example
Expression.ITERATE_METHODorExpression.EVALUATE_METHODorExpression.PROCESS_METHOD
-
getStreamerName
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerNamein classExpression- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
getRole
Get the RoleLocator (used to construct error messages)- Returns:
- the roleDiagnostic locator
-
evaluateItem
Evaluate as an Item. This should only be called if a singleton or empty sequence is required; it throws a type error if the underlying sequence is multi-valued.- Overrides:
evaluateItemin 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
-
getItemType
Determine the data type of the items returned by the expression, if possible- Overrides:
getItemTypein classUnaryExpression- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER. For this class, the result is always an atomic type, but it might be more specific.
-
computeCardinality
protected int computeCardinality()Determine the static cardinality of the expression- Overrides:
computeCardinalityin classUnaryExpression- 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 returnStaticProperty.ALLOWS_ZEROif the result is known to be an empty sequence, orStaticProperty.ALLOWS_MANYif if is known to return a sequence of length two or more.
-
getExpressionName
Give a string representation of the expression name for use in diagnostics- Overrides:
getExpressionNamein classExpression- Returns:
- the expression name, as a string
-
export
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
exportin interfaceExportAgent- Overrides:
exportin classUnaryExpression- Parameters:
out- the destination for the report- Throws:
XPathException- if the export fails, for example if an expression is found that won't work in the target environment.
-
toShortString
Description copied from class:ExpressionProduce a short string identifying the expression for use in error messages- Overrides:
toShortStringin classUnaryExpression- Returns:
- a short string, sufficient to identify the expression
-
getElaborator
Make an elaborator for this expression- Overrides:
getElaboratorin classExpression- Returns:
- a suitable elaborator
-