|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.expr.parser.ExpressionTool
public class ExpressionTool
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
Field Summary | |
---|---|
static int |
CALL_EVALUATE_ITEM
|
static int |
EVALUATE_AND_MATERIALIZE_VARIABLE
|
static int |
EVALUATE_SUPPLIED_PARAMETER
|
static int |
EVALUATE_VARIABLE
|
static int |
ITERATE_AND_MATERIALIZE
|
static int |
LAZY_TAIL_EXPRESSION
|
static int |
MAKE_CLOSURE
|
static int |
MAKE_INDEXED_VARIABLE
|
static int |
MAKE_MEMO_CLOSURE
|
static int |
MAKE_SINGLETON_CLOSURE
|
static int |
NO_EVALUATION_NEEDED
|
static int |
PROCESS
|
static int |
RETURN_EMPTY_SEQUENCE
|
static int |
SHARED_APPEND_EXPRESSION
|
static int |
UNDECIDED
|
Method Summary | |
---|---|
static int |
allocateSlots(Expression exp,
int nextFree,
SlotManager frame)
Allocate slot numbers to range variables |
static boolean |
callsFunction(Expression exp,
StructuredQName qName)
Determine whether an expression contains a call on the function with a given fingerprint |
static boolean |
containsLocalParam(Expression exp)
Determine whether an expression contains a LocalParamSetter subexpression |
static void |
copyLocationInfo(Expression from,
Expression to)
Copy location information (the line number and reference to the container) from one expression to another |
static boolean |
dependsOnFocus(Expression exp)
Ask whether an expression has a dependency on the focus |
static boolean |
dependsOnVariable(Expression e,
Binding[] bindingList)
Determine whether an expression depends on any one of a set of variables |
static ValueRepresentation |
eagerEvaluate(Expression exp,
XPathContext context)
Evaluate an expression now; lazy evaluation is not permitted in this case |
static int |
eagerEvaluationMode(Expression exp)
Determine the method of evaluation to be used when lazy evaluation of an expression is preferred. |
static void |
ebvError(String reason)
Report an error in computing the effective boolean value of an expression |
static boolean |
effectiveBooleanValue(Item item)
Determine the effective boolean value of a single item |
static boolean |
effectiveBooleanValue(SequenceIterator<? extends Item> iterator)
Determine the effective boolean value of a sequence, given an iterator over the sequence |
static ValueRepresentation<? extends Item> |
evaluate(Expression exp,
int evaluationMode,
XPathContext context,
int ref)
Do lazy evaluation of an expression. |
static int |
expressionSize(Expression exp)
Get the size of an expression tree (the number of subexpressions it contains) |
static void |
gatherAllSubExpressions(Expression exp,
HashSet set)
Gather the set of all the subexpressions of an expression (the transitive closure) |
static void |
gatherCalledFunctionNames(Expression e,
List list)
Gather a list of the names of the user-defined functions which a given expression calls directly |
static void |
gatherCalledFunctions(Expression e,
List<UserFunction> list)
Gather a list of all the user-defined functions which a given expression calls directly |
static void |
gatherReferencedVariables(Expression e,
List<Binding> list)
Gather a list of all the variable bindings on which a given expression depends |
static void |
gatherVariableReferences(Expression exp,
Binding binding,
List<VariableReference> list)
Get a list of all references to a particular variable within a subtree |
static URI |
getBaseURI(StaticContext env,
SourceLocator locator,
boolean fail)
Determine the base URI of an expression, so that it can be saved on the expression tree for use when the expression is evaluated |
static String |
getCurrentDirectory()
|
static int |
getReferenceCount(Expression exp,
Binding binding,
boolean inLoop)
Determine how often a variable is referenced. |
static String |
indent(int level)
Construct indent string, for diagnostic output |
static boolean |
isAllowedInUpdatingContext(Expression exp)
Determine whether the expression is either an updating expression, or an expression that is permitted in a context where updating expressions are allowed |
static ValueRepresentation<? extends Item> |
lazyEvaluate(Expression exp,
XPathContext context,
int ref)
Do lazy evaluation of an expression. |
static int |
lazyEvaluationMode(Expression exp)
Determine the method of evaluation to be used when lazy evaluation of an expression is preferred. |
static Expression |
make(String expression,
StaticContext env,
Container container,
int start,
int terminator,
int lineNumber,
CodeInjector codeInjector)
Parse an XPath expression. |
static Expression |
makePathExpression(Expression start,
Expression step,
boolean sortAndDeduplicate)
Make a mapping expression. |
static int |
markTailFunctionCalls(Expression exp,
StructuredQName qName,
int arity)
Scan an expression to find and mark any recursive tail function calls |
static Stack<Expression> |
pathToContainedExpression(Expression ancestor,
Expression child,
Stack<Expression> expressionStack)
Check if child expression is a sub-expression of a expression |
static void |
rebindVariableReferences(Expression exp,
Binding oldBinding,
Binding newBinding)
Rebind all variable references to a binding |
static boolean |
refersToVariableOrFunction(Expression e)
Determine whether the expression contains any variable references or calls to user-written functions |
static void |
replaceNthSubexpression(Expression target,
int n,
Expression replacement)
Replace the Nth subexpression of an expression |
static void |
resetPropertiesWithinSubtree(Expression exp)
Reset cached static properties within a subtree, meaning that they have to be recalulated next time they are required |
static Expression |
resolveCallsToCurrentFunction(Expression exp,
Configuration config)
Resolve calls to the XSLT current() function within an expression |
static boolean |
selectsOutwards(Expression e)
Tests whether an expression performs navigation downwards or sideways |
static boolean |
selectsSideways(Expression e)
Tests whether an expression performs navigation downwards or sideways |
static Expression |
tryToFactorOutDot(Expression exp,
ItemType contextItemType)
Try to factor out dependencies on the context item, by rewriting an expression f(.) as let $dot := . |
static Expression |
unsorted(Optimizer opt,
Expression exp,
boolean retainAllNodes)
Remove unwanted sorting from an expression, at compile time |
static Expression |
unsortedIfHomogeneous(Optimizer opt,
Expression exp)
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 |
Field Detail |
---|
public static final int UNDECIDED
public static final int NO_EVALUATION_NEEDED
public static final int EVALUATE_VARIABLE
public static final int MAKE_CLOSURE
public static final int MAKE_MEMO_CLOSURE
public static final int RETURN_EMPTY_SEQUENCE
public static final int EVALUATE_AND_MATERIALIZE_VARIABLE
public static final int CALL_EVALUATE_ITEM
public static final int ITERATE_AND_MATERIALIZE
public static final int PROCESS
public static final int LAZY_TAIL_EXPRESSION
public static final int SHARED_APPEND_EXPRESSION
public static final int MAKE_INDEXED_VARIABLE
public static final int MAKE_SINGLETON_CLOSURE
public static final int EVALUATE_SUPPLIED_PARAMETER
Method Detail |
---|
public static Expression make(String expression, StaticContext env, Container container, int start, int terminator, int lineNumber, CodeInjector codeInjector) throws XPathException
expression
- The expression (as a character string)env
- An object giving information about the compile-time
context of the expressioncontainer
- The expression's containerstart
- position of the first significant character in the expressionterminator
- The token that marks the end of this expression; typically
Token.EOF, but may for example be a right curly bracelineNumber
- the line number of the start of the expressioncodeInjector
- true allows injection of tracing, debugging, or performance monitoring code; null if
not required
XPathException
- if the expression contains a static errorpublic static void copyLocationInfo(Expression from, Expression to)
from
- the expression containing the location informationto
- the expression to which the information is to be copiedpublic static Expression unsorted(Optimizer opt, Expression exp, boolean retainAllNodes) throws XPathException
opt
- the expression optimizerexp
- the expression to be optimizedretainAllNodes
- true if there is a need to retain exactly those nodes returned by exp
even if there are duplicates; false if the caller doesn't mind whether duplicate nodes
are retained or eliminated
XPathException
- if a static error is found while doing the rewritepublic static Expression unsortedIfHomogeneous(Optimizer opt, Expression exp) throws XPathException
opt
- the expression optimizerexp
- the expression to be optimized
XPathException
- if a static error is found while doing the rewritepublic static int lazyEvaluationMode(Expression exp)
exp
- the expression to be evaluated
public static int eagerEvaluationMode(Expression exp)
exp
- the expression to be evaluated
public static ValueRepresentation<? extends Item> evaluate(Expression exp, int evaluationMode, XPathContext context, int ref) throws XPathException
exp
- the expression to be evaluatedevaluationMode
- the evaluation mode for this expressioncontext
- 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 Closureref
- an indication of how the value will be used. The value 1 indicates that the value
is only expected to be used once, so that there is no need to keep it in memory. A small value >1
indicates multiple references, so the value will be saved when first evaluated. The special value
FILTERED indicates a reference within a loop of the form $x[predicate], indicating that the value
should be saved in a way that permits indexing.
XPathException
- if any error occurs in evaluating the
expressionpublic static ValueRepresentation<? extends Item> lazyEvaluate(Expression exp, XPathContext context, int ref) throws XPathException
exp
- the expression to be evaluatedcontext
- 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 Closureref
- an indication of how the value will be used. The value 1 indicates that the value
is only expected to be used once, so that there is no need to keep it in memory. A small value >1
indicates multiple references, so the value will be saved when first evaluated. The special value
FILTERED indicates a reference within a loop of the form $x[predicate], indicating that the value
should be saved in a way that permits indexing.
XPathException
- if any error occurs in evaluating the
expressionpublic static ValueRepresentation eagerEvaluate(Expression exp, XPathContext context) throws XPathException
exp
- the expression to be evaluatedcontext
- the run-time evaluation context
XPathException
- if any dynamic error occurs evaluating the
expressionpublic static int markTailFunctionCalls(Expression exp, StructuredQName qName, int arity)
exp
- the expression to be analyzedqName
- the name of the containing functionarity
- the arity of the containing function
public static String indent(int level)
level
- the indentation level (the number of spaces to return)
public static boolean containsLocalParam(Expression exp)
exp
- the expression to be testedpublic static int allocateSlots(Expression exp, int nextFree, SlotManager frame)
exp
- the expression whose range variables need to have slot numbers assignednextFree
- the next slot number that is available for allocationframe
- a SlotManager object that is used to track the mapping of slot numbers
to variable names for debugging purposes. May be null.
public static boolean effectiveBooleanValue(SequenceIterator<? extends Item> iterator) throws XPathException
iterator
- An iterator over the sequence whose effective boolean value is required
XPathException
- if a dynamic error occurspublic static boolean effectiveBooleanValue(Item item) throws XPathException
item
- the item whose effective boolean value is required
XPathException
- if a dynamic error occurspublic static void ebvError(String reason) throws XPathException
reason
- the nature of the error
XPathException
public static boolean dependsOnFocus(Expression exp)
exp
- the expression
public static boolean dependsOnVariable(Expression e, Binding[] bindingList)
e
- the expression being testedbindingList
- the set of variables being tested
public static void gatherReferencedVariables(Expression e, List<Binding> list)
e
- the expression being testedlist
- a list to which the bindings are to be added. The items in this list must
implement Binding
public static boolean refersToVariableOrFunction(Expression e)
e
- the expression being tested
public static boolean callsFunction(Expression exp, StructuredQName qName)
exp
- The expression being testedqName
- The name of the function
public static void gatherCalledFunctions(Expression e, List<UserFunction> list)
e
- the expression being testedlist
- a list of the functions that are called. The items in this list must
be objects of class UserFunction
public static void gatherCalledFunctionNames(Expression e, List list)
e
- the expression being testedlist
- a list of the functions that are called. The items in this list are strings in the format
"{uri}local/arity"public static void resetPropertiesWithinSubtree(Expression exp)
exp
- the root of the subtree within which static properties should be resetpublic static Expression resolveCallsToCurrentFunction(Expression exp, Configuration config) throws XPathException
exp
- the expression within which calls to current() should be resolvedconfig
- the Saxon configuration
XPathException
- if a static error is detectedpublic static void gatherVariableReferences(Expression exp, Binding binding, List<VariableReference> list)
exp
- the expression at the root of the subtreebinding
- the variable binding whose references are soughtlist
- a list to be populated with the references to this variablepublic static int getReferenceCount(Expression exp, Binding binding, boolean inLoop)
exp
- the expression within which variable references are to be countedbinding
- identifies the variable of interestinLoop
- true if the expression is within a loop, in which case a reference counts as many.
This should be set to false on the initial call, it may be set to true on an internal recursive
call
public static void gatherAllSubExpressions(Expression exp, HashSet set)
exp
- the parent expressionset
- the set to be populated; on return it will contain all the subexpressions.
Beware that testing for membership of a set of expressions relies on the equals() comparison,
which does not test identity.public static Stack<Expression> pathToContainedExpression(Expression ancestor, Expression child, Stack<Expression> expressionStack)
ancestor
- the ancestor expressionchild
- the child expressions.public static int expressionSize(Expression exp)
exp
- the expression whose size is required
public static void rebindVariableReferences(Expression exp, Binding oldBinding, Binding newBinding)
exp
- the expression whose contained variable references are to be reboundoldBinding
- the old binding for the variable referencesnewBinding
- the new binding to which the variables should be reboundpublic static Expression makePathExpression(Expression start, Expression step, boolean sortAndDeduplicate)
start
- the start expression (the first operand of "/")step
- the step expression (the second operand of "/")sortAndDeduplicate
- set to true if this is a path expression ("/") where the result needs to be
homogenous, and needs to be sorted and deduplicated if it consists of nodes. Set to false if the caller
knows that this is not necessary (typically because it has already been checked).
public static Expression tryToFactorOutDot(Expression exp, ItemType contextItemType)
exp
- the expression from which references to "." should be factored out if possiblecontextItemType
- the static type of the context item
public static boolean isAllowedInUpdatingContext(Expression exp)
exp
- the expression under test
public static void replaceNthSubexpression(Expression target, int n, Expression replacement)
target
- the parent expression whose subexpression is to be replacedn
- the index of the subexpression to be replaced (starting at zero)replacement
- the replacement subexpressionpublic static boolean selectsOutwards(Expression e)
e
- the expression
public static boolean selectsSideways(Expression e)
e
- the expression
public static String getCurrentDirectory()
public static URI getBaseURI(StaticContext env, SourceLocator locator, boolean fail) throws XPathException
env
- the static contextlocator
- location of the expression for error messagesfail
- if true, the method throws an exception when there is no absolute base URI; otherwise, the
method returns null @return the absolute base URI of the expression
XPathException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |