Package net.sf.saxon.expr

## Class CastingExpression

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.UnaryExpression
    - - net.sf.saxon.expr.CastingExpression

- All Implemented Interfaces:
    `ExportAgent`, `Locatable`, `IdentityComparable`, `Traceable`
  Direct Known Subclasses:
    `CastableExpression`, `CastExpression`

      public abstract class CastingExpression
      extends UnaryExpression

  Casting Expression: abstract superclass for "cast as X" and "castable as X", which share a good deal of logic

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Converter` | `converter` |

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

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CastingExpression​(Expression source, AtomicType target, boolean allowEmpty)` | Create a cast expression

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `allowsEmpty()` | Ask whether the expression accepts an empty sequence as input (producing an empty sequence as output)
    `int` | `computeSpecialProperties()` | Determine the special properties of this expression
    `protected void` | `export​(ExpressionPresenter out, java.lang.String elemName)` | Export expression structure to SEF file.
    `Converter` | `getConverter()` | Get the Converter allocated to implement this cast expression, if any
    `int` | `getIntrinsicDependencies()` | Get the expression's dependencies.
    `NamespaceResolver` | `getNamespaceResolver()` | Get the namespace resolver, if any
    `protected OperandRole` | `getOperandRole()` | Get the usage (in terms of streamability analysis) of the single operand
    `AtomicType` | `getTargetPrimitiveType()` | Get the primitive base type of the target type of the cast
    `AtomicType` | `getTargetType()` | Get the target type (the result type)
    `boolean` | `isOperandIsStringLiteral()` | Ask whether the operand to the cast expression was supplied in the form of a string literal.
    `void` | `setAllowEmpty​(boolean allow)` | Say whether the expression accepts an empty sequence as input (producing an empty sequence as output)
    `void` | `setOperandIsStringLiteral​(boolean option)` | Say whether the operand to the cast expression was supplied in the form of a string literal.
    `void` | `setTargetType​(AtomicType type)` | Set the target type
    `Expression` | `simplify()` | Simplify the expression

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

      `computeCardinality, computeHashCode, displayOperator, emitExtraAttributes, equals, export, getBaseExpression, getItemType, getOperand, operands, optimize, setBaseExpression, toShortString, toString, typeCheck`

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

      `addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExpressionName, getExtraProperty, getImplementationMethod, getIntegerBounds, getInterpretedExpression, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers`

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

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

    - ### Methods inherited from interface net.sf.saxon.trace.Traceable

      `gatherProperties`

- - ### Field Detail

    - #### converter

          protected Converter converter

  - ### Constructor Detail

    - #### CastingExpression

          public CastingExpression​(Expression source,
                                   AtomicType target,
                                   boolean allowEmpty)

      Create a cast expression
      Parameters:
        `source` - expression giving the value to be converted
        `target` - the type to which the value is to be converted
        `allowEmpty` - true if the expression allows an empty sequence as input, producing an empty sequence as output. If false, an empty sequence is a type error.

  - ### Method Detail

    - #### getTargetPrimitiveType

          public AtomicType getTargetPrimitiveType()

      Get the primitive base type of the target type of the cast
      Returns:
        the primitive type of the target type

    - #### setTargetType

          public void setTargetType​(AtomicType type)

      Set the target type
      Parameters:
        `type` - the target type for the cast

    - #### getTargetType

          public AtomicType getTargetType()

      Get the target type (the result type)
      Returns:
        the target type

    - #### getOperandRole

          protected OperandRole getOperandRole()

      Description copied from class: `UnaryExpression`
      Get the usage (in terms of streamability analysis) of the single operand
      Specified by:
        `getOperandRole` in class `UnaryExpression`
      Returns:
        the operand usage

    - #### setAllowEmpty

          public void setAllowEmpty​(boolean allow)

      Say whether the expression accepts an empty sequence as input (producing an empty sequence as output)
      Parameters:
        `allow` - true if an empty sequence is accepted

    - #### allowsEmpty

          public boolean allowsEmpty()

      Ask whether the expression accepts an empty sequence as input (producing an empty sequence as output)
      Returns:
        true if an empty sequence is accepted

    - #### setOperandIsStringLiteral

          public void setOperandIsStringLiteral​(boolean option)

      Say whether the operand to the cast expression was supplied in the form of a string literal. This is relevant only for XPath 2.0 / XQuery 1.0, and then only when the target type is a QName or NOTATION.
      Parameters:
        `option` - true if the operand was supplied as a string literal

    - #### isOperandIsStringLiteral

          public boolean isOperandIsStringLiteral()

      Ask whether the operand to the cast expression was supplied in the form of a string literal. This is relevant only for XPath 2.0 / XQuery 1.0, and then only when the target type is a QName or NOTATION.
      Returns:
        true if the operand was supplied as a string literal

    - #### getConverter

          public Converter getConverter()

      Get the Converter allocated to implement this cast expression, if any
      Returns:
        the Converter if one has been statically allocated, or null if not

    - #### getNamespaceResolver

          public NamespaceResolver getNamespaceResolver()

      Get the namespace resolver, if any
      Returns:
        the namespace resolver that was statically allocated if the target type is namespace-sensitive

    - #### getIntrinsicDependencies

          public int getIntrinsicDependencies()

      Get the expression's dependencies. If the target type is namespace-sensitive, then the expression has a dependency on the namespace bindings in the static context
      Overrides:
        `getIntrinsicDependencies` in class `Expression`
      Returns:
        the expression's dependencies.

    - #### simplify

          public Expression simplify()
                              throws XPathException

      Simplify the expression
      Overrides:
        `simplify` in class `Expression`
      Returns:
        the simplified expression (or the original if unchanged, or if modified in-situ)
      Throws:
        `XPathException` - if an error is discovered during expression rewriting

    - #### computeSpecialProperties

          public int computeSpecialProperties()

      Determine the special properties of this expression
      Overrides:
        `computeSpecialProperties` in class `UnaryExpression`
      Returns:
        `StaticProperty.NO_NODES_NEWLY_CREATED`.

    - #### export

          protected void export​(ExpressionPresenter out,
                                java.lang.String elemName)
                         throws XPathException

      Export expression structure to SEF file. The abstract expression tree is written to the supplied output destination. Helper method for subclasses.
      Parameters:
        `out` - the destination of the output
        `elemName` - the element name to be used in the SEF file
      Throws:
        `XPathException` - if output fails