Package net.sf.saxon.expr
Class VariableReference
java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.VariableReference
- All Implemented Interfaces:
- BindingReference,- ExportAgent,- Locatable,- IdentityComparable,- Traceable
- Direct Known Subclasses:
- GlobalVariableReference,- LocalVariableReference
Variable reference: a reference to a variable. This may be an XSLT-defined variable, a range
 variable defined within the XPath expression, or a variable defined in some other static context.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Bindingprotected GroundedValueprotected SequenceTypeFields inherited from class net.sf.saxon.expr.ExpressionEFFECTIVE_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 SummaryConstructorsConstructorDescriptionVariableReference(Binding binding) Create a Variable ReferenceCreate a Variable Reference
- 
Method SummaryModifier and TypeMethodDescriptionaddToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) Add a representation of this expression to a PathMap.protected intGet the static cardinalityprotected intget HashCode for comparing two expressionsprotected intDetermine the special properties of this expressionabstract Expressioncopy(RebindingMap rebindings) Create a clone copy of this VariableReferenceprotected voidbooleanTest if this expression is the same as another expression.Evaluate an expression as a single item.Evaluate this variablevoidexport(ExpressionPresenter destination) Diagnostic print of expression structure.voidFix up this variable reference to a Binding object, which enables the value of the variable to be located at run-time.Get the object bound to the variableGet the display name of the variable.Get the EQName of the variable.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.intDetermine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.Determine the data type of the expression, if possibleintReturn the net cost of evaluating this expression, excluding the cost of evaluating its operands.Get the innermost scoping expression of this expression, for expressions that directly depend on something in the dynamic context.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.Get the (partial) name of a class that supports streaming of this kind of expressionGet the variable namebooleanDetermine whether this variable reference is filteredbooleanTest whether this variable reference is flattened - that is, whether it is atomized etcbooleanisInLoop()Ask whether this variable reference appears in a loop relative to its declaration.Get the value of this variable in a given context.optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) Optimize the expression.voidprocess(Outputter output, XPathContext c) Process the instructionvoidvoidrefineVariableType(ItemType type, int cardinality, GroundedValue constantValue, int properties) Provide additional information about the type of the variable, typically derived by analyzing the initializer of the variable bindingvoidsetFiltered(boolean filtered) Mark an expression as filtered: that is, it appears as the base expression in a filter expression.voidsetFlattened(boolean flattened) Mark an expression as being "flattened".voidsetInLoop(boolean inLoop) Say whether this variable reference appears in a loop relative to its declaration.voidsetStaticType(SequenceType type, GroundedValue value, int properties) Set static type.voidSet the variable namebooleanAsk whether the expression supports lazy evaluation.Produce a short string identifying the expression for use in error messagestoString()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.typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) Type-check the expression.Methods inherited from class net.sf.saxon.expr.ExpressionadoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, evaluateAsString, explain, getCardinality, getConfiguration, getCost, getDependencies, getElaborator, getEvaluationMethod, getExtraProperty, getLocalRetainedStaticContext, getLocation, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, 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, operands, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocationMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.sf.saxon.trace.TraceablegatherProperties
- 
Field Details- 
binding
- 
staticType
- 
constantValue
 
- 
- 
Constructor Details- 
VariableReferenceCreate a Variable Reference- Parameters:
- name- the name of the variable
 
- 
VariableReferenceCreate a Variable Reference- Parameters:
- binding- the variable binding to which this variable refers
 
 
- 
- 
Method Details- 
setVariableNameSet the variable name- Parameters:
- name- the name of the variable
 
- 
getVariableNameGet the variable name- Returns:
- the name of the variable
 
- 
copyCreate a clone copy of this VariableReference- Specified by:
- copyin class- Expression
- Parameters:
- rebindings- variables that need to switch to new bindings
- Returns:
- the cloned copy
 
- 
getNetCostpublic int getNetCost()Description copied from class:ExpressionReturn the net cost of evaluating this expression, excluding the cost of evaluating its operands. We take the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one).- Overrides:
- getNetCostin class- Expression
- Returns:
- the intrinsic cost of this operation, excluding the costs of evaluating the operands
 
