Package io.quarkus.gizmo
Interface Switch<T>
-
- Type Parameters:
T- Constant type
- All Known Subinterfaces:
Switch.EnumSwitch<E>,Switch.StringSwitch
- All Known Implementing Classes:
AbstractSwitch,ClassTransfromerMethodCreatorImpl.ClassTransformerEnumSwitchImpl,EnumSwitchImpl,StringSwitchImpl
public interface Switch<T>A switch statement.This construct is not thread-safe and should not be re-used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSwitch.EnumSwitch<E extends java.lang.Enum<E>>A switch forEnum.static interfaceSwitch.StringSwitchA switch forString.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcaseOf(java.util.List<T> values, java.util.function.Consumer<BytecodeCreator> caseBlockConsumer)Adds multiple case labels for a single block.voidcaseOf(T value, java.util.function.Consumer<BytecodeCreator> caseBlockConsumer)Adds a case block.voiddefaultCase(java.util.function.Consumer<BytecodeCreator> defatultBlockConsumer)Adds the default block.voiddoBreak(BytecodeCreator creator)Writes bytecode into the providedBytecodeCreatorto make it exit the switch, effectively issuing a Java 'break' statement.voidfallThrough()Enables fall through.
-
-
-
Method Detail
-
fallThrough
void fallThrough()
Enables fall through.By default, the fall through is disabled. A case block is treated as a switch rule block; i.e. it's not necessary to add the break statement to prevent the fall through. However, if fall through is enabled then a case block is treated as a labeled statement group; i.e. it's necessary to add the break statement to prevent the fall through.
For example, if fall through is disabled then:
is an equivalent of:StringSwitch s = method.stringSwitch(val); s.caseOf(List.of("boom", "foo"), bc -> {...});switch (val) { case "boom", "foo" -> // statements provided by the consumer }However, if fall though is enabled then:
is an equivalent of:StringSwitch s = method.stringSwitch(val); s.fallThrough(); s.caseOf(List.of("boom", "foo"), bc -> {...});switch (val) { case "val1": case "val2": // statements provided by the consumer }
-
caseOf
void caseOf(T value, java.util.function.Consumer<BytecodeCreator> caseBlockConsumer)
Adds a case block.- Parameters:
value- The value for the case labelcaseBlockConsumer- The consumer used to define the case block- Throws:
java.lang.IllegalArgumentException- If a case block for the specified value was already added
-
caseOf
void caseOf(java.util.List<T> values, java.util.function.Consumer<BytecodeCreator> caseBlockConsumer)
Adds multiple case labels for a single block.- Parameters:
values-caseBlockConsumer-- Throws:
java.lang.IllegalArgumentException- If a case block for the specified value was already added
-
defaultCase
void defaultCase(java.util.function.Consumer<BytecodeCreator> defatultBlockConsumer)
Adds the default block.- Parameters:
defatultBlockConsumer-
-
doBreak
void doBreak(BytecodeCreator creator)
Writes bytecode into the providedBytecodeCreatorto make it exit the switch, effectively issuing a Java 'break' statement.- Parameters:
creator-- See Also:
fallThrough()
-
-