Class AnnotationScalars

java.lang.Object
io.micronaut.python.processing.util.AnnotationScalars

@Internal public final class AnnotationScalars extends Object
Narrows a literal from the Python processor (a String, Boolean, Integer, Long or Double) to the declared scalar annotation member type, the way the Java annotation processor would deliver it. Python is more permissive than Java here: value=True on a String member becomes "true", and 1 on a long member becomes 1L.
Since:
5.2.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    bool(Object value)
    A literal for a boolean member: a boolean, not a string.
    static char
    A literal for a char member or array element: a one-character string, never a number or a boolean that happens to print as one character.
    static char
    character(String string)
    A literal for a char member: exactly one character, as in Java source.
     
    static float
    floating(Number number)
    A literal for a float member: a finite value must not overflow to infinity, as javac rejects a constant too large for the type.
    static long
    integral(Number number, long min, long max, String typeName)
    A literal for an integral member, checked the way javac checks a constant: integral and in range.
    static Number
    number(Object value, String typeName)
    A literal for a numeric member: a number, not a string or a boolean that happens to parse.

    Methods inherited from class Object

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

    • coerce

      @Nullable public static @Nullable Object coerce(@Nullable @Nullable Object value, @Nullable @Nullable ClassElement memberType)
      Parameters:
      value - The literal value
      memberType - The declared member type
      Returns:
      The value narrowed to the member type, or the value itself when no narrowing applies
    • integral

      public static long integral(Number number, long min, long max, String typeName)
      A literal for an integral member, checked the way javac checks a constant: integral and in range.
      Parameters:
      number - The literal
      min - The member type's minimum
      max - The member type's maximum
      typeName - The member type, for the message
      Returns:
      The value
    • floating

      public static float floating(Number number)
      A literal for a float member: a finite value must not overflow to infinity, as javac rejects a constant too large for the type.
      Parameters:
      number - The literal
      Returns:
      The float
    • number

      public static Number number(Object value, String typeName)
      A literal for a numeric member: a number, not a string or a boolean that happens to parse.
      Parameters:
      value - The literal
      typeName - The member type, for the message
      Returns:
      The number
    • bool

      public static boolean bool(Object value)
      A literal for a boolean member: a boolean, not a string.
      Parameters:
      value - The literal
      Returns:
      The boolean
    • character

      public static char character(String string)
      A literal for a char member: exactly one character, as in Java source.
      Parameters:
      string - The literal
      Returns:
      The character
    • character

      public static char character(Object value)
      A literal for a char member or array element: a one-character string, never a number or a boolean that happens to print as one character.
      Parameters:
      value - The literal
      Returns:
      The character