Package java.lang.invoke

Examples of java.lang.invoke.MethodHandle.invokeWithArguments()


  @Test
  public void check_oftype() throws Throwable {
    String str = "abc";
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((Boolean) oftype.invokeWithArguments(str, String.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Object.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Integer.class), is(false));
    assertThat((Boolean) oftype.invokeWithArguments(str, Exception.class), is(false));
  }
View Full Code Here


  @Test
  public void check_oftype() throws Throwable {
    String str = "abc";
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((Boolean) oftype.invokeWithArguments(str, String.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Object.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Integer.class), is(false));
    assertThat((Boolean) oftype.invokeWithArguments(str, Exception.class), is(false));
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
View Full Code Here

  public void check_oftype() throws Throwable {
    String str = "abc";
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((Boolean) oftype.invokeWithArguments(str, String.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Object.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Integer.class), is(false));
    assertThat((Boolean) oftype.invokeWithArguments(str, Exception.class), is(false));
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void check_oftype_not_a_class_param() throws Throwable {
View Full Code Here

    String str = "abc";
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
    assertThat((Boolean) oftype.invokeWithArguments(str, String.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Object.class), is(true));
    assertThat((Boolean) oftype.invokeWithArguments(str, Integer.class), is(false));
    assertThat((Boolean) oftype.invokeWithArguments(str, Exception.class), is(false));
  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void check_oftype_not_a_class_param() throws Throwable {
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
View Full Code Here

  }

  @Test(expectedExceptions = IllegalArgumentException.class)
  public void check_oftype_not_a_class_param() throws Throwable {
    MethodHandle oftype = OperatorSupport.bootstrap(lookup(), "oftype", BINOP_TYPE, 2).dynamicInvoker();
    oftype.invokeWithArguments("abc", 123);
  }

  @Test
  public void check_add_double_and_float() throws Throwable {
    Double a = 2.5;
View Full Code Here

  @Test
  public void check_add_double_and_float() throws Throwable {
    Double a = 2.5;
    Float b = 2.5f;
    MethodHandle plus = OperatorSupport.bootstrap(lookup(), "plus", BINOP_TYPE, 2).dynamicInvoker();
    Object result = plus.invokeWithArguments(a, b);

    assertThat(result, instanceOf(Double.class));
    Double r = (Double) result;
    assertThat(r, is(a + ((double) b)));
  }
View Full Code Here

    Integer two = 2;
    Integer four = 4;
    Long three_l = 3L;
    MethodHandle modulo = OperatorSupport.bootstrap(lookup(), "modulo", BINOP_TYPE, 2).dynamicInvoker();

    assertThat((Integer) modulo.invokeWithArguments(four, two), is(0));
    assertThat((Long) modulo.invokeWithArguments(three_l, two), is(1L));
  }

  @Test
  public void check_orIfNull() throws Throwable {
View Full Code Here

    Integer four = 4;
    Long three_l = 3L;
    MethodHandle modulo = OperatorSupport.bootstrap(lookup(), "modulo", BINOP_TYPE, 2).dynamicInvoker();

    assertThat((Integer) modulo.invokeWithArguments(four, two), is(0));
    assertThat((Long) modulo.invokeWithArguments(three_l, two), is(1L));
  }

  @Test
  public void check_orIfNull() throws Throwable {
    MethodHandle orIfNull = OperatorSupport.bootstrap(lookup(), "orifnull", BINOP_TYPE, 2).dynamicInvoker();
View Full Code Here

        if (handle.isVarargsCollector() && args[args.length - 1] instanceof Object[]) {
          Object[] trailing = (Object[]) args[args.length - 1];
          Object[] spreadArgs = new Object[args.length + trailing.length - 1];
          arraycopy(args, 0, spreadArgs, 0, args.length - 1);
          arraycopy(trailing, 0, spreadArgs, args.length - 1, trailing.length);
          return handle.invokeWithArguments(spreadArgs);
        }
        return handle.invokeWithArguments(args);
      } else {
        throw new UnsupportedOperationException("There is no dynamic object method defined for " + property);
      }
View Full Code Here

          Object[] spreadArgs = new Object[args.length + trailing.length - 1];
          arraycopy(args, 0, spreadArgs, 0, args.length - 1);
          arraycopy(trailing, 0, spreadArgs, args.length - 1, trailing.length);
          return handle.invokeWithArguments(spreadArgs);
        }
        return handle.invokeWithArguments(args);
      } else {
        throw new UnsupportedOperationException("There is no dynamic object method defined for " + property);
      }
    }
    if (obj.hasFallback()) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.