Package java.lang.invoke

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


  @Test
  public void with_params() throws Throwable {
    TemplateEngine engine = new TemplateEngine();
    String template = "<%@params foo, bar %>=<%= foo + bar %>";
    MethodHandle tpl = engine.compile(template);
    assertThat(tpl.type().parameterCount(), is(2));
    assertThat((String) tpl.invoke(1, 2), is("=3"));
  }

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


    Method raw_handle = moduleClass.getMethod("raw_handle");
    result = raw_handle.invoke(null);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((String) handle.invoke(123), is("123"));

    Method handle_with_capture = moduleClass.getMethod("handle_with_capture", Object.class, Object.class);
    result = handle_with_capture.invoke(null, 1, 2);
    assertThat(result, instanceOf(MethodHandle.class));
View Full Code Here

    Method handle_with_capture = moduleClass.getMethod("handle_with_capture", Object.class, Object.class);
    result = handle_with_capture.invoke(null, 1, 2);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((Integer) handle.invoke(100), is(300));
    assertThat((Integer) handle.invoke(10), is(30));

    Method call_with_invoke = moduleClass.getMethod("call_with_invoke");
    assertThat((Integer) call_with_invoke.invoke(null), is(90));
View Full Code Here

    Method nested_compact = moduleClass.getMethod("nested_compact", Object.class);
    result = nested_compact.invoke(null, 1);
    assertThat(result, instanceOf(MethodHandle.class));
    handle = (MethodHandle) result;
    assertThat(handle.type(), is(genericMethodType(1)));
    assertThat((Integer) handle.invoke(2), is(3));

    Method in_a_map = moduleClass.getMethod("in_a_map");
    result = in_a_map.invoke(null);
    assertThat(result, notNullValue());
View Full Code Here

    Object result = callSite.dynamicInvoker().invoke();
    assertThat(result, instanceOf(MethodHandle.class));

    MethodHandle handle = (MethodHandle) result;
    assertThat(handle.type(), is(methodType(Object.class, Object.class, Object.class)));

    result = handle.invoke("foo", "bar");
    assertThat(result, instanceOf(List.class));
    assertThat(((List) result).size(), is(2));
  }
View Full Code Here

    Object result = callSite.dynamicInvoker().invoke();
    assertThat(result, instanceOf(MethodHandle.class));

    MethodHandle handle = (MethodHandle) result;
    assertThat(handle.type(), is(methodType(Object.class, Object[].class)));

    result = handle.invoke("foo", "bar");
    assertThat(result, instanceOf(String.class));
    assertThat((String) result, is("foobar"));
  }
View Full Code Here

            }

            FunctionInfo operatorInfo = metadata.resolveOperator(OperatorType.NEGATION, types(node.getValue()));

            MethodHandle handle = operatorInfo.getMethodHandle();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == ConnectorSession.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(value);
            }
View Full Code Here

            }

            FunctionInfo operatorInfo = metadata.resolveOperator(OperatorType.NEGATION, types(node.getValue()));

            MethodHandle handle = operatorInfo.getMethodHandle();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == ConnectorSession.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(value);
            }
View Full Code Here

            // do not optimize non-deterministic functions
            if (optimize && !function.isDeterministic()) {
                return new FunctionCall(node.getName(), node.getWindow().orNull(), node.isDistinct(), toExpressions(argumentValues));
            }
            MethodHandle handle = function.getScalarFunction();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == Session.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(argumentValues);
            }
View Full Code Here

            // do not optimize non-deterministic functions
            if (optimize && !function.isDeterministic()) {
                return new FunctionCall(node.getName(), node.getWindow().orNull(), node.isDistinct(), toExpressions(argumentValues));
            }
            MethodHandle handle = function.getScalarFunction();
            if (handle.type().parameterCount() > 0 && handle.type().parameterType(0) == Session.class) {
                handle = handle.bindTo(session);
            }
            try {
                return handle.invokeWithArguments(argumentValues);
            }
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.