Package net.sf.saxon.expr
Class ItemChecker
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.UnaryExpression
-
- net.sf.saxon.expr.ItemChecker
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public final class ItemChecker extends UnaryExpression
A ItemChecker implements the item type checking of "treat as": that is, it returns the supplied sequence, checking that all its items are of the correct type. It is used both for actual "treat as" expressions, and more commonly, for the run-time type checking invoked by function calls. Note that these differ in the error code produced when type checking fails.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ItemChecker.ItemCheckerElaborator
Elaborator for atreat as
expression, which is usually system-generated by the type checking phase of the compiler
-
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 ItemChecker(Expression sequence, ItemType itemType, java.util.function.Supplier<RoleDiagnostic> roleSupplier)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Item
checkItem(Item item, XPathContext context)
protected int
computeHashCode()
get HashCode for comparing two expressions.Expression
copy(RebindingMap rebindings)
Copy an expression.boolean
equals(java.lang.Object other)
Is this expression the same as another expression?Item
evaluateItem(XPathContext context)
Evaluate as an Item.void
export(ExpressionPresenter out)
Diagnostic print of expression structure.Elaborator
getElaborator()
Make an elaborator for this expressionjava.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().IntegerValue[]
getIntegerBounds()
For an expression that returns an integer or a sequence of integers, get a lower and upper bound on the values of the integers that may be returned, from static analysis.ItemType
getItemType()
Determine the data type of the items returned by the expressionprotected OperandRole
getOperandRole()
Get the usage (in terms of streamability analysis) of the single operandItemType
getRequiredType()
Get the required typeRoleDiagnostic
getRoleLocator()
Get the RoleLocator (used to construct error messages)UType
getStaticUType(UType contextItemType)
Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.java.lang.String
getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expressionSequenceIterator
iterate(XPathContext context)
Iterate over the sequence of valuesExpression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform optimisation of an expression and its subexpressions.void
process(Outputter output, XPathContext context)
Process the instruction, without returning any tail callsExpression
simplify()
Simplify an expressionjava.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesjava.lang.String
toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.Expression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Type-check the expression-
Methods inherited from class net.sf.saxon.expr.UnaryExpression
computeCardinality, computeSpecialProperties, displayOperator, emitExtraAttributes, getBaseExpression, getOperand, operands, setBaseExpression
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, 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, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
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
-
ItemChecker
public ItemChecker(Expression sequence, ItemType itemType, java.util.function.Supplier<RoleDiagnostic> roleSupplier)
Constructor- Parameters:
sequence
- the expression whose value we are checkingitemType
- the required type of the items in the sequenceroleSupplier
- information used in constructing an error message
-
-
Method Detail
-
getRequiredType
public ItemType getRequiredType()
Get the required type- Returns:
- the required type of the items in the sequence
-
getOperandRole
protected OperandRole getOperandRole()
Description copied from class:UnaryExpression
Get the usage (in terms of streamability analysis) of the single operand- Specified by:
getOperandRole
in classUnaryExpression
- Returns:
- the operand usage
-
getRoleLocator
public RoleDiagnostic getRoleLocator()
Get the RoleLocator (used to construct error messages)- Returns:
- the RoleLocator
-
simplify
public Expression simplify() throws XPathException
Simplify an expression- Overrides:
simplify
in 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:
typeCheck
in 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
Perform 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:
optimize
in 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)
-
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. This implementation provides both iterate() and process() methods natively.- Specified by:
getImplementationMethod
in classExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
getStreamerName
public java.lang.String getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerName
in 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
-
getIntegerBounds
public IntegerValue[] getIntegerBounds()
For an expression that returns an integer or a sequence of integers, get a lower and upper bound on the values of the integers that may be returned, from static analysis. The default implementation returns null, meaning "unknown" or "not applicable". Other implementations return an array of two IntegerValue objects, representing the lower and upper bounds respectively. The values UNBOUNDED_LOWER and UNBOUNDED_UPPER are used by convention to indicate that the value may be arbitrarily large. The values MAX_STRING_LENGTH and MAX_SEQUENCE_LENGTH are used to indicate values limited by the size of a string or the size of a sequence.- Overrides:
getIntegerBounds
in classExpression
- Returns:
- the lower and upper bounds of integer values in the result, or null to indicate unknown or not applicable.
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Iterate over the sequence of values- 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
-
evaluateItem
public Item evaluateItem(XPathContext context) throws XPathException
Evaluate as an Item.- 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
-
checkItem
public Item checkItem(Item item, XPathContext context) throws XPathException
- Throws:
XPathException
-
process
public void process(Outputter output, XPathContext context) throws XPathException
Process the instruction, without returning any tail calls- Overrides:
process
in classExpression
- Parameters:
output
- the destination for the resultcontext
- The dynamic context, giving access to the current node,- Throws:
XPathException
- if a dynamic error occurs
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- variable bindings that need to be changed- Returns:
- the copy of the original expression
-
getItemType
public ItemType getItemType()
Determine the data type of the items returned by the expression- Overrides:
getItemType
in classUnaryExpression
- Returns:
- the item type of the items in the result sequence, insofar as this is known statically.
-
getStaticUType
public UType getStaticUType(UType contextItemType)
Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.- Overrides:
getStaticUType
in classExpression
- Parameters:
contextItemType
- the type of the context item- Returns:
- the static item type of the expression according to the XSLT 3.0 defined rules
-
equals
public boolean equals(java.lang.Object other)
Is this expression the same as another expression?- Overrides:
equals
in classUnaryExpression
- Parameters:
other
- the other operand; the result is false if this is not an Expression- Returns:
- true if the other operand is an expression and if it can be determined that the two expressions are equivalent, in the sense that they will always return the same result.
-
computeHashCode
protected int computeHashCode()
get HashCode for comparing two expressions. Note that this hashcode gives the same result for (A op B) and for (B op A), whether or not the operator is commutative.- Overrides:
computeHashCode
in classUnaryExpression
- Returns:
- a computed hash code
-
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 interfaceExportAgent
- Overrides:
export
in classUnaryExpression
- 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.
-
getExpressionName
public java.lang.String getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionName
in classExpression
- 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 explain() output displaying the expression.
-
toString
public java.lang.String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax- Overrides:
toString
in classUnaryExpression
- Returns:
- a representation of the expression as a string
-
toShortString
public java.lang.String toShortString()
Description copied from class:Expression
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classUnaryExpression
- Returns:
- a short string, sufficient to identify the expression
-
getElaborator
public Elaborator getElaborator()
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- a suitable elaborator
-
-