com.saxonica.expr
Class IndexedLookupExpression

java.lang.Object
  extended by net.sf.saxon.expr.Expression
      extended by com.saxonica.expr.IndexedLookupExpression
All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, EvaluableItem, SequenceIterable, InstructionInfo, Locator

public final class IndexedLookupExpression
extends Expression

An IndexedLookupExpression contains a base expression and a lookup expression. The base expression will always be a local variable reference. The expression returns true if the base expression (after atomization) contains the value of the lookup expression. That is, the expression is equivalent to exists(base[lookup]), except that lookup is evaluated with the same context as base.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, EVENT_FEED_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, PROCESS_METHOD, PUSH_SELECTION, staticProperties, WATCH_METHOD
 
Constructor Summary
IndexedLookupExpression(VariableReference base, Expression lookup, AtomicComparer comparer)
          Constructor
 
Method Summary
 int computeCardinality()
          Get the static cardinality of this expression
 int computeDependencies()
          Determine which aspects of the context the expression depends on.
 int computeSpecialProperties()
          Get the static properties of this expression (other than its type).
 Expression copy()
          Copy an expression.
 boolean effectiveBooleanValue(XPathContext context)
          Get the effective boolean value of the expression.
 boolean equals(Object other)
          Is this expression the same as another expression?
 Item evaluateItem(XPathContext context)
          Evaluate an expression as a single item.
 void explain(ExpressionPresenter destination)
          Diagnostic print of expression structure.
 AtomicComparer getAtomicComparer()
          Get the atomic comparer used
 Expression getBaseExpression()
          Get the underlying expression
 ItemType getItemType(TypeHierarchy th)
          Get the data type of the items returned
 Expression getLookup()
          Get the lookup expression
 Expression getLookupExpression()
          Get the expression to be searched
 int hashCode()
          get HashCode for comparing two expressions
 Iterator<Expression> iterateSubExpressions()
          Get the immediate subexpressions of this expression
 Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
          Perform optimisation of an expression and its subexpressions.
 Expression promote(PromotionOffer offer, Expression parent)
          Promote this expression if possible
 boolean replaceSubExpression(Expression original, Expression replacement)
          Replace one subexpression by a replacement subexpression
 Expression simplify(ExpressionVisitor visitor)
          Simplify an expression
 Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
          Type-check the expression
 
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeStaticProperties, doPromotion, dynamicError, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getEvaluationMethod, getExecutable, getExpressionName, getHostLanguage, getImplementationMethod, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toString, typeError
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexedLookupExpression

public IndexedLookupExpression(VariableReference base,
                               Expression lookup,
                               AtomicComparer comparer)
Constructor

Parameters:
base - A sequence expression denoting the sequence to be searched
lookup - An expression defining value to be sought
Method Detail

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the data type of the items returned

Specified by:
getItemType in class Expression
Parameters:
th - the type hierarchy cache
Returns:
an integer representing the data type

getBaseExpression

public Expression getBaseExpression()
Get the underlying expression

Returns:
the expression being filtered

getLookup

public Expression getLookup()
Get the lookup expression

Returns:
the expression acting as the filter predicate

getLookupExpression

public Expression getLookupExpression()
Get the expression to be searched

Returns:
the expression whose value will be searched

getAtomicComparer

public AtomicComparer getAtomicComparer()
Get the atomic comparer used

Returns:
the atomic comparer

simplify

public Expression simplify(ExpressionVisitor visitor)
                    throws XPathException
Simplify an expression

Overrides:
simplify in class Expression
Parameters:
visitor - an expression visitor
Returns:
the simplified expression
Throws:
XPathException - if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
Type-check the expression

Overrides:
typeCheck in class Expression
Parameters:
visitor - an expression visitor
contextItemType - 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 expression after type-checking (potentially modified to add run-time checks and/or conversions)

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
Perform optimisation of an expression and its subexpressions.

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
contextItemType - 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

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Specified by:
copy in class Expression
Returns:
the copy of the original expression

promote

public Expression promote(PromotionOffer offer,
                          Expression parent)
                   throws XPathException
Promote this expression if possible

Overrides:
promote in class Expression
Parameters:
offer - details of the promotion that is possible
parent -
Returns:
the promoted expression (or the original expression, unchanged)
Throws:
XPathException - if any error is detected

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()
Get the immediate subexpressions of this expression

Overrides:
iterateSubExpressions in class Expression
Returns:
the subexpressions, as an array

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Replace one subexpression by a replacement subexpression

Overrides:
replaceSubExpression in class Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

computeCardinality

public int computeCardinality()
Get the static cardinality of this expression

Specified by:
computeCardinality in class Expression
Returns:
the cardinality. The method attempts to determine the case where the filter predicate is guaranteed to select at most one item from the sequence being filtered

computeSpecialProperties

public int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-significant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.

Overrides:
computeSpecialProperties in class Expression
Returns:
the static properties of the expression, as a bit-significant value

equals

public boolean equals(Object other)
Is this expression the same as another expression?

Overrides:
equals in class Object
Parameters:
other - the expression to be compared with this one
Returns:
true if the two expressions are statically equivalent

hashCode

public int hashCode()
get HashCode for comparing two expressions

Overrides:
hashCode in class Object
Returns:
the hash code

effectiveBooleanValue

public boolean effectiveBooleanValue(XPathContext context)
                              throws XPathException
Description copied from class: Expression
Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.

Overrides:
effectiveBooleanValue in class Expression
Parameters:
context - The context in which the expression is to be evaluated
Returns:
the effective boolean value
Throws:
XPathException - if any dynamic error occurs evaluating the expression

evaluateItem

public Item evaluateItem(XPathContext context)
                  throws XPathException
Description copied from class: Expression
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.

Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in class Expression
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

computeDependencies

public int computeDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE

Overrides:
computeDependencies in class Expression
Returns:
the dependencies

explain

public void explain(ExpressionPresenter destination)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

Specified by:
explain in class Expression
Parameters:
destination - the expression presenter used to display the structure


Copyright (c) 2004-2010 Saxonica Limited. All rights reserved.