Move tests for LambdaMetafactory to source tree
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2022-11-13 10:29:26 +01:00
parent eb6c2538b5
commit b0326536c7
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 35 additions and 2 deletions

View File

@ -25,14 +25,15 @@ public class Main {
String[] newArgs = new String[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, args.length - 1);
Method mainMethod = Class.forName(args[0]).getMethod("main", String[].class);
Class<?> mainClass = Class.forName(args[0]);
Method mainMethod = mainClass.getMethod("main", String[].class);
MethodHandles.Lookup lookup = MethodHandles.lookup();
@SuppressWarnings("ConfusingArgumentToVarargsMethod") Runnable main = (Runnable) LambdaMetafactory.metafactory(
lookup,
"run",
MethodType.methodType(Runnable.class, String[].class),
MethodType.methodType(Void.TYPE),
MethodHandles.lookup().unreflect(mainMethod),
lookup.unreflect(mainMethod),
MethodType.methodType(Void.TYPE)
).getTarget().invokeExact(newArgs);

View File

@ -0,0 +1,24 @@
package io.gitlab.jfronny.inceptum.launchwrapper.test;
import java.lang.invoke.*;
import java.lang.reflect.Method;
public class InvokeTest {
public static void main(String[] args) throws Throwable {
Class<?> klazz = TestClass.class;
Method mainMethod = klazz.getMethod("main", String[].class);
MethodHandles.Lookup lookup = MethodHandles.lookup();
String[] yes = new String[] {"Shesh"};
Runnable main = (Runnable) LambdaMetafactory.metafactory(
lookup,
"run",
MethodType.methodType(Runnable.class, String[].class),
MethodType.methodType(Void.TYPE),
lookup.unreflect(mainMethod),
MethodType.methodType(Void.TYPE)
).getTarget().invokeExact(yes);
new Thread(main).start();
}
}

View File

@ -0,0 +1,8 @@
package io.gitlab.jfronny.inceptum.launchwrapper.test;
public class TestClass {
public static void main(String[] args) {
System.out.println("Yes! " + args[0]);
new Throwable().printStackTrace();
}
}