Search in sources :

Example 31 with MethodHandle

use of java.lang.invoke.MethodHandle in project invokebinder by headius.

the class BinderTest method testInvoke.

@Test
public void testInvoke() throws Throwable {
    MethodHandle target = Subjects.concatHandle();
    MethodHandle handle = Binder.from(String.class, String.class, String.class).invoke(target);
    assertEquals(MethodType.methodType(String.class, String.class, String.class), handle.type());
    assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", "world"));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 32 with MethodHandle

use of java.lang.invoke.MethodHandle in project invokebinder by headius.

the class BinderTest method testGetStatic.

@Test
public void testGetStatic() throws Throwable {
    MethodHandle handle = Binder.from(String.class).getStatic(LOOKUP, Fields.class, "staticField");
    assertEquals(MethodType.methodType(String.class), handle.type());
    assertEquals("initial", (String) handle.invokeExact());
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 33 with MethodHandle

use of java.lang.invoke.MethodHandle in project invokebinder by headius.

the class BinderTest method testTryFinally2.

@Test
public void testTryFinally2() throws Throwable {
    MethodHandle post = Binder.from(void.class, String[].class).invokeStatic(LOOKUP, BinderTest.class, "finallyLogic");
    MethodHandle handle = Binder.from(void.class, String[].class).tryFinally(post).invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooAndRaise");
    assertEquals(MethodType.methodType(void.class, String[].class), handle.type());
    String[] stringAry = new String[1];
    try {
        handle.invokeExact(stringAry);
        assertTrue("should not have reached here", false);
    } catch (BlahException re) {
    }
    assertEquals("foofinally", stringAry[0]);
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 34 with MethodHandle

use of java.lang.invoke.MethodHandle in project invokebinder by headius.

the class BinderTest method testDropLast.

@Test
public void testDropLast() throws Throwable {
    MethodHandle target = Subjects.concatHandle();
    MethodHandle handle = Binder.from(String.class, String.class, Object.class).dropLast().insert(1, "world").invoke(target);
    assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle.type());
    assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", new Object()));
    handle = Binder.from(String.class, String.class, Object.class, double.class).dropLast(2).insert(1, "world").invoke(target);
    assertEquals(MethodType.methodType(String.class, String.class, Object.class, double.class), handle.type());
    assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", new Object(), 1.0));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 35 with MethodHandle

use of java.lang.invoke.MethodHandle in project invokebinder by headius.

the class BinderTest method testInvokeConstructor.

@Test
public void testInvokeConstructor() throws Throwable {
    MethodHandle handle = Binder.from(Constructable.class, String.class, String.class).invokeConstructor(LOOKUP, Constructable.class);
    assertEquals(MethodType.methodType(Constructable.class, String.class, String.class), handle.type());
    assertEquals(new Constructable("foo", "bar"), (Constructable) handle.invokeExact("foo", "bar"));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Aggregations

MethodHandle (java.lang.invoke.MethodHandle)302 Test (org.junit.Test)101 MethodType (java.lang.invoke.MethodType)44 Type (com.facebook.presto.spi.type.Type)37 Method (java.lang.reflect.Method)18 OperatorType (com.facebook.presto.spi.function.OperatorType)14 MethodHandles (java.lang.invoke.MethodHandles)13 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)11 Signature (com.facebook.presto.metadata.Signature)10 CallSite (java.lang.invoke.CallSite)10 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)9 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)8 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)7 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)7 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)6 Parameter (com.facebook.presto.bytecode.Parameter)6 PrestoException (com.facebook.presto.spi.PrestoException)6 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)6 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)6