Search in sources :

Example 46 with MethodHandle

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

the class BinderTest method testFrom.

@Test
public void testFrom() throws Throwable {
    MethodHandle target = Subjects.concatHandle();
    Binder binder1 = Binder.from(String.class, String.class, Object.class).drop(1);
    MethodHandle handle = Binder.from(binder1).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()));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 47 with MethodHandle

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

the class BinderTest method testAppend.

@Test
public void testAppend() throws Throwable {
    MethodHandle target = Subjects.concatHandle();
    MethodHandle handle = Binder.from(String.class, String.class, Object.class).append("world").drop(1).invoke(target);
    assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle.type());
    assertEquals("Hello, world", (String) handle.invokeExact("Hello, ", new Object()));
    MethodHandle target2 = Subjects.concatCharSequenceHandle();
    MethodHandle handle2 = Binder.from(String.class, String.class, Object.class).append(CharSequence.class, "world").drop(1).invoke(target2);
    assertEquals(MethodType.methodType(String.class, String.class, Object.class), handle2.type());
    assertEquals("Hello, world", (String) handle2.invokeExact("Hello, ", new Object()));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 48 with MethodHandle

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

the class BinderTest method testSetField2.

@Test
public void testSetField2() throws Throwable {
    Fields fields = new Fields();
    MethodHandle handle = Binder.from(void.class, Fields.class, String.class).setFieldQuiet(LOOKUP, "instanceField");
    assertEquals(MethodType.methodType(void.class, Fields.class, String.class), handle.type());
    handle.invokeExact(fields, "modified");
    assertEquals("modified", fields.instanceField);
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 49 with MethodHandle

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

the class BinderTest method testTryFinally.

@Test
public void testTryFinally() 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, "setZeroToFoo");
    assertEquals(MethodType.methodType(void.class, String[].class), handle.type());
    String[] stringAry = new String[1];
    handle.invokeExact(stringAry);
    assertEquals("foofinally", stringAry[0]);
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 50 with MethodHandle

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

the class BinderTest method testTryFinallyReturn.

@Test
public void testTryFinallyReturn() throws Throwable {
    MethodHandle post = Binder.from(void.class, String[].class).invokeStatic(LOOKUP, BinderTest.class, "finallyLogic");
    MethodHandle handle = Binder.from(int.class, String[].class).tryFinally(post).invokeStatic(LOOKUP, BinderTest.class, "setZeroToFooReturnInt");
    assertEquals(MethodType.methodType(int.class, String[].class), handle.type());
    String[] stringAry = new String[1];
    assertEquals(1, (int) handle.invokeExact(stringAry));
    assertEquals("foofinally", stringAry[0]);
}
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