Class ItemChecker
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.UnaryExpression
net.sf.saxon.expr.ItemChecker
- All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator
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
- See Also:
-
Field Summary
Fields inherited from class UnaryExpression
operand -
Constructor Summary
ConstructorsConstructorDescriptionItemChecker(Expression sequence, ItemType itemType, RoleLocator role) Constructor -
Method Summary
Modifier and TypeMethodDescriptioncopy()Copy an expression.booleanIs this expression the same as another expression?evaluateItem(XPathContext context) Evaluate as an Item.voidDiagnostic print of expression structure.Get a name identifying the kind of expression, in terms meaningful to a user.intAn implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().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.Determine the data type of the items returned by the expressiongetMappingFunction(XPathContext context) Get the mapping function used to implement this item check.Get the required typeGet the RoleLocator (used to construct error messages)inthashCode()get HashCode for comparing two expressions.iterate(XPathContext context) Iterate over the sequence of valuesvoidprocess(XPathContext context) Process the instruction, without returning any tail callssimplify(ExpressionVisitor visitor) Simplify an expressiontypeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) Type-check the expressionMethods inherited from class UnaryExpression
computeCardinality, computeSpecialProperties, displayOperator, getBaseExpression, iterateSubExpressions, optimize, promote, replaceSubExpression, toStringMethods inherited from class Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getEvaluationMethod, getExecutable, getHostLanguage, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, typeError
-
Constructor Details
-
ItemChecker
Constructor- Parameters:
sequence- the expression whose value we are checkingitemType- the required type of the items in the sequencerole- information used in constructing an error message
-
-
Method Details
-
getRequiredType
Get the required type- Returns:
- the required type of the items in the sequence
-
getRoleLocator
Get the RoleLocator (used to construct error messages)- Returns:
- the RoleLocator
-
simplify
Simplify an expression- Overrides:
simplifyin classUnaryExpression- Parameters:
visitor- an expression visitor- Returns:
- the simplified expression
- Throws:
XPathException- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) throws XPathException Type-check the expression- Overrides:
typeCheckin 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 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)
-
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.- Overrides:
getImplementationMethodin classExpression- Returns:
- the implementation method, for example
Expression.ITERATE_METHODorExpression.EVALUATE_METHODorExpression.PROCESS_METHOD
-
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:
getIntegerBoundsin classExpression- Returns:
- the lower and upper bounds of integer values in the result, or null to indicate unknown or not applicable.
-
iterate
Iterate over the sequence of values- Overrides:
iteratein 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
-
getMappingFunction
Get the mapping function used to implement this item check. This mapping function is applied to each item in the input sequence.- Parameters:
context- The dynamic context used to evaluate the mapping function- Returns:
- the mapping function. This will be an identity mapping: the output sequence is the same as the input sequence, unless the dynamic type checking reveals an error.
-
evaluateItem
Evaluate as an Item.- 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
-
process
Process the instruction, without returning any tail calls- Overrides:
processin classExpression- Parameters:
context- The dynamic context, giving access to the current node, the current variables, etc.- Throws:
XPathException- if a dynamic error occurs
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copyin classExpression- Returns:
- the copy of the original expression
-
getItemType
Determine the data type of the items returned by the expression- Overrides:
getItemTypein classUnaryExpression- Parameters:
th- the type hierarchy cache- Returns:
- the item type of the items in the result sequence, insofar as this is known statically.
-
equals
Is this expression the same as another expression?- Overrides:
equalsin classUnaryExpression
-
hashCode
public int hashCode()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:
hashCodein classUnaryExpression
-
explain
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Overrides:
explainin classUnaryExpression- Parameters:
out- the expression presenter used to display the structure
-
getExpressionName
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionNamein 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.
-