lux.xpath
Class AbstractExpression

java.lang.Object
  extended by lux.xpath.AbstractExpression
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
AttributeConstructor, BinaryOperation, CastableExpression, CommentConstructor, ComputedElementConstructor, Conditional, DocumentConstructor, Dot, ElementConstructor, FLWOR, FunCall, InstanceOf, Let, LiteralExpression, PathExpression, PathStep, Predicate, ProcessingInstructionConstructor, Root, Satisfies, Sequence, Subsequence, TextConstructor, TreatAs, UnaryMinus, Variable

public abstract class AbstractExpression
extends Object
implements Visitable

An abstract XPath or XQuery expression. This class and its subclasses represent XPath expressions. Their toString() methods return valid XPath.


Nested Class Summary
static class AbstractExpression.Type
           
 
Field Summary
protected  AbstractExpression[] subs
           
protected  AbstractExpression sup
           
 
Constructor Summary
protected AbstractExpression(AbstractExpression.Type type)
           
 
Method Summary
 void acceptSubs(ExpressionVisitor visitor)
           
protected  void appendSub(StringBuilder buf, AbstractExpression sub)
          append the sub-expression to the buffer, wrapping it in parentheses if its precedence is lower than or equal to this expression's.
 VariableContext getBindingContext()
          If this expression depends "directly" on a variable, return that variable's binding context: a for or let clause, or a global variable definition.
 AbstractExpression getLastContextStep()
          This method is called by the optimizer in order to determine an element or attribute QName (or wildcard) against which some expression is being compared, in order to generate an appropriate text query.
abstract  int getPrecedence()
           
 AbstractExpression getRoot()
           
 AbstractExpression[] getSubs()
           
 AbstractExpression getSuper()
           
 AbstractExpression getTail()
           
 AbstractExpression.Type getType()
          Most types will correspond one-one with a subclass of AbstractExpression, but this enumerated value provides an integer equivalent that should be useful for efficient switch operations, encoding and the like.
 boolean isAbsolute()
           
 boolean isDocumentOrdered()
           
 AbstractExpression replaceRoot(AbstractExpression replacement)
          If this has absolute subexpressions, replace them with the replacement expression (see Root.replaceRoot(AbstractExpression)
protected  void setSubs(AbstractExpression... subExprs)
           
 String toString()
           
abstract  void toString(StringBuilder buf)
          Each subclass must implement the toString(StringBuilder) method by rendering itself as a syntatically valid XPath/XQuery expression in the given buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface lux.xpath.Visitable
accept
 

Field Detail

sup

protected AbstractExpression sup

subs

protected AbstractExpression[] subs
Constructor Detail

AbstractExpression

protected AbstractExpression(AbstractExpression.Type type)
Method Detail

getType

public AbstractExpression.Type getType()
Most types will correspond one-one with a subclass of AbstractExpression, but this enumerated value provides an integer equivalent that should be useful for efficient switch operations, encoding and the like. TODO: determine if this is just a waste of time; we could be using instanceof?

Returns:
the type of this expression

acceptSubs

public void acceptSubs(ExpressionVisitor visitor)

getSuper

public AbstractExpression getSuper()
Returns:
the super (containing) expression, or null if this is the outermost expression in its tree

getSubs

public AbstractExpression[] getSubs()
Returns:
the sub-expressions of this expression.

setSubs

protected void setSubs(AbstractExpression... subExprs)

toString

public abstract void toString(StringBuilder buf)
Each subclass must implement the toString(StringBuilder) method by rendering itself as a syntatically valid XPath/XQuery expression in the given buffer.

Parameters:
buf -

toString

public String toString()
Overrides:
toString in class Object

getRoot

public AbstractExpression getRoot()
Returns:
the root of this expression: this will either be a Root(/), a function returning document nodes, or null.

isAbsolute

public boolean isAbsolute()
Returns:
whether this expression is a Root or another expression that introduces a new query scope, such as a PathExpression beginning with a Root (/), or a subsequence of another absolute expression. This method returns false, supplying the common default.

isDocumentOrdered

public boolean isDocumentOrdered()
Returns:
whether this expression is proven to return results in document order. This method returns true iff all its subs return true, or it has none. Warning: incorrect results may occur if document-ordering is falsely asserted.

replaceRoot

public AbstractExpression replaceRoot(AbstractExpression replacement)
If this has absolute subexpressions, replace them with the replacement expression (see Root.replaceRoot(AbstractExpression)

Parameters:
replacement - the expression to use in place of '/'
Returns:
this

appendSub

protected void appendSub(StringBuilder buf,
                         AbstractExpression sub)
append the sub-expression to the buffer, wrapping it in parentheses if its precedence is lower than or equal to this expression's. We need parens when precedence is equal because otherwise operations simply group left or right, but we have the actual grouping encoded in the expression tree and need to preserve that. Note: we can't just blindly wrap everything in parentheses because parens have special meaning in some XPath expressions where they can introduce document-ordering.

Parameters:
buf - the buffer to append to
sub - the sub-expression

getTail

public AbstractExpression getTail()
Returns:
the tail of this expression; ie everything after the head is removed, which is null unless this is a PathExpression PathExpression.getTail().

getLastContextStep

public AbstractExpression getLastContextStep()
This method is called by the optimizer in order to determine an element or attribute QName (or wildcard) against which some expression is being compared, in order to generate an appropriate text query.

Returns:
the rightmost path step in the context of this expression.

getBindingContext

public VariableContext getBindingContext()
If this expression depends "directly" on a variable, return that variable's binding context: a for or let clause, or a global variable definition. This recurses through variables, so if there are aliases it retrieves the ultimate context. We need to define directly dependent precisely; what it's used for is to determine with an order by expression is dependent on a for-variable, and ultimately whether an order by optimization can be applied.

Returns:
the binding context of the variable on which this expression depends, or null

getPrecedence

public abstract int getPrecedence()
Returns:
a number indicating the *outer* precedence of this expression. Expressions with lower precedence numbers have lower precedence, ie bind more loosely, than expressions with higher precedence. Expressions with no sub-expressions are assigned a high precedence. Complex expressions can be seen as having an inner and an outer precedence; for example function call expressions behave as a comma with regard to their sub-expressions, the arguments, and like parentheses to their enclosing expression.


Copyright © 2013. All Rights Reserved.