コード例 #1
0
  private void convertArguments(JBlock parent, VarArgParser parser) {
    int index = 0;
    for (VarArgParser.PositionalArg posArg : parser.getPositionalArguments()) {
      parent.assign(
          posArg.getVariable(), convert(posArg.getFormal(), args.component(lit(index++))));
    }

    JForLoop forLoop = parent._for();
    JVar loopCounter =
        forLoop.init(codeModel._ref(int.class), "i", lit(parser.getPositionalArguments().size()));
    forLoop.test(loopCounter.lt(JExpr.direct("args.length")));
    forLoop.update(loopCounter.incr());

    forLoop
        .body()
        .invoke(parser.getVarArgBuilder(), "add")
        .arg(argNames.component(loopCounter))
        .arg(args.component(loopCounter));
  }
コード例 #2
0
  public void buildVarArgs() {
    declareMethod();

    ExceptionWrapper mainTryBlock = new ExceptionWrapper(codeModel, method.body(), context);

    JvmMethod overload = primitive.getOverloads().get(0);
    VarArgParser parser = new VarArgParser(this, mainTryBlock.body(), overload);

    // convert the positional arguments
    convertArguments(parser.getArgumentProcessingBlock(), parser);

    // finally invoke the underlying function
    JInvocation invocation =
        classRef(overload.getDeclaringClass()).staticInvoke(overload.getName());
    for (JExpression argument : parser.getArguments()) {
      invocation.arg(argument);
    }

    CodeModelUtils.returnSexp(codeModel, mainTryBlock.body(), overload, invocation);

    mainTryBlock.catchEvalExceptions();
    mainTryBlock.catchRuntimeExceptions();
    mainTryBlock.catchExceptions();
  }