Package net.sf.saxon.pattern
Class GeneralNodePattern
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.PseudoExpression
net.sf.saxon.pattern.Pattern
net.sf.saxon.pattern.GeneralNodePattern
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
A GeneralNodePattern represents a pattern which, because of the presence of positional
predicates or otherwise, can only be evaluated "the hard way", by evaluating the equivalent
expression with successive ancestors of the tested node as context item.
-
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
ConstructorsConstructorDescriptionGeneralNodePattern
(Expression expr, NodeTest itemType) Create a GeneralNodePattern -
Method Summary
Modifier and TypeMethodDescriptionint
allocateSlots
(SlotManager slotManager, int nextFree) Allocate slots to any variables used within the patternvoid
bindCurrent
(LocalBinding binding) Replace any calls on current() by a variable reference bound to the supplied bindingprotected int
hashcode supporting equals()copy
(RebindingMap rebindings) Copy a pattern.boolean
Determine whether this pattern is the same as another patternvoid
export
(ExpressionPresenter presenter) Diagnostic print of expression structure.int
Get the dependencies of the pattern.int
Determine the fingerprint of nodes to which this pattern applies.Get a NodeTest that all the nodes matching this pattern must satisfygetUType()
Get a UType indicating which kinds of items this Pattern can match.boolean
Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream.void
A pattern whose first step uses the child axis is treated as using the child-or-top axis, which selects a node that is either (a) a child, or (b) a parentless element, comment, text node, or PI.boolean
matches
(Item item, XPathContext context) Determine whether the pattern matches a given item.boolean
matchesBeneathAnchor
(NodeInfo node, NodeInfo anchor, XPathContext context) Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node.operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.optimize
(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Perform optimisation of an expression and its subexpressions.typeCheck
(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) Type-check the pattern, performing any type-dependent optimizations.Methods inherited from class net.sf.saxon.pattern.Pattern
convertToTypedPattern, effectiveBooleanValue, getDefaultPriority, getElaborator, getHostLanguage, getOriginalText, handleDynamicError, isLiftable, isRecoverable, make, matchesCurrentGroup, matchesItem, patternContainsVariable, reconstruct, replaceCurrent, selectNodes, setOriginalText, setPriority, setRecoverable, simplify, toPattern, toShortString, toString
Methods inherited from class net.sf.saxon.expr.PseudoExpression
computeCardinality, evaluateAsString, evaluateItem, getImplementationMethod, iterate, process
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, explain, getCardinality, getConfiguration, getCost, getEvaluationMethod, getExpressionName, getExtraProperty, getIntegerBounds, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, 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, 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 Details
-
GeneralNodePattern
Create a GeneralNodePattern- Parameters:
expr
- the "equivalent expression"itemType
- a type that all matched nodes must satisfy
-
-
Method Details
-
makeTopNodeEquivalent
public void makeTopNodeEquivalent()A pattern whose first step uses the child axis is treated as using the child-or-top axis, which selects a node that is either (a) a child, or (b) a parentless element, comment, text node, or PI. We handle this by creating a variant of the equivalent expression that uses the self axis instead of child, and using this variant if matching a tree that satisfies the other conditions. -
operands
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation works off the results of iterateSubExpressions()If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.
- Overrides:
operands
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
isMotionless
public boolean isMotionless()Test whether a pattern is motionless, that is, whether it can be evaluated against a node without repositioning the input stream. This is a necessary condition for patterns used as the match pattern of a streamed template rule.- Overrides:
isMotionless
in classPattern
- Returns:
- true if the pattern is motionless, that is, if it can be evaluated against a streamed node without changing the position in the streamed input file
-
typeCheck
public Pattern typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException Type-check the pattern, performing any type-dependent optimizations.- Overrides:
typeCheck
in classPattern
- Parameters:
visitor
- an expression visitorcontextItemType
- the type of the context item at the point where the pattern appears- Returns:
- the optimised Pattern
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
optimize
public Pattern optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.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 classPattern
- 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)
-
getDependencies
public int getDependencies()Get the dependencies of the pattern. The only interesting dependencies for a pattern are dependencies on local variables or on user-defined functions. These are analyzed in those patterns containing predicates.- Overrides:
getDependencies
in classPattern
- Returns:
- the dependencies, as a bit-significant mask
-
bindCurrent
Replace any calls on current() by a variable reference bound to the supplied binding- Overrides:
bindCurrent
in classPattern
-
allocateSlots
Allocate slots to any variables used within the pattern- Overrides:
allocateSlots
in classPattern
- Parameters:
slotManager
- details of the stack framenextFree
- the next slot that is free to be allocated @return the next slot that is free to be allocated- Returns:
- the next slot that is free to be allocated
-
matches
Determine whether the pattern matches a given item.- Specified by:
matches
in classPattern
- Parameters:
item
- the item to be testedcontext
- The dynamic context.- Returns:
- true if the pattern matches, else false
- Throws:
XPathException
- if an error occurs while matching the pattern
-
matchesBeneathAnchor
public boolean matchesBeneathAnchor(NodeInfo node, NodeInfo anchor, XPathContext context) throws XPathException Determine whether this pattern matches a given Node within the subtree rooted at a given anchor node. This method is used when the pattern is used for streaming.- Overrides:
matchesBeneathAnchor
in classPattern
- Parameters:
node
- The NodeInfo representing the Element or other node to be tested against the Patternanchor
- The anchor node, which if present must match any AnchorPattern subpattern; may be nullcontext
- The dynamic context. Only relevant if the pattern uses variables, or contains calls on functions such as document() or key().- Returns:
- true if the node matches the Pattern, false otherwise
- Throws:
XPathException
- if an error occurs while matching the pattern (the caller will usually treat this the same as a false result)
-
getUType
Get a UType indicating which kinds of items this Pattern can match. -
getFingerprint
public int getFingerprint()Determine the fingerprint of nodes to which this pattern applies. Used for optimisation.- Overrides:
getFingerprint
in classPattern
- Returns:
- the fingerprint of nodes matched by this pattern.
-
getItemType
Get a NodeTest that all the nodes matching this pattern must satisfy- Specified by:
getItemType
in classPattern
- Returns:
- an ItemType, as specific as possible, which all the matching items satisfy
-
getEquivalentExpr
-
equals
Determine whether this pattern is the same as another pattern- Overrides:
equals
in classExpression
- Parameters:
other
- the other object- 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()hashcode supporting equals()- Overrides:
computeHashCode
in classExpression
- Returns:
- a computed hash code
-
copy
Copy a pattern. This makes a deep copy. -
export
Description copied from class:Expression
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classPattern
- Parameters:
presenter
- 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.
-