- 
copyFrom
- 
setStaticTypeSet static type. This is a callback from the variable declaration object. As well as supplying the static type, it may also supply a compile-time value for the variable. As well as the type information, other static properties of the value are supplied: for example, whether the value is an ordered node-set.- Specified by:
- setStaticTypein interface- BindingReference
- Parameters:
- type- the static type of the variable
- value- the value of the variable if this is a compile-time constant, or null otherwise
- properties- static properties of the expression to which the variable is bound
 
- 
setFlattenedpublic void setFlattened(boolean flattened) Mark an expression as being "flattened". This is a collective term that includes extracting the string value or typed value, or operations such as simple value construction that concatenate text nodes before atomizing. The implication of all of these is that although the expression might return nodes, the identity of the nodes has no significance. This is called during type checking of the parent expression. At present, only variable references take any notice of this notification.- Overrides:
- setFlattenedin class- Expression
- Parameters:
- flattened- set to true if the result of the expression is atomized or otherwise turned into an atomic value
 
- 
isFlattenedpublic boolean isFlattened()Test whether this variable reference is flattened - that is, whether it is atomized etc- Returns:
- true if the value of the variable is atomized, or converted to a string or number
 
- 
setFilteredpublic void setFiltered(boolean filtered) Mark an expression as filtered: that is, it appears as the base expression in a filter expression. This notification currently has no effect except when the expression is a variable reference.- Overrides:
- setFilteredin class- Expression
- Parameters:
- filtered- if true, marks this expression as the base of a filter expression
 
- 
isFilteredpublic boolean isFiltered()Determine whether this variable reference is filtered- Returns:
- true if the value of the variable is filtered by a predicate
 
- 
isInLooppublic boolean isInLoop()Ask whether this variable reference appears in a loop relative to its declaration. By default, when in doubt, returns true. This is calculated during type-checking.- Returns:
- true if this variable reference occurs in a loop, where the variable declaration is outside the loop
 
- 
setInLooppublic void setInLoop(boolean inLoop) Say whether this variable reference appears in a loop relative to its declaration.- Parameters:
- inLoop- true if this variable reference occurs in a loop, where the variable declaration is outside the loop
 
- 
typeCheckpublic Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException Type-check the expression. At this stage details of the static type must be known. If the variable has a compile-time value, this is substituted for the variable reference- Overrides:
- typeCheckin class- Expression
- Parameters:
- visitor- an expression visitor
- contextInfo- 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)
 
- 
recomputeInLooppublic void recomputeInLoop()
- 
optimizepublic Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException Optimize the expression. At this stage details of the static type must be known. If the variable has a compile-time value, this is substituted for the variable reference- Overrides:
- optimizein class- Expression
- Parameters:
- visitor- an expression visitor
- contextItemType- 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 to- Type.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)
 
- 
fixupFix up this variable reference to a Binding object, which enables the value of the variable to be located at run-time.- Specified by:
- fixupin interface- BindingReference
- Parameters:
- newBinding- the Binding to which the variable refers
 
- 
refineVariableTypepublic void refineVariableType(ItemType type, int cardinality, GroundedValue constantValue, int properties) Provide additional information about the type of the variable, typically derived by analyzing the initializer of the variable binding- Parameters:
- type- the item type of the variable
- cardinality- the cardinality of the variable
- constantValue- the actual value of the variable, if this is known statically, otherwise null
- properties- additional static properties of the variable's initializer
 
- 
getItemTypeDetermine the data type of the expression, if possible- Specified by:
- getItemTypein class- Expression
- Returns:
- the type of the variable, if this can be determined statically; otherwise Type.ITEM (meaning not known in advance)
 
- 
getStaticUTypeGet the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.- Overrides:
- getStaticUTypein class- Expression
- Parameters:
- contextItemType- the static context item type
- Returns:
- the static item type of the expression according to the XSLT 3.0 defined rules
 
- 
getIntegerBoundsFor 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 class- Expression
- Returns:
- the lower and upper bounds of integer values in the result, or null to indicate unknown or not applicable.
 
- 
computeCardinalityprotected int computeCardinality()Get the static cardinality- Specified by:
- computeCardinalityin class- Expression
- 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.
 
- 
computeSpecialPropertiesprotected int computeSpecialProperties()Determine the special properties of this expression- Overrides:
- computeSpecialPropertiesin class- Expression
- Returns:
- StaticProperty.NO_NODES_NEWLY_CREATED(unless the variable is assignable using saxon:assign)
 
