static Statement ifElseChain(final List<IfBlock> ifs, final Optional<Statement> elseBlock) {
    checkArgument(!ifs.isEmpty());
    return new Statement() {
      @Override
      protected void doGen(CodeBuilder adapter) {
        Label end = new Label();
        Label next;
        for (int i = 0; i < ifs.size(); i++) {
          IfBlock curr = ifs.get(i);
          boolean isLastIfBlock = i == ifs.size() - 1;
          if (isLastIfBlock && !elseBlock.isPresent()) {
            next = end;
          } else {
            next = new Label();
          }
          curr.condition().gen(adapter);
          adapter.ifZCmp(Opcodes.IFEQ, next);
          curr.block().gen(adapter);
          if (end != next) {
            adapter.goTo(end);
          }
          adapter.mark(next);
        }
        if (elseBlock.isPresent()) {
          elseBlock.get().gen(adapter);
          adapter.mark(end);
        }
      }
    };
  }
static Statement ifElseChain ( final List < IfBlock > ifs , final Optional < Statement > elseBlock ) { checkArgument ( ! ifs . isEmpty ( ) ) ; return new Statement ( ) { @ Override protected void doGen ( CodeBuilder adapter ) { Label end = new Label ( ) ; Label next ; for ( int i = 0 ; i < ifs . size ( ) ; i ++ ) { IfBlock curr = ifs . get ( i ) ; boolean isLastIfBlock = i == ifs . size ( ) - 1 ; if ( isLastIfBlock && ! elseBlock . isPresent ( ) ) { next = end ; } else { next = new Label ( ) ; } curr . condition ( ) . gen ( adapter ) ; adapter . ifZCmp ( Opcodes . IFEQ , next ) ; curr . block ( ) . gen ( adapter ) ; if ( end != next ) { adapter . goTo ( end ) ; } adapter . mark ( next ) ; } if ( elseBlock . isPresent ( ) ) { elseBlock . get ( ) . gen ( adapter ) ; adapter . mark ( end ) ; } } } ; }
Returns a statement that encodes the given sequence of {@link IfBlock if blocks} as an
if-elseif-else chain.