net.sf.saxon.expr

## Class SubscriptExpression

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.UnaryExpression
    - - net.sf.saxon.expr.SingleItemFilter
      - - net.sf.saxon.expr.SubscriptExpression

- All Implemented Interfaces:
    Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator

      public class SubscriptExpression
      extends SingleItemFilter

  A SubscriptExpression represents a FilterExpression of the form EXPR[n] where n is known to be singleton numeric and to be independent of the focus; it does not need to be constant
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.UnaryExpression

      `operand`

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, INHERITED_CONTEXT, INSPECTION_CONTEXT, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, NAVIGATION_CONTEXT, NODE_VALUE_CONTEXT, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, W3C_CONSUMING, W3C_FREE_RANGING, W3C_GROUP_CONSUMING, W3C_MOTIONLESS, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SubscriptExpression(Expression base, Expression subscript)` Construct a SubscriptExpression

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `computeCardinality()` Get the static cardinality: this implementation is appropriate for [1] and [last()] which will always return something if the input is non-empty
    `Expression` | `copy()` Copy an expression.
    `boolean` | `equals(Object other)` Compare two expressions to see if they are equal
    `Item` | `evaluateItem(XPathContext context)` Evaluate an expression as a single item.
    `void` | `explain(ExpressionPresenter destination)` Diagnostic print of expression structure.
    `ExpressionCompiler` | `getExpressionCompiler()` Return the compiler of the TailExpression expression
    `Expression` | `getSubscriptExpression()` Get the subscript expression
    `int` | `hashCode()` get HashCode for comparing two expressions.
    `Iterator<Expression>` | `iterateSubExpressions()` Get the immediate subexpressions of this expression
    `Expression` | `optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType 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
    `Pattern` | `toStreamingPattern(Configuration config, List<String> reasonForFailure)` Convert this expression to a streaming pattern (a pattern used internally to match nodes during push processing of an event stream)
    `String` | `toString()` The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
    `Expression` | `typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)` Type-check the expression.

    - ### Methods inherited from class net.sf.saxon.expr.UnaryExpression

      `computeSpecialProperties, displayOperator, getBaseExpression, getItemType, simplify`

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `addToPathMap, adoptChildExpression, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getEvaluationMethod, getExecutable, getExpressionName, getHostLanguage, getImplementationMethod, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getStreamability, getStreamingAdjunct, getSystemId, getSystemId, hasVariableBinding, implementsStaticTypeCheck, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, iterateEvents, iterateSubExpressionInfo, markTailFunctionCalls, process, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation, toPattern, typeError`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SubscriptExpression

          public SubscriptExpression(Expression base,
                             Expression subscript)

      Construct a SubscriptExpression
      Parameters:
        `base` - the expression to be filtered
        `subscript` - the positional subscript filter

  - ### Method Detail

    - #### typeCheck

          public Expression typeCheck(ExpressionVisitor visitor,
                             ExpressionVisitor.ContextItemType contextItemType)
                               throws XPathException

      Description copied from class: `UnaryExpression`
      Type-check the expression. Default implementation for unary operators that accept any kind of operand
      Overrides:
        `typeCheck` in class `UnaryExpression`
      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 to perform necessary run-time type checks, and to perform other type-related optimizations
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### optimize

          public Expression optimize(ExpressionVisitor visitor,
                            ExpressionVisitor.ContextItemType contextItemType)
                              throws XPathException

      Description copied from class: `SingleItemFilter`
      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 `SingleItemFilter`
      Parameters:
        `visitor` - an expresion 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
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### promote

          public Expression promote(PromotionOffer offer,
                           Expression parent)
                             throws XPathException

      Description copied from class: `SingleItemFilter`
      Promote this expression if possible
      Overrides:
        `promote` in class `SingleItemFilter`
      Parameters:
        `offer` - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
        `parent` - the containing expression in the expression tree
      Returns:
        if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
      Throws:
        `XPathException` - if any error is detected

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

    - #### iterateSubExpressions

          public Iterator<Expression> iterateSubExpressions()

      Description copied from class: `UnaryExpression`
      Get the immediate subexpressions of this expression
      Overrides:
        `iterateSubExpressions` in class `UnaryExpression`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### replaceSubExpression

          public boolean replaceSubExpression(Expression original,
                                     Expression replacement)

      Replace one subexpression by a replacement subexpression
      Overrides:
        `replaceSubExpression` in class `UnaryExpression`
      Parameters:
        `original` - the original subexpression
        `replacement` - the replacement subexpression
      Returns:
        true if the original subexpression is found

    - #### getSubscriptExpression

          public Expression getSubscriptExpression()

      Get the subscript expression
      Returns:
        the expression used to compute the one-based start offset

    - #### equals

          public boolean equals(Object other)

      Compare two expressions to see if they are equal
      Overrides:
        `equals` in class `UnaryExpression`
      Parameters:
        `other` - the other expression
      Returns:
        true if the expressions are equivalent

    - #### hashCode

          public int hashCode()

      Description copied from class: `UnaryExpression`
      get HashCode for comparing two expressions. Note that this hashcode gives the same result for (A op B) and for (B op A), whether or not the operator is commutative.
      Overrides:
        `hashCode` in class `UnaryExpression`

    - #### computeCardinality

          public int computeCardinality()

      Get the static cardinality: this implementation is appropriate for [1] and [last()] which will always return something if the input is non-empty
      Overrides:
        `computeCardinality` in class `SingleItemFilter`
      Returns:
        the computed cardinality, as one of the values `StaticProperty.ALLOWS_ZERO_OR_ONE`, `StaticProperty.EXACTLY_ONE`, `StaticProperty.ALLOWS_ONE_OR_MORE`, `StaticProperty.ALLOWS_ZERO_OR_MORE`

    - #### toStreamingPattern

          public Pattern toStreamingPattern(Configuration config,
                                   List<String> reasonForFailure)

      Convert this expression to a streaming pattern (a pattern used internally to match nodes during push processing of an event stream)
      Overrides:
        `toStreamingPattern` in class `Expression`
      Parameters:
        `config` - the Saxon configuration
        `reasonForFailure` - a list which will be populated with messages giving reasons why the expression cannot be converted
      Returns:
        the equivalent pattern if conversion succeeds; otherwise null

    - #### 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.
      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

    - #### getExpressionCompiler

          public ExpressionCompiler getExpressionCompiler()

      Return the compiler of the TailExpression expression
      Overrides:
        `getExpressionCompiler` in class `Expression`
      Returns:
        the relevant ExpressionCompiler

    - #### explain

          public void explain(ExpressionPresenter destination)

      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Overrides:
        `explain` in class `UnaryExpression`
      Parameters:
        `destination` - the expression presenter used to display the structure

    - #### toString

          public String toString()

      The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.

      For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression.

      Overrides:
        `toString` in class `UnaryExpression`
      Returns:
        a representation of the expression as a string

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