Class ELSupport

java.lang.Object
io.micronaut.el.runtime.ELSupport

@Internal public final class ELSupport extends Object
The type conversion, comparison and emptiness rules of the Jakarta Expression Language specification.

This class is invoked by the expressions generated at compilation time, it is not part of the public API of the module.

Since:
1.0
Author:
Denis Stepanov
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable Object
    argument(@Nullable Object[] arguments, int index)
     
    static int
    argumentCount(@Nullable Object[] arguments)
     
    static <T> @Nullable T
    coerce(@Nullable Object value, @Nullable Class<T> type)
    Coerces a value applying the standard rules of the specification.
    static @Nullable Object
    coerceToArray(@Nullable Object value, Class<?> componentType)
    Coerces a value to an array as described in the section 1.25.7 of the specification.
    static @Nullable Boolean
    coerceToBoolean(@Nullable Object value, boolean primitive)
    Coerces a value to Boolean as described in the section 1.25.5 of the specification.
    static @Nullable Character
    coerceToCharacter(@Nullable Object value, boolean primitive)
    Coerces a value to Character as described in the section 1.25.4 of the specification.
    static <T extends Enum<T>>
    @Nullable T
    coerceToEnum(@Nullable Object value, Class<T> type)
    Coerces a value to an enum as described in the section 1.25.6 of the specification.
    static <T> @Nullable T
    coerceToFunctionalInterface(@Nullable jakarta.el.ELContext context, @Nullable Object value, @Nullable Class<T> type)
    Coerces a value to a functional interface, invoking the lambda expression when one is given.
    static @Nullable Number
    coerceToNumber(@Nullable Object value, Class<?> type)
    Coerces a value to a number type as described in the section 1.25.3 of the specification.
    static String
    coerceToString(@Nullable Object value)
    Coerces a value to String as described in the section 1.25.2 of the specification.
    static <T> @Nullable T
    coerceToType(@Nullable jakarta.el.ELContext context, @Nullable Object value, @Nullable Class<T> type)
    Coerces a value applying the custom converters of the context before the standard rules.
    static int
    compare(@Nullable Object left, @Nullable Object right)
    Compares two values as described in the section 1.9.1 of the specification.
    static boolean
    equals(@Nullable Object left, @Nullable Object right)
    The == operator described in the section 1.9.2 of the specification.
    static boolean
    greaterThan(@Nullable Object left, @Nullable Object right)
    The > operator described in the section 1.9.1 of the specification.
    static boolean
    greaterThanOrEqual(@Nullable Object left, @Nullable Object right)
    The >= operator described in the section 1.9.1 of the specification.
    static boolean
    isEmpty(@Nullable Object value)
    The empty operator described in the section 1.11 of the specification.
    static boolean
    isFloatingPoint(@Nullable Object value)
     
    static boolean
    isFloatingPointInstance(@Nullable Object left, @Nullable Object right)
    The floating point rule of the relational operators, which the sections 1.9.1 and 1.9.2 of the specification restrict to actual Float and Double instances.
    static boolean
     
    static boolean
    isFloatingPointOperand(@Nullable Object left, @Nullable Object right)
     
    static boolean
    isOperand(@Nullable Object left, @Nullable Object right, Class<?> type)
     
    static boolean
    lessThan(@Nullable Object left, @Nullable Object right)
    The < operator described in the section 1.9.1 of the specification.
    static boolean
    lessThanOrEqual(@Nullable Object left, @Nullable Object right)
    The <= operator described in the section 1.9.1 of the specification.
    static boolean
    not(@Nullable Object value)
    The unary not operator described in the section 1.10.2 of the specification.
    static boolean
    notEquals(@Nullable Object left, @Nullable Object right)
    The != operator described in the section 1.9.2 of the specification.
    static @Nullable Object
    sequence(@Nullable Object discarded, @Nullable Object value)
    The semicolon operator described in the section 1.14 of the specification.
    static boolean
    toBoolean(@Nullable Object value)
    Coerces a value to a primitive boolean, the form used by the logical operators.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • coerceToType

      public static <T> @Nullable T coerceToType(@Nullable jakarta.el.ELContext context, @Nullable Object value, @Nullable Class<T> type)
      Coerces a value applying the custom converters of the context before the standard rules.
      Type Parameters:
      T - The target type
      Parameters:
      context - The context, can be null
      value - The value
      type - The target type
      Returns:
      The coerced value
    • coerce

      public static <T> @Nullable T coerce(@Nullable Object value, @Nullable Class<T> type)
      Coerces a value applying the standard rules of the specification.
      Type Parameters:
      T - The target type
      Parameters:
      value - The value
      type - The target type
      Returns:
      The coerced value
    • coerceToFunctionalInterface

      public static <T> @Nullable T coerceToFunctionalInterface(@Nullable jakarta.el.ELContext context, @Nullable Object value, @Nullable Class<T> type)
      Coerces a value to a functional interface, invoking the lambda expression when one is given.
      Type Parameters:
      T - The target type
      Parameters:
      context - The context
      value - The value
      type - The functional interface
      Returns:
      The coerced value
    • coerceToString

      public static String coerceToString(@Nullable Object value)
      Coerces a value to String as described in the section 1.25.2 of the specification.
      Parameters:
      value - The value
      Returns:
      The coerced value, never null
    • coerceToBoolean

      public static @Nullable Boolean coerceToBoolean(@Nullable Object value, boolean primitive)
      Coerces a value to Boolean as described in the section 1.25.5 of the specification.
      Parameters:
      value - The value
      primitive - Whether the target type is the primitive boolean
      Returns:
      The coerced value
    • toBoolean

      public static boolean toBoolean(@Nullable Object value)
      Coerces a value to a primitive boolean, the form used by the logical operators.
      Parameters:
      value - The value
      Returns:
      The coerced value
    • coerceToCharacter

      public static @Nullable Character coerceToCharacter(@Nullable Object value, boolean primitive)
      Coerces a value to Character as described in the section 1.25.4 of the specification.
      Parameters:
      value - The value
      primitive - Whether the target type is the primitive char
      Returns:
      The coerced value
    • coerceToNumber

      public static @Nullable Number coerceToNumber(@Nullable Object value, Class<?> type)
      Coerces a value to a number type as described in the section 1.25.3 of the specification.
      Parameters:
      value - The value
      type - The number type
      Returns:
      The coerced value
    • coerceToEnum

      public static <T extends Enum<T>> @Nullable T coerceToEnum(@Nullable Object value, Class<T> type)
      Coerces a value to an enum as described in the section 1.25.6 of the specification.
      Type Parameters:
      T - The enum type
      Parameters:
      value - The value
      type - The enum type
      Returns:
      The coerced value
    • coerceToArray

      public static @Nullable Object coerceToArray(@Nullable Object value, Class<?> componentType)
      Coerces a value to an array as described in the section 1.25.7 of the specification.
      Parameters:
      value - The value
      componentType - The component type of the target array
      Returns:
      The coerced value
    • isEmpty

      public static boolean isEmpty(@Nullable Object value)
      The empty operator described in the section 1.11 of the specification.
      Parameters:
      value - The value
      Returns:
      True if the value is considered empty
    • argumentCount

      public static int argumentCount(@Nullable Object[] arguments)
      Parameters:
      arguments - The arguments
      Returns:
      The number of arguments, zero when the array is null
    • argument

      public static @Nullable Object argument(@Nullable Object[] arguments, int index)
      Parameters:
      arguments - The arguments
      index - The index of the argument
      Returns:
      The argument at the given index, null when there is none
    • not

      public static boolean not(@Nullable Object value)
      The unary not operator described in the section 1.10.2 of the specification.
      Parameters:
      value - The operand
      Returns:
      The negated value
    • sequence

      public static @Nullable Object sequence(@Nullable Object discarded, @Nullable Object value)
      The semicolon operator described in the section 1.14 of the specification. Both operands are evaluated from left to right and the value of the left operand is discarded.
      Parameters:
      discarded - The value of the left operand
      value - The value of the right operand
      Returns:
      The value of the right operand
    • equals

      public static boolean equals(@Nullable Object left, @Nullable Object right)
      The == operator described in the section 1.9.2 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • notEquals

      public static boolean notEquals(@Nullable Object left, @Nullable Object right)
      The != operator described in the section 1.9.2 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • lessThan

      public static boolean lessThan(@Nullable Object left, @Nullable Object right)
      The < operator described in the section 1.9.1 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • greaterThan

      public static boolean greaterThan(@Nullable Object left, @Nullable Object right)
      The > operator described in the section 1.9.1 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • lessThanOrEqual

      public static boolean lessThanOrEqual(@Nullable Object left, @Nullable Object right)
      The <= operator described in the section 1.9.1 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • greaterThanOrEqual

      public static boolean greaterThanOrEqual(@Nullable Object left, @Nullable Object right)
      The >= operator described in the section 1.9.1 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      The result of the comparison
    • compare

      public static int compare(@Nullable Object left, @Nullable Object right)
      Compares two values as described in the section 1.9.1 of the specification.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      A negative value, zero or a positive value
    • isFloatingPointInstance

      public static boolean isFloatingPointInstance(@Nullable Object left, @Nullable Object right)
      The floating point rule of the relational operators, which the sections 1.9.1 and 1.9.2 of the specification restrict to actual Float and Double instances. Only the arithmetic operators of the section 1.7 extend it to strings in floating point notation.
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      True when one of the operands is a Float or a Double
    • isFloatingPointOperand

      public static boolean isFloatingPointOperand(@Nullable Object left, @Nullable Object right)
      Parameters:
      left - The left operand
      right - The right operand
      Returns:
      True when one of the operands is a floating point value, or a string in floating point notation
    • isFloatingPoint

      public static boolean isFloatingPoint(@Nullable Object value)
      Parameters:
      value - The value
      Returns:
      True when the value is a floating point value, including a string in floating point notation
    • isFloatingPointNotation

      public static boolean isFloatingPointNotation(String value)
      Parameters:
      value - The value
      Returns:
      True when the string uses the floating point notation
    • isOperand

      public static boolean isOperand(@Nullable Object left, @Nullable Object right, Class<?> type)
      Parameters:
      left - The left operand
      right - The right operand
      type - The type
      Returns:
      True when one of the operands is of the given type