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 -
Method Summary
Modifier and TypeMethodDescriptionvoidcaseOf(List<T> values, Consumer<BytecodeCreator> caseBlockConsumer) Adds multiple case labels for a single block.voidcaseOf(T value, Consumer<BytecodeCreator> caseBlockConsumer) Adds a case block.voiddefaultCase(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.voidEnables fall through.
-
Method Details
-
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
Adds a case block.- Parameters:
value- The value for the case labelcaseBlockConsumer- The consumer used to define the case block- Throws:
IllegalArgumentException- If a case block for the specified value was already added
-
caseOf
Adds multiple case labels for a single block.- Parameters:
values-caseBlockConsumer-- Throws:
IllegalArgumentException- If a case block for the specified value was already added
-
defaultCase
Adds the default block.- Parameters:
defatultBlockConsumer-
-
doBreak
Writes bytecode into the providedBytecodeCreatorto make it exit the switch, effectively issuing a Java 'break' statement.- Parameters:
creator-- See Also:
-