Search in sources :

Example 36 with MethodHandle

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

the class BinderTest method testGetField2.

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

Example 37 with MethodHandle

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

the class BinderTest method testFoldStatic.

@Test
public void testFoldStatic() throws Throwable {
    MethodHandle target = Subjects.concatHandle();
    MethodHandle handle = Binder.from(LOOKUP, String.class, String.class).foldStatic(BinderTest.class, "alwaysYahooStatic").invoke(target);
    assertEquals(MethodType.methodType(String.class, String.class), handle.type());
    assertEquals("yahoofoo", (String) handle.invokeExact("foo"));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 38 with MethodHandle

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

the class SmartBinderTest method testPrintSignature.

@Test
public void testPrintSignature() throws Throwable {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    MethodHandle handle = SmartBinder.from(Subjects.StringIntegerIntegerInteger).foldStatic("x", Subjects.class, "foldStringIntegerIntegerInteger").drop("a").printSignature(ps).drop("b1").drop("b2").drop("b3").printSignature(ps).invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase").handle();
    String result = baos.toString();
    assertEquals("(String x, Integer b1, Integer b2, Integer b3)String\n" + "(String x)String\n", result);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MethodHandle(java.lang.invoke.MethodHandle) Test(org.junit.Test)

Example 39 with MethodHandle

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

the class SmartBinderTest method testAppend.

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

Example 40 with MethodHandle

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

the class SmartBinderTest method testFoldStatic.

@Test
public void testFoldStatic() throws Throwable {
    MethodHandle handle = SmartBinder.from(Subjects.StringIntegerIntegerInteger).foldStatic("x", Subjects.class, "foldStringIntegerIntegerInteger").drop("a").drop("b1").drop("b2").drop("b3").invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase").handle();
    assertEquals("FORTY_TWO", (String) handle.invokeExact("foo", Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)));
}
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