public final class SwitchExpressionUtils
extends Object
Shared classification of switch-expression labels for static compilation.
Intrinsic dispatch (tableswitch / lookupswitch / enum name)
is used only when every case label is a compile-time constant of a type
javac would switch on. Mixed labels fall back to isCase.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static String |
enumConstantName(Expression expression, ClassNode enumType)Extracts the enum constant name from a case label of enumType, or null.
|
|
public static Integer |
intConstant(Expression expression)Extracts an int-family constant from a case label, or null. |
|
public static boolean |
isIntegralSelector(ClassNode type)True for byte, short, char, int and their wrappers. |
|
public static boolean |
isIntegralType(ClassNode type)True for the integral primitive types javac switches on. |
|
public static boolean |
isIntegralWrapper(ClassNode type)True for the wrappers of the integral primitive types javac switches on. |
|
public static boolean |
isOptimizedEnumSwitch(ClassNode selectorType, List<CaseStatement> caseStatements)True when the selector is an enum and every label names a constant of that enum. |
|
public static boolean |
isOptimizedIntSwitch(ClassNode selectorType, List<CaseStatement> caseStatements)True when the selector is an integral primitive or wrapper and every label is an int-family constant. |
|
public static boolean |
isOptimizedStringSwitch(ClassNode selectorType, List<CaseStatement> caseStatements)True when the selector is String and every label is a string constant. |
|
public static boolean |
isOptimizedSwitch(ClassNode selectorType, List<CaseStatement> caseStatements)True when the selector type and every case label permit tableswitch, lookupswitch, or enum-name dispatch. |
|
public static String |
stringConstant(Expression expression)Extracts a string constant from a case label, or null. |
|
public static ClassNode |
unwrapEnumType(ClassNode type)Returns the enum type behind type, or null if it is not an enum. |
Extracts the enum constant name from a case label of enumType, or null.
Accepts EnumType.NAME, an unqualified name that resolves to that constant,
or a constant expression holding the enum value.
expression - the case labelenumType - the selector enum typenull if the label is not a constant of enumType Extracts an int-family constant from a case label, or null.
expression - the case labelnull if the label is not an int-family constant True for byte, short, char, int and their wrappers.
type - the selector typetrue if the type can feed a JVM int switch True for the integral primitive types javac switches on.
type - the type to testtrue if the type is int, byte, short, or char True for the wrappers of the integral primitive types javac switches on.
type - the type to testtrue if the type is Integer, Byte, Short, or CharacterTrue when the selector is an enum and every label names a constant of that enum.
selectorType - the inferred type of the selectorcaseStatements - the case armstrue if enum-name dispatch appliesTrue when the selector is an integral primitive or wrapper and every label is an int-family constant.
selectorType - the inferred type of the selectorcaseStatements - the case armstrue if int tableswitch / lookupswitch appliesTrue when the selector is String and every label is a string constant.
selectorType - the inferred type of the selectorcaseStatements - the case armstrue if string lookupswitch applies True when the selector type and every case label permit tableswitch,
lookupswitch, or enum-name dispatch. An empty case list, a null
label, or a single non-constant label (a range, a variable, …) makes
the whole switch an isCase switch.
selectorType - the inferred type of the selectorcaseStatements - the case armstrue if codegen can emit an intrinsic switch Extracts a string constant from a case label, or null.
expression - the case labelnull if the label is not a string constant