Class SwitchKeys

java.lang.Object
io.micronaut.sourcegen.bytecode.core.SwitchKeys

@Internal public final class SwitchKeys extends Object
The switches both bytecode writers write as a switch on an int, as javac writes them: a selector of type int, char, short or byte is widened to an int, and one of their wrappers is unboxed first, which throws NullPointerException for null.
Since:
2.3
  • Method Details

    • switchesOnInt

      public static boolean switchesOnInt(TypeDef selector)
      Whether a switch on a selector of a type is a switch on the int it widens or unboxes to.
      Parameters:
      selector - The type of the selector
      Returns:
      true for an int, a char, a short, a byte and their wrappers
    • key

      public static @Nullable Integer key(ExpressionDef.Constant constant)
      The int a case constant of a switch on an int matches.
      Parameters:
      constant - The constant of the case
      Returns:
      The key, or null for a constant that is no int, char, short or byte