Interface Switch<T>

    • 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:

         
         StringSwitch s = method.stringSwitch(val);
               s.caseOf(List.of("boom", "foo"), bc -> {...});
         
         
        is an equivalent of:
         switch (val) {
             case "boom", "foo" -> // statements provided by the consumer
         }
         
        However, if fall though is enabled then:
         
         StringSwitch s = method.stringSwitch(val);
         s.fallThrough();
         s.caseOf(List.of("boom", "foo"), bc -> {...});
         
         
        is an equivalent of:
         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 label
        caseBlockConsumer - 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 provided BytecodeCreator to make it exit the switch, effectively issuing a Java 'break' statement.
        Parameters:
        creator -
        See Also:
        fallThrough()