Class ContextValueExpression

java.lang.Object
net.sf.saxon.expr.Expression
net.sf.saxon.expr.ContextValueExpression
All Implemented Interfaces:
ExportAgent, Locatable, IdentityComparable, Traceable

public class ContextValueExpression extends Expression
This class represents the expression "(dot)", when the static context indicates that the context value may be a general sequence. In XPath 4.0, the context item is generalized to a context value. The idea of a context item is so deeply embedded, however, that for the most part we still assume that the context value will be a single item. However, if the static context tells us that the context value may be bound to a general sequence (for example, in an array filter expression $array?[filter]), the context item expression is rewritten as a context value expression. In this situation the dynamic context holds the context value wrapped as a Parcel to turn it into a single item.
  • Constructor Details

    • ContextValueExpression

      public ContextValueExpression()
      Create the expression
  • Method Details

    • getExpressionName

      public String getExpressionName()
      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
      getExpressionName in 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 explain() output displaying the expression.
    • copy

      public Expression copy(RebindingMap rebindings)
      Create a clone copy of this expression
      Specified by:
      copy in class Expression
      Parameters:
      rebindings - variables that must be re-bound
      Returns:
      a copy of this expression
    • typeCheck

      public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
      Type-check the expression.
      Overrides:
      typeCheck in 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)
    • 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 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)
    • getItemType

      public ItemType getItemType()
      Determine the item type
      Specified by:
      getItemType in class Expression
      Returns:
      a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
    • 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 class Expression
      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
    • computeCardinality

      protected int computeCardinality()
      Get the static cardinality
      Specified by:
      computeCardinality in 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 return StaticProperty.ALLOWS_ZERO if the result is known to be an empty sequence, or StaticProperty.ALLOWS_MANY if if is known to return a sequence of length two or more.
    • computeSpecialProperties

      protected int computeSpecialProperties()
      Determine the special properties of this expression
      Overrides:
      computeSpecialProperties in class Expression
      Returns:
      the value StaticProperty.NO_NODES_NEWLY_CREATED
    • getImplementationMethod

      public int getImplementationMethod()
      Description copied from class: Expression
      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.
      Specified by:
      getImplementationMethod in class Expression
      Returns:
      the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD
    • equals

      public boolean equals(Object other)
      Is this expression the same as another expression?
      Overrides:
      equals in 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.
    • computeHashCode

      protected int computeHashCode()
      get HashCode for comparing two expressions
      Overrides:
      computeHashCode in class Expression
      Returns:
      a computed hash code
    • getIntrinsicDependencies

      public int getIntrinsicDependencies()
      Description copied from class: Expression
      Determine 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:
      getIntrinsicDependencies in class Expression
      Returns:
      an integer containing bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
    • isSubtreeExpression

      public boolean isSubtreeExpression()
      Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.
      Overrides:
      isSubtreeExpression in class Expression
      Returns:
      true if the expression has no dependencies on the context node, or if the only dependencies on the context node are downward selections using the self, child, descendant, attribute, and namespace axes.
    • getNetCost

      public int getNetCost()
      Description copied from class: Expression
      Return 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:
      getNetCost in class Expression
      Returns:
      the intrinsic cost of this operation, excluding the costs of evaluating the operands
    • toPattern

      public Pattern toPattern(Configuration config, boolean firstInPath) throws XPathException
      Convert this expression to an equivalent XSLT pattern
      Overrides:
      toPattern in class Expression
      Parameters:
      config - the Saxon configuration
      firstInPath -
      Returns:
      the equivalent pattern
      Throws:
      XPathException - if conversion is not possible
    • getStreamerName

      public String getStreamerName()
      Get the (partial) name of a class that supports streaming of this kind of expression
      Overrides:
      getStreamerName in 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
    • iterate

      public SequenceIterator iterate(XPathContext context) throws XPathException
      Iterate over the value of the expression
      Overrides:
      iterate in class Expression
      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
    • reportAbsentContext

      public void reportAbsentContext(XPathContext context) throws XPathException
      Throws:
      XPathException
    • toString

      public 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 class Expression
      Returns:
      a representation of the expression as a string
    • export

      public void export(ExpressionPresenter destination) throws XPathException
      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
      export in interface ExportAgent
      Specified by:
      export in 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.
    • toShortString

      public String toShortString()
      Description copied from class: Expression
      Produce a short string identifying the expression for use in error messages
      Overrides:
      toShortString in class Expression
      Returns:
      a short string, sufficient to identify the expression
    • getElaborator

      public Elaborator getElaborator()
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      a suitable elaborator