Package com.saxonica.ee.bytecode

## Class CastExpressionCompiler

- java.lang.Object
- - com.saxonica.ee.bytecode.ExpressionCompiler
  - - com.saxonica.ee.bytecode.ToItemCompiler
    - - com.saxonica.ee.bytecode.CastExpressionCompiler

-     public class CastExpressionCompiler
      extends ToItemCompiler

  Generate code for a CastExpression

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CastExpressionCompiler()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `compileToItem​(CompilerService compiler, Expression expression)` | Generate bytecode to evaluate the CastExpression as an Item Precondition: none.
    `void` | `compileToPrimitive​(CompilerService compiler, Expression expression, java.lang.Class requiredClass, OnEmpty onEmpty)` | Generate bytecode to evaluate the expression leaving a plain Java value on the stack.
    `static ConverterCompiler` | `getConverterCompiler​(PlainType sourceType, AtomicType targetType)` |

    - ### Methods inherited from class com.saxonica.ee.bytecode.ToItemCompiler

      `compileToBoolean, compileToIterator, compileToPush, returnZeroLengthStringIfNull`

    - ### Methods inherited from class com.saxonica.ee.bytecode.ExpressionCompiler

      `allocateStatic, compileItemFromInt, generateMethod, handleEmptyStringResult, printStackTop, verify, visitAnnotation, visitLineNumber`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CastExpressionCompiler

          public CastExpressionCompiler()

  - ### Method Detail

    - #### compileToItem

          public void compileToItem​(CompilerService compiler,
                                    Expression expression)
                             throws CannotCompileException

      Generate bytecode to evaluate the CastExpression as an Item Precondition: none. Postcondition: the stack contains an Item representing the result of the expression
      Specified by:
        `compileToItem` in class `ExpressionCompiler`
      Parameters:
        `compiler` - the compiler service
        `expression` - the expression to be compiled
      Throws:
        `CannotCompileException` - if the expression cannot be compiled to bytecode

    - #### compileToPrimitive

          public void compileToPrimitive​(CompilerService compiler,
                                         Expression expression,
                                         java.lang.Class requiredClass,
                                         OnEmpty onEmpty)
                                  throws CannotCompileException

      Generate bytecode to evaluate the expression leaving a plain Java value on the stack. The static type of the expression must be such that the value is known to be representable by a value of the specified class; the cardinality must be either exactly-one or zero-or-one.
      Overrides:
        `compileToPrimitive` in class `ExpressionCompiler`
      Parameters:
        `compiler` - the compiler service
        `expression` - the expression to be compiled
        `requiredClass` - the class of the Java value that is to be left on the stack if the generated code exits normally. This must be one of Integer.TYPE, Double.TYPE, Float.TYPE, BigDecimal.class, CharSequence.class.
        `onEmpty` - action to be taken if the result of the expression is an empty sequence
      Throws:
        `CannotCompileException` - if the expression cannot be compiled to bytecode

    - #### getConverterCompiler

          public static ConverterCompiler getConverterCompiler​(PlainType sourceType,
                                                               AtomicType targetType)
                                                        throws CannotCompileException

      Throws:
        `CannotCompileException`