Enum PrimitiveNarrowingDelegate

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<PrimitiveNarrowingDelegate>

    public enum PrimitiveNarrowingDelegate
    extends java.lang.Enum<PrimitiveNarrowingDelegate>
    This delegate is responsible for narrowing a primitive type to represent a smaller primitive type. The rules for this narrowing are equivalent to those in the JLS. This class also includes the byte-to-char conversion in widening and narrowing primitive conversions.
    • Field Detail

      • toBooleanStackManipulation

        private final StackManipulation toBooleanStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a boolean.
      • toByteStackManipulation

        private final StackManipulation toByteStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a byte.
      • toShortStackManipulation

        private final StackManipulation toShortStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a short.
      • toCharacterStackManipulation

        private final StackManipulation toCharacterStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a char.
      • toIntegerStackManipulation

        private final StackManipulation toIntegerStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a int.
      • toLongStackManipulation

        private final StackManipulation toLongStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a long.
      • toFloatStackManipulation

        private final StackManipulation toFloatStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a float.
      • toDoubleStackManipulation

        private final StackManipulation toDoubleStackManipulation
        A stack manipulation that narrows the type that is represented by this instance to a double.
    • Constructor Detail

      • PrimitiveNarrowingDelegate

        private PrimitiveNarrowingDelegate​(StackManipulation toBooleanStackManipulation,
                                           StackManipulation toByteStackManipulation,
                                           StackManipulation toShortStackManipulation,
                                           StackManipulation toCharacterStackManipulation,
                                           StackManipulation toIntegerStackManipulation,
                                           StackManipulation toLongStackManipulation,
                                           StackManipulation toFloatStackManipulation,
                                           StackManipulation toDoubleStackManipulation)
        Creates a new primitive narrowing delegate.
        Parameters:
        toBooleanStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a boolean.
        toByteStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a byte.
        toShortStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a short.
        toCharacterStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a char.
        toIntegerStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a int.
        toLongStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a long.
        toFloatStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a float.
        toDoubleStackManipulation - A stack manipulation that narrows the type that is represented by this instance to a double.
    • Method Detail

      • values

        public static PrimitiveNarrowingDelegate[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (PrimitiveNarrowingDelegate c : PrimitiveNarrowingDelegate.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static PrimitiveNarrowingDelegate valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • forPrimitive

        public static PrimitiveNarrowingDelegate forPrimitive​(TypeDefinition typeDefinition)
        Locates the delegate that is capable of narrowing the given type into another type.
        Parameters:
        typeDefinition - A non-void primitive type that is to be narrowed into another type.
        Returns:
        A delegate for the given type.
      • narrowTo

        public StackManipulation narrowTo​(TypeDefinition typeDefinition)
        Attempts to narrow the represented type into another type.
        Parameters:
        typeDefinition - A non-void primitive type that is the expected result of the narrowing operation.
        Returns:
        A narrowing instruction or an illegal stack manipulation if such narrowing is not legitimate.