Package net.sf.saxon.expr
Class FilterExpression
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.BinaryExpression
-
- net.sf.saxon.expr.FilterExpression
-
- All Implemented Interfaces:
ContextOriginator
,ContextSwitchingExpression
,ExportAgent
,Locatable
,IdentityComparable
,Traceable
public final class FilterExpression extends BinaryExpression implements ContextSwitchingExpression
A FilterExpression contains a base expression and a filter predicate, which may be an integer expression (positional filter), or a boolean expression (qualifier)
-
-
Field Summary
Fields Modifier and Type Field Description boolean
doneReorderingPredicates
static OperandRole
FILTER_PREDICATE
static int
FILTERED
-
Fields inherited from class net.sf.saxon.expr.BinaryExpression
operator
-
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 FilterExpression(Expression base, Expression filter)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PathMap.PathMapNodeSet
addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.int
computeCardinality()
Get the static cardinality of this expressionint
computeHashCode()
get HashCode for comparing two expressionsint
computeSpecialProperties()
Get the static properties of this expression (other than its type).Expression
copy(RebindingMap rebindings)
Copy an expression.boolean
equals(java.lang.Object other)
Is this expression the same as another expression?void
export(ExpressionPresenter out)
Diagnostic print of expression structure.Expression
getActionExpression()
Get the subexpression that is evaluated in the new contextExpression
getBase()
double
getCost()
Return the estimated cost of evaluating an expression.java.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.Expression
getFilter()
Get the filter expressionint
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()
Get the data type of the items returnedprotected OperandRole
getOperandRole(int arg)
Get the operand roleExpression
getSelectExpression()
Get the base expressionUType
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 expressionboolean
isFilterIsPositional()
Ask if the filter is positional (used from bytecode)boolean
isIndependentFilter()
Determine whether the filter is independent of the context item and positionboolean
isPositional(TypeHierarchy th)
Determine if the filter is positionalstatic boolean
isPositionalFilter(Expression exp, TypeHierarchy th)
Determine whether an expression, when used as a filter, is potentially positional; that is, where it either contains a call on position() or last(), or where it is capable of returning a numeric result.boolean
isSimpleBooleanFilter()
Test if the filter always returns a singleton boolean.SequenceIterator
iterate(XPathContext context)
Iterate over the results, returning them in the correct orderExpression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform optimisation of an expression and its subexpressions.void
setBase(Expression base)
void
setFilter(Expression filter)
void
setFlags(java.lang.String flags)
Expression
simplify()
Simplify an expressionPattern
toPattern(Configuration config)
Convert this expression to an equivalent XSLT patternjava.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 expressionExpression
unordered(boolean retainAllNodes, boolean forStreaming)
Replace this expression by a simpler expression that delivers the results without regard to order.-
Methods inherited from class net.sf.saxon.expr.BinaryExpression
displayOperator, explainExtraAttributes, getLhs, getLhsExpression, getOperator, getRhs, getRhsExpression, isAssociative, isCommutative, isInverse, operands, setFlattened, setLhsExpression, setRhsExpression, tag
-
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getDependencies, getEvaluationMethod, getExtraProperty, getInterpretedExpression, 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, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, typeCheckChildren, typeError, 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
-
-
-
-
Field Detail
-
doneReorderingPredicates
public boolean doneReorderingPredicates
-
FILTERED
public static final int FILTERED
- See Also:
- Constant Field Values
-
FILTER_PREDICATE
public static final OperandRole FILTER_PREDICATE
-
-
Constructor Detail
-
FilterExpression
public FilterExpression(Expression base, Expression filter)
Constructor- Parameters:
base
- The base expression to be filtered.filter
- An expression defining the filter predicate
-
-
Method Detail
-
getOperandRole
protected OperandRole getOperandRole(int arg)
Description copied from class:BinaryExpression
Get the operand role- Overrides:
getOperandRole
in classBinaryExpression
- Parameters:
arg
- which argument: 0 for the lhs, 1 for the rhs- Returns:
- the operand role
-
getBase
public Expression getBase()
-
setBase
public void setBase(Expression base)
-
getFilter
public Expression getFilter()
Get the filter expression- Returns:
- the expression acting as the filter predicate
-
setFilter
public void setFilter(Expression filter)
-
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.
-
getItemType
public ItemType getItemType()
Get the data type of the items returned- Specified by:
getItemType
in classExpression
- Returns:
- an integer representing the data type
-
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 static type of the context item- Returns:
- the static item type of the expression according to the XSLT 3.0 defined rules
-
getSelectExpression
public Expression getSelectExpression()
Get the base expression- Specified by:
getSelectExpression
in interfaceContextSwitchingExpression
- Returns:
- the base expression being filtered
-
isFilterIsPositional
public boolean isFilterIsPositional()
Ask if the filter is positional (used from bytecode)- Returns:
- true filter is positional
-
getActionExpression
public Expression getActionExpression()
Get the subexpression that is evaluated in the new context- Specified by:
getActionExpression
in interfaceContextSwitchingExpression
- Returns:
- the subexpression evaluated in the context set by the controlling expression
-
isPositional
public boolean isPositional(TypeHierarchy th)
Determine if the filter is positional- Parameters:
th
- the Type Hierarchy (for cached access to type information)- Returns:
- true if the value of the filter depends on the position of the item against which it is evaluated
-
isSimpleBooleanFilter
public boolean isSimpleBooleanFilter()
Test if the filter always returns a singleton boolean.This information is available only after typeCheck() has been called.
- Returns:
- true if the filter is a simple boolean expression
-
isIndependentFilter
public boolean isIndependentFilter()
Determine whether the filter is independent of the context item and positionThis information is available only after typeCheck() has been called.
- Returns:
- true if the filter is a numeric value that does not depend on the context item or position
-
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 any failure occurs
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Type-check the expression- Overrides:
typeCheck
in classBinaryExpression
- Parameters:
visitor
- the expression visitorcontextInfo
- return the expression after type-checking (potentially modified to add run-time checks and/or conversions)- 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 contextItemType) 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 classBinaryExpression
- 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)
-
getCost
public double getCost()
Return the estimated cost of evaluating an expression. This is a very crude measure based on the syntactic form of the expression (we have no knowledge of data values). We take the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one), and we assume that a sequence has length 5. The resulting estimates may be used, for example, to reorder the predicates in a filter expression so cheaper predicates are evaluated first.- Overrides:
getCost
in classExpression
- Returns:
- the estimated cost
-
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.- Overrides:
getImplementationMethod
in classBinaryExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
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.
-
addToPathMap
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.- Overrides:
addToPathMap
in classExpression
- Parameters:
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be added- Returns:
- the pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression
-
unordered
public Expression unordered(boolean retainAllNodes, boolean forStreaming) throws XPathException
Replace this expression by a simpler expression that delivers the results without regard to order.- Overrides:
unordered
in classExpression
- Parameters:
retainAllNodes
- set to true if the result must contain exactly the same nodes as the original; set to false if the result can eliminate (or introduce) duplicates.forStreaming
- set to true if optimizing for streaming- Returns:
- an expression that delivers the same nodes in a more convenient order
- Throws:
XPathException
- if the rewrite fails
-
isPositionalFilter
public static boolean isPositionalFilter(Expression exp, TypeHierarchy th)
Determine whether an expression, when used as a filter, is potentially positional; that is, where it either contains a call on position() or last(), or where it is capable of returning a numeric result.- Parameters:
exp
- the expression to be examinedth
- the type hierarchy cache- Returns:
- true if the expression depends on position() or last() explicitly or implicitly
-
computeCardinality
public int computeCardinality()
Get the static cardinality of this expression- Overrides:
computeCardinality
in classBinaryExpression
- Returns:
- the cardinality. The method attempts to determine the case where the filter predicate is guaranteed to select at most one item from the sequence being filtered
-
computeSpecialProperties
public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-significant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.- Overrides:
computeSpecialProperties
in classBinaryExpression
- Returns:
- the static properties of the expression, as a bit-significant value
-
equals
public boolean equals(java.lang.Object other)
Is this expression the same as another expression?- Overrides:
equals
in classBinaryExpression
- Parameters:
other
- the expression to be compared with this one- Returns:
- true if the two expressions are statically equivalent
-
computeHashCode
public int computeHashCode()
get HashCode for comparing two expressions- Overrides:
computeHashCode
in classBinaryExpression
- Returns:
- the hash code
-
toPattern
public Pattern toPattern(Configuration config) throws XPathException
Convert this expression to an equivalent XSLT pattern- Overrides:
toPattern
in classExpression
- Parameters:
config
- the Saxon configuration- Returns:
- the equivalent pattern
- Throws:
XPathException
- if conversion is not possible
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Iterate over the results, returning them in the correct order- Overrides:
iterate
in classExpression
- Parameters:
context
- the dynamic context for the evaluation- Returns:
- an iterator over the expression results
- Throws:
XPathException
- if any dynamic error occurs
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- a mutable list of (old binding, new binding) pairs that is used to update the bindings held in any local variable references that are copied.- Returns:
- the copy of the original expression
-
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
-
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 classBinaryExpression
- Returns:
- the expression as a string in XPath 3.0 syntax
-
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 classBinaryExpression
- Returns:
- a short string, sufficient to identify 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 interfaceExportAgent
- Overrides:
export
in classBinaryExpression
- Parameters:
out
- the ExpressionPresenter to be used- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
setFlags
public void setFlags(java.lang.String flags)
-
-