net.sf.saxon.expr

Class ExpressionVisitor

public class ExpressionVisitor extends Object

The ExpressionVisitor supports the various phases of processing of an expression tree which require a recursive walk of the tree structure visiting each node in turn. In maintains a stack holding the ancestor nodes of the node currently being visited.
Constructor Summary
ExpressionVisitor()
Create an ExpressionVisitor
Method Summary
ConfigurationgetConfiguration()
Get the Saxon configuration
ExpressiongetCurrentExpression()
Get the current expression, the one being visited
ExecutablegetExecutable()
Get the Executable containing the expressions being visited
ExpressiongetParentExpression()
Get the parent expression of the current expression in the expression tree
Stack<Expression>getStack()
Get the stack containing all the expressions currently being visited
StaticContextgetStaticContext()
Get the static context for the expressions being visited.
booleanisLoopingSubexpression(Expression ancestor)
Return true if the current expression at the top of the visitor's stack is evaluated repeatedly when a given ancestor expression is evaluated once
static ExpressionVisitormake(StaticContext env)
Factory method: make an expression visitor
Expressionoptimize(Expression exp, ItemType contextItemType)
Optimize an expression, via the ExpressionVisitor
voidresetStaticProperties()
Reset the static properties for the current expression and for all its containing expressions.
voidsetConfiguration(Configuration configuration)
Set the Saxon configuration
voidsetExecutable(Executable executable)
Set the Executable containing the expressions being visited
voidsetStack(Stack<Expression> stack)
Set the stack used to hold the expressions being visited
voidsetStaticContext(StaticContext staticContext)
Set the static context for the expressions being visited.
Expressionsimplify(Expression exp)
Simplify an expression, via the ExpressionVisitor
ExpressiontypeCheck(Expression exp, ItemType contextItemType)
Type check an expression, via the ExpressionVisitor

Constructor Detail

ExpressionVisitor

public ExpressionVisitor()
Create an ExpressionVisitor

Method Detail

getConfiguration

public Configuration getConfiguration()
Get the Saxon configuration

Returns: the Saxon configuration

getCurrentExpression

public Expression getCurrentExpression()
Get the current expression, the one being visited

Returns: the current expression

getExecutable

public Executable getExecutable()
Get the Executable containing the expressions being visited

Returns: the Executable

getParentExpression

public Expression getParentExpression()
Get the parent expression of the current expression in the expression tree

Returns: the parent of the current expression (or null if this is the root)

getStack

public Stack<Expression> getStack()
Get the stack containing all the expressions currently being visited

Returns: the expression stack holding all the containing expressions of the current expression; the objects on this Stack are instances of Expression

getStaticContext

public StaticContext getStaticContext()
Get the static context for the expressions being visited. Note: this may not reflect all changes in static context (e.g. namespace context, base URI) applying to nested expressions

Returns: the static context

isLoopingSubexpression

public boolean isLoopingSubexpression(Expression ancestor)
Return true if the current expression at the top of the visitor's stack is evaluated repeatedly when a given ancestor expression is evaluated once

Parameters: ancestor the ancestor expression. May be null, in which case the search goes all the way to the base of the stack.

Returns: true if the current expression is evaluated repeatedly

make

public static ExpressionVisitor make(StaticContext env)
Factory method: make an expression visitor

Parameters: env the static context

Returns: the new expression visitor

optimize

public Expression optimize(Expression exp, ItemType contextItemType)
Optimize an expression, via the ExpressionVisitor

Parameters: exp the expression to be typechecked contextItemType the static type of the context item for this expression

Returns: the rewritten expression

Throws: XPathException

resetStaticProperties

public final void resetStaticProperties()
Reset the static properties for the current expression and for all its containing expressions. This should be done whenever the expression is changed in a way that might affect the properties. It causes the properties to be recomputed next time they are needed.

setConfiguration

public void setConfiguration(Configuration configuration)
Set the Saxon configuration

Parameters: configuration the Saxon configuration

setExecutable

public void setExecutable(Executable executable)
Set the Executable containing the expressions being visited

Parameters: executable the Executable

setStack

public void setStack(Stack<Expression> stack)
Set the stack used to hold the expressions being visited

Parameters: stack the expression stack

setStaticContext

public void setStaticContext(StaticContext staticContext)
Set the static context for the expressions being visited. Note: this may not reflect all changes in static context (e.g. namespace context, base URI) applying to nested expressions

Parameters: staticContext the static context

simplify

public Expression simplify(Expression exp)
Simplify an expression, via the ExpressionVisitor

Parameters: exp the expression to be simplified

Returns: the simplified expression

Throws: XPathException

typeCheck

public Expression typeCheck(Expression exp, ItemType contextItemType)
Type check an expression, via the ExpressionVisitor

Parameters: exp the expression to be typechecked contextItemType the static type of the context item for this expression

Returns: the expression that results from type checking (this may be wrapped in expressions that perform dynamic checking of the item type or cardinality, or that perform atomization or numeric promotion)

Throws: XPathException if static type checking fails, that is, if the expression cannot possibly deliver a value of the required type