Package org.renjin.invoke.model

Examples of org.renjin.invoke.model.JvmMethod



  @Test
  public void scalarPriority() throws Exception {

    JvmMethod intMethod = new JvmMethod(Ops.class.getMethod("minus", int.class));
    JvmMethod doubleMethod = new JvmMethod(Ops.class.getMethod("minus", double.class));

    List<JvmMethod> list = Lists.newArrayList(doubleMethod, intMethod);

    Collections.sort(list, new OverloadComparator());
View Full Code Here


    assertThat(list.get(1), is(doubleMethod));
  }

  @Test
  public void pairListVsVector() throws Exception {
    JvmMethod vectorMethod = new JvmMethod(Vectors.class.getMethod("asVector", Vector.class, String.class));
    JvmMethod pairListMethod = new JvmMethod(Vectors.class.getMethod("asVector", PairList.class, String.class));

    OverloadComparator comparator = new OverloadComparator();

    assertThat(comparator.compare(vectorMethod, pairListMethod), lessThan(0));
  }
View Full Code Here

                    .arg(lit(primitive.argumentErrorMessage()))
                    .arg(e.invoke("getMessage")));
  }

  private GenericDispatchStrategy genericDispatchStrategy(PrimitiveModel primitive) {
    JvmMethod overload =  primitive.getOverloads().get(0);
    if (overload.isGroupGeneric()) {
      if (overload.getGenericGroup().equals("Ops")) {
        return new OpsGroupGenericDispatchStrategy(codeModel, primitive.getName());
      } else if (overload.getGenericGroup().equals("Summary")) {
        return new SummaryGroupGenericStrategy(codeModel, primitive.getName());
      } else {
        throw new GeneratorDefinitionException(
            "Group generic dispatch for group '" + overload.getGenericName()
                + "' is not implemented");
      }
    } else if (overload.isGeneric()) {
      return new SimpleDispatchStrategy(codeModel, primitive.getName());
    } else {
      return new GenericDispatchStrategy(codeModel);
    }
  }
View Full Code Here

  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);
View Full Code Here

    super(codeModel, invoker, primitive);
  }

  @Override
  protected void apply(JBlock parent) {
    JvmMethod overload = primitive.getOverloads().get(0);

    parser = new VarArgParser(this, parent, overload);

    convertArgs(parser.getArgumentProcessingBlock());

    // try S3 dispatch
    genericDispatchStrategy.beforePrimitiveCalled(parent, parser, this, call);

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

    CodeModelUtils.returnSexp(codeModel, parent,  overload, invocation);
View Full Code Here

public class JvmMethodTest {


  @Test(expected = EvalException.class)
  public void validation() throws NoSuchMethodException {
    JvmMethod m0 = new JvmMethod(getClass().getMethod("doStuff", Boolean.TYPE, Boolean.TYPE, Boolean.TYPE));
    JvmMethod m1 = new JvmMethod(getClass().getMethod("doStuff", Null.class));
    JvmMethod m2 = new JvmMethod(getClass().getMethod("doStuff", Integer.TYPE));
    JvmMethod m3 = new JvmMethod(getClass().getMethod("doStuff", AtomicVector.class));
    JvmMethod m4 = new JvmMethod(getClass().getMethod("doStuff"));

    // make sure that we get an error because doStuff(AtomicExp) hides doStuff(NullExp)

    JvmMethod.validate(asList(m0, m1, m2, m3, m4));
  }
View Full Code Here

TOP

Related Classes of org.renjin.invoke.model.JvmMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.