## net.sf.saxon.expr
Class ExpressionTool

    java.lang.Object
      net.sf.saxon.expr.ExpressionTool

public class ExpressionTool
extends java.lang.Object

This class, ExpressionTool, contains a number of useful static methods for manipulating expressions. Most importantly, it provides the factory method make() for constructing a new expression

Method Summary
`static int` `allocateSlots(Expression exp, int nextFree, SlotManager frame)` Allocate slot numbers to range variables
`static void` `copyLocationInfo(Expression from, Expression to)` Copy location information (currently the line number and parent) from one expression to another
`static boolean` `dependsOnVariable(Expression e, Binding[] bindingList)` Determine whether an expression depends on any one of a set of variables
`static Value` `eagerEvaluate(Expression exp, XPathContext context)` Evaluate an expression now; lazy evaluation is not permitted in this case
`static void` `ebvError(java.lang.String reason)`
`static boolean` `effectiveBooleanValue(SequenceIterator iterator)` Determine the effective boolean value of a sequence, given an iterator over the sequence
`static javax.xml.transform.SourceLocator` `getLocator(Expression exp)` Get location information for an expression in the form of a SourceLocator
`static java.lang.String` `indent(int level)` Construct indent string, for diagnostic output
`static boolean` `isRepeatedSubexpression(Expression parent, Expression child)` Determine whether an expression is a repeatedly-evaluated subexpression of a parent expression.
`static ValueRepresentation` `lazyEvaluate(Expression exp, XPathContext context, boolean save)` Do lazy evaluation of an expression.
`static Expression` `make(java.lang.String expression, StaticContext env, int start, int terminator, int lineNumber)` Parse an expression.
`static void` `makeParentReferences(Expression top)` Establish the links from subexpressions to their parent expressions, by means of a recursive tree walk.
`static boolean` `markTailFunctionCalls(Expression exp)`
`static Expression` `unsorted(Expression exp, boolean eliminateDuplicates)` Remove unwanted sorting from an expression, at compile time
`static Expression` `unsortedIfHomogeneous(Expression exp, boolean eliminateDuplicates)` Remove unwanted sorting from an expression, at compile time, if and only if it is known that the result of the expression will be homogeneous (all nodes, or all atomic values).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### make

    public static Expression make(java.lang.String expression,
                                  StaticContext env,
                                  int start,
                                  int terminator,
                                  int lineNumber)
                           throws XPathException

  Parse an expression. This performs the basic analysis of the expression against the grammar, it binds variable references and function calls to variable definitions and function definitions, and it performs context-independent expression rewriting for optimization purposes.

  Parameters:
    `expression` - The expression (as a character string)
    `env` - An object giving information about the compile-time context of the expression
    `terminator` - The token that marks the end of this expression; typically Tokenizer.EOF, but may for example be a right curly brace
    `lineNumber` - the line number of the start of the expression
  Returns:
    an object of type Expression
  Throws:
    `XPathException` - if the expression contains a static error

### copyLocationInfo

    public static void copyLocationInfo(Expression from,
                                        Expression to)

  Copy location information (currently the line number and parent) from one expression to another

### makeParentReferences

    public static void makeParentReferences(Expression top)

  Establish the links from subexpressions to their parent expressions, by means of a recursive tree walk.

### getLocator

    public static javax.xml.transform.SourceLocator getLocator(Expression exp)

  Get location information for an expression in the form of a SourceLocator

### isRepeatedSubexpression

    public static boolean isRepeatedSubexpression(Expression parent,
                                                  Expression child)

  Determine whether an expression is a repeatedly-evaluated subexpression of a parent expression. For example, the predicate in a filter expression is a repeatedly-evaluated subexpression of the filter expression.

### unsorted

    public static Expression unsorted(Expression exp,
                                      boolean eliminateDuplicates)
                               throws XPathException

  Remove unwanted sorting from an expression, at compile time

  Throws:
    `XPathException`

### unsortedIfHomogeneous

    public static Expression unsortedIfHomogeneous(Expression exp,
                                                   boolean eliminateDuplicates)
                                            throws XPathException

  Remove unwanted sorting from an expression, at compile time, if and only if it is known that the result of the expression will be homogeneous (all nodes, or all atomic values). This is done when we need the effective boolean value of a sequence: the EBV of a homogenous sequence does not depend on its order, but this is not true when atomic values and nodes are mixed: (N, AV) is true, but (AV, N) is an error.

  Throws:
    `XPathException`

### lazyEvaluate

    public static ValueRepresentation lazyEvaluate(Expression exp,
                                                   XPathContext context,
                                                   boolean save)
                                            throws XPathException

  Do lazy evaluation of an expression. This will return a value, which may optionally be a SequenceIntent, which is a wrapper around an iterator over the value of the expression.

  Parameters:
    `context` - the run-time evaluation context for the expression. If the expression is not evaluated immediately, then parts of the context on which the expression depends need to be saved as part of the Closure
    `save` - indicates whether the value should be saved while it is being evaluated, so that it can be used more than once.
  Returns:
    a value: either the actual value obtained by evaluating the expression, or a Closure containing all the information needed to evaluate it later
  Throws:
    `XPathException` - if any error occurs in evaluating the expression

### eagerEvaluate

    public static Value eagerEvaluate(Expression exp,
                                      XPathContext context)
                               throws XPathException

  Evaluate an expression now; lazy evaluation is not permitted in this case

  Parameters:
    `exp` - the expression to be evaluated
    `context` - the run-time evaluation context
  Returns:
    the result of evaluating the expression
  Throws:
    `XPathException` - if any dynamic error occurs evaluating the expression

### markTailFunctionCalls

    public static boolean markTailFunctionCalls(Expression exp)

### indent

    public static java.lang.String indent(int level)

  Construct indent string, for diagnostic output

  Parameters:
    `level` - the indentation level (the number of spaces to return)
  Returns:
    a string of "level*2" spaces

### allocateSlots

    public static int allocateSlots(Expression exp,
                                    int nextFree,
                                    SlotManager frame)

  Allocate slot numbers to range variables

  Parameters:
    `exp` - the expression whose range variables need to have slot numbers assigned
    `nextFree` - the next slot number that is available for allocation
    `frame` - a SlotManager object that is used to track the mapping of slot numbers to variable names for debugging purposes. May be null.
  Returns:
    the next unallocated slot number.

### effectiveBooleanValue

    public static boolean effectiveBooleanValue(SequenceIterator iterator)
                                         throws XPathException

  Determine the effective boolean value of a sequence, given an iterator over the sequence

  Parameters:
    `iterator` - An iterator over the sequence whose effective boolean value is required
  Returns:
    the effective boolean value
  Throws:
    `XPathException` - if a dynamic error occurs

### ebvError

    public static void ebvError(java.lang.String reason)
                         throws XPathException

  Throws:
    `XPathException`

### dependsOnVariable

    public static boolean dependsOnVariable(Expression e,
                                            Binding[] bindingList)

  Determine whether an expression depends on any one of a set of variables

  Parameters:
    `e` - the expression being tested
    `bindingList` - the set of variables being tested
  Returns:
    true if the expression depends on one of the given variables