Class TraceExpression

All Implemented Interfaces:
ExportAgent, Locatable, IdentityComparable, Traceable

public class TraceExpression extends Instruction
A wrapper expression used to trace expressions in XSLT and XQuery.
  • Constructor Details

    • TraceExpression

      public TraceExpression(Expression child)
      Create a trace expression that traces execution of a given child expression
      Parameters:
      child - the expression to be traced. This will be available to the TraceListener as the value of the "expression" property of the InstructionInfo.
  • Method Details

    • getChild

      public Expression getChild()
    • getBody

      public Expression getBody()
    • operands

      public Iterable<Operand> operands()
      Description copied from class: Expression
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.

      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.

      Specified by:
      operands in class Instruction
      Returns:
      an iterator containing the sub-expressions of this expression
    • setProperty

      public void setProperty(String name, Object value)
      Set a named property of the instruction/expression
      Parameters:
      name - the name of the property
      value - the value of the property
    • getProperty

      public Object getProperty(String name)
      Get a named property of the instruction/expression
      Overrides:
      getProperty in class Expression
      Parameters:
      name - the name of the property
      Returns:
      the value of the property
    • getProperties

      public Iterator<String> getProperties()
      Get an iterator over all the properties available. The values returned by the iterator will be of type String, and each string can be supplied as input to the getProperty() method to retrieve the value of the property.
      Overrides:
      getProperties in class Expression
      Returns:
      an iterator over the properties
    • getExpressionName

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

      public Expression copy(RebindingMap rebindings)
      Description copied from class: Expression
      Copy an expression. This makes a deep copy.
      Specified by:
      copy in class Expression
      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
    • isUpdatingExpression

      public boolean isUpdatingExpression()
      Determine whether this is an updating expression as defined in the XQuery update specification
      Overrides:
      isUpdatingExpression in class Expression
      Returns:
      true if this is an updating expression
    • isVacuousExpression

      public boolean isVacuousExpression()
      Determine whether this is a vacuous expression as defined in the XQuery update specification
      Overrides:
      isVacuousExpression in class Expression
      Returns:
      true if this expression is vacuous
    • checkForUpdatingSubexpressions

      public void checkForUpdatingSubexpressions() throws XPathException
      Check to ensure that this expression does not contain any inappropriate updating subexpressions. This check is overridden for those expressions that permit updating subexpressions.
      Overrides:
      checkForUpdatingSubexpressions in class Expression
      Throws:
      XPathException - if the expression has a non-permitted updating subexpression
    • getImplementationMethod

      public int getImplementationMethod()
      Description copied from class: Instruction
      An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is preferred. For instructions this is the process() method.
      Overrides:
      getImplementationMethod in class Instruction
      Returns:
      the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD
    • getItemType

      public ItemType getItemType()
      Get the item type of the items returned by evaluating this instruction
      Overrides:
      getItemType in class Instruction
      Returns:
      the static item type of the instruction
    • getCardinality

      public int getCardinality()
      Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.
      Overrides:
      getCardinality in class Expression
      Returns:
      one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).
    • getDependencies

      public int getDependencies()
      Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as StaticProperty.DEPENDS_ON_CONTEXT_ITEM and StaticProperty.DEPENDS_ON_CURRENT_ITEM. The default implementation combines the intrinsic dependencies of this expression with the dependencies of the subexpressions, computed recursively. This is overridden for expressions such as FilterExpression where a subexpression's dependencies are not necessarily inherited by the parent expression.
      Overrides:
      getDependencies in class Expression
      Returns:
      a set of bit-significant flags identifying the dependencies of the expression
    • mayCreateNewNodes

      public final boolean mayCreateNewNodes()
      Determine whether this instruction potentially creates new nodes.
      Overrides:
      mayCreateNewNodes in class Instruction
      Returns:
      true if the instruction creates new nodes under some input conditions (or if it can't be proved that it doesn't)
    • equals

      public boolean equals(Object other)
      Description copied from class: Expression
      The equals() test for expressions returns true if it can be determined that two expressions (given their static context) will return the same result in all circumstances. The value false is returned if this is not the case or if it cannot be determined to be the case.

      During the various phases of compilation, expression objects are mutable. Changing an expression may change its hashCode, and may change the result of equals() comparisons. Expressions should therefore not be held in data structures such as maps and sets that depend on equality comparison unless they are no longer subject to such mutation.

      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()
      Compute a hash code, which will then be cached for later use
      Overrides:
      computeHashCode in class Expression
      Returns:
      a computed hash code
    • getNetCost

      public int getNetCost()
      Return the estimated cost of evaluating an expression. For a TraceExpression we return zero, because ideally we don't want trace expressions to affect optimization decisions.
      Overrides:
      getNetCost in class Instruction
      Returns:
      zero
    • evaluateItem

      public Item evaluateItem(XPathContext context) throws XPathException
      Evaluate 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:
      evaluateItem in class Instruction
      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
    • iterate

      public SequenceIterator iterate(XPathContext context) throws XPathException
      Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.
      Overrides:
      iterate in class Instruction
      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
    • getInstructionNameCode

      public int getInstructionNameCode()
      Description copied from class: Instruction
      Get the namecode of the instruction for use in diagnostics
      Overrides:
      getInstructionNameCode in class Instruction
      Returns:
      a code identifying the instruction: typically but not always the fingerprint of a name in the XSLT namespace
    • optimize

      public Expression 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 class Expression
      Parameters:
      visitor - an expression visitor
      contextInfo - 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)
    • export

      public void export(ExpressionPresenter out) throws XPathException
      Export the expression structure. The abstract expression tree is written to the supplied output destination. Note: trace expressions are omitted from the generated SEF file.
      Specified by:
      export in interface ExportAgent
      Specified by:
      export in class Expression
      Parameters:
      out - 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()
      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()
      Description copied from class: Expression
      Make an elaborator for this expression
      Overrides:
      getElaborator in class Expression
      Returns:
      an appropriate Elaborator