- 
supportsLazyEvaluationpublic boolean supportsLazyEvaluation()Ask whether the expression supports lazy evaluation.- Overrides:
- supportsLazyEvaluationin class- Expression
- Returns:
- false either if the expression cannot be evaluated lazily because it has dependencies that cannot be saved in the context, or because lazy evaluation is pointless (for example, for literals and variable references).
 
- 
equalsTest if this expression is the same as another expression. (Note, we only compare expressions that have the same static and dynamic context).- Overrides:
- equalsin class- Expression
- 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.
 
- 
computeHashCodeprotected int computeHashCode()get HashCode for comparing two expressions- Overrides:
- computeHashCodein class- Expression
- Returns:
- a computed hash code
 
- 
getIntrinsicDependenciespublic int getIntrinsicDependencies()Description copied from class:ExpressionDetermine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".- Overrides:
- getIntrinsicDependenciesin class- Expression
- Returns:
- an integer containing bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
 
- 
getImplementationMethodpublic 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 all three methods natively.- Specified by:
- getImplementationMethodin class- Expression
- Returns:
- the implementation method, for example Expression.ITERATE_METHODorExpression.EVALUATE_METHODorExpression.PROCESS_METHOD
 
- 
getScopingExpressionGet the innermost scoping expression of this expression, for expressions that directly depend on something in the dynamic context. For example, in the case of a local variable reference this is the expression that causes the relevant variable to be bound; for a context item expression it is the innermost focus-setting container. For expressions that have no intrinsic dependency on the dynamic context, the value returned is null; the scoping container for such an expression is the innermost scoping container of its operands.- Overrides:
- getScopingExpressionin class- Expression
- Returns:
- the innermost scoping container of this expression
 
- 
addToPathMapAdd a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression. - Overrides:
- addToPathMapin class- Expression
- Parameters:
- pathMap- the PathMap to which the expression should be added
- pathMapNodeSet- the PathMapNodeSet to which the paths embodied in this expression should be added
- Returns:
- the pathMapNodeSet representing the points in the source document that are both reachable by this expression, and that represent possible results of this expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.
 
- 
iterateGet the value of this variable in a given context.- Overrides:
- iteratein class- Expression
- Parameters:
- c- the XPathContext which contains the relevant variable bindings
- Returns:
- the value of the variable, if it is defined
- Throws:
- XPathException- if the variable is undefined
 
- 
evaluateItemDescription copied from class:ExpressionEvaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.- Overrides:
- evaluateItemin class- Expression
- Parameters:
- c- 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
 
- 
processDescription copied from class:ExpressionProcess the instruction- Overrides:
- processin class- Expression
- Parameters:
- output- the destination for the result
- c- The dynamic context, giving access to the current node, the current variables, etc.
- Throws:
- XPathException- if a dynamic error occurs
 
- 
evaluateVariableEvaluate this variable- Parameters:
- c- the XPath dynamic context
- Returns:
- the value of the variable
- Throws:
- XPathException- if any error occurs
 
- 
getBindingGet the object bound to the variable- Returns:
- the Binding which declares this variable and associates it with a value
 
- 
getDisplayNameGet the display name of the variable. This is taken from the variable binding if possible- Returns:
- the display name (a lexical QName
 
- 
getEQNameGet the EQName of the variable. This is taken from the variable binding if possible. The returned name is in the format Q{uri}local if in a namespace, or the local name alone if not.- Returns:
- the EQName, or the local name if not in a namespace
 
- 
toStringThe 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:
- toStringin class- Expression
- Returns:
- a representation of the expression as a string
 
- 
toShortStringProduce a short string identifying the expression for use in error messages- Overrides:
- toShortStringin class- Expression
- Returns:
- a short string, sufficient to identify the expression
 
- 
getExpressionNameGet a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
- getExpressionNamein class- Expression
- 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 export() output displaying the expression.
 
- 
exportDiagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
- exportin interface- ExportAgent
- Specified by:
- exportin class- Expression
- Parameters:
- destination- 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.
 
- 
getStreamerNameGet the (partial) name of a class that supports streaming of this kind of expression- Overrides:
- getStreamerNamein class- Expression
- 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
 
 
-