Search in sources :

Example 6 with SerializedLambda

use of java.lang.invoke.SerializedLambda in project ninja by ninjaframework.

the class LambdasTest method anonymousMethodReference.

@Test
public void anonymousMethodReference() throws Exception {
    ControllerMethod1<Context> lambda = (Context context) -> Results.html().renderRaw("".getBytes(StandardCharsets.UTF_8));
    LambdaInfo lambdaInfo = Lambdas.reflect(lambda);
    assertThat(lambdaInfo.getKind(), is(Kind.ANONYMOUS_METHOD_REFERENCE));
    SerializedLambda serializedLambda = lambdaInfo.getSerializedLambda();
    assertThat(serializedLambda.getFunctionalInterfaceMethodName(), is("apply"));
    assertThat(serializedLambda.getImplClass().replace('/', '.'), is(LambdasTest.class.getCanonicalName()));
    assertThat(serializedLambda.getImplMethodName(), startsWith("lambda$"));
    assertThat(serializedLambda.getInstantiatedMethodType(), is("(Lninja/Context;)Lninja/Result;"));
    // includes captured args btw...
    assertThat(serializedLambda.getImplMethodSignature(), is("(Lninja/Context;)Lninja/Result;"));
    // 6 = REF_invokeStatic
    assertThat(serializedLambda.getImplMethodKind(), is(6));
    assertThat(serializedLambda.getCapturedArgCount(), is(0));
}
Also used : Context(ninja.Context) LambdaInfo(ninja.utils.Lambdas.LambdaInfo) SerializedLambda(java.lang.invoke.SerializedLambda) Test(org.junit.Test)

Aggregations

SerializedLambda (java.lang.invoke.SerializedLambda)6 LambdaInfo (ninja.utils.Lambdas.LambdaInfo)4 Test (org.junit.Test)4 Method (java.lang.reflect.Method)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Context (ninja.Context)1