63 public static void testMethodInvoke() throws Exception {
64 Class<?> pointQType = Point.class.asValueType();
65 Class<?> nonFlattenValueQType = NonFlattenValue.class.asValueType();
66 Method m = QTypeDescriptorTest.class
67 .getDeclaredMethod("toLine", pointQType, nonFlattenValueQType);
68 makeLine(m, P0, NFV);
69
70 m = QTypeDescriptorTest.class
71 .getDeclaredMethod("toLine", Point[].class);
72 makeLine(m, (Object) new Point[] { P0, P1});
73 }
74
75 private static void makeLine(Method m, Object... args) throws Exception {
76 Line l = (Line) m.invoke(null, args);
77 assertEquals(l.p1, P0);
78 assertEquals(l.p2, NFV.pointValue());
79 }
80
81 @Test
82 public static void testStaticMethod() throws Throwable {
83 // static method in a value type with no parameter and void return type
84 Runnable r = () -> ValueTest.run();
85 r.run();
86
87 // via Method::invoke
88 Method m = ValueTest.class.getMethod("run");
89 m.invoke(null);
90
91 // via MethodHandle
92 MethodHandle mh = MethodHandles.lookup()
93 .findStatic(ValueTest.class, "run", MethodType.methodType(void.class));
94 mh.invokeExact();
95
96 mh = MethodHandles.lookup().unreflect(m);
97 mh.invokeExact();
98 }
99
100 @Test
101 public static void testConstructor() throws Exception {
102 Constructor<T> ctor = T.class.getDeclaredConstructor(Point[].class);
103 Point[] points = new Point[] { P0, P1 };
190 private static Line toLine(Point p, NonFlattenValue nfv) {
191 return Line.makeLine(p, nfv.pointValue());
192 }
193
194 private static Line toLine(Point[] points) {
195 assertTrue(points.length == 2);
196 return Line.makeLine(points[0], points[1]);
197 }
198
199 static class T {
200 final Point[] points;
201 T(Point[] points) {
202 this.points = points;
203 }
204 }
205
206 interface I {
207 Line toLine(Point p, NonFlattenValue nfv);
208 }
209
210 static value class ValueTest {
211 private final int value;
212 public ValueTest() { this.value = 0; }
213
214 public static void run() {
215 Runnable r = () -> {
216 System.out.println("called ValueTest::run");
217 };
218 r.run();
219 }
220 }
221
222 }
|
63 public static void testMethodInvoke() throws Exception {
64 Class<?> pointQType = Point.class.asValueType();
65 Class<?> nonFlattenValueQType = NonFlattenValue.class.asValueType();
66 Method m = QTypeDescriptorTest.class
67 .getDeclaredMethod("toLine", pointQType, nonFlattenValueQType);
68 makeLine(m, P0, NFV);
69
70 m = QTypeDescriptorTest.class
71 .getDeclaredMethod("toLine", Point[].class);
72 makeLine(m, (Object) new Point[] { P0, P1});
73 }
74
75 private static void makeLine(Method m, Object... args) throws Exception {
76 Line l = (Line) m.invoke(null, args);
77 assertEquals(l.p1, P0);
78 assertEquals(l.p2, NFV.pointValue());
79 }
80
81 @Test
82 public static void testStaticMethod() throws Throwable {
83 // static method in an inline type with no parameter and void return type
84 Runnable r = () -> ValueTest.run();
85 r.run();
86
87 // via Method::invoke
88 Method m = ValueTest.class.getMethod("run");
89 m.invoke(null);
90
91 // via MethodHandle
92 MethodHandle mh = MethodHandles.lookup()
93 .findStatic(ValueTest.class, "run", MethodType.methodType(void.class));
94 mh.invokeExact();
95
96 mh = MethodHandles.lookup().unreflect(m);
97 mh.invokeExact();
98 }
99
100 @Test
101 public static void testConstructor() throws Exception {
102 Constructor<T> ctor = T.class.getDeclaredConstructor(Point[].class);
103 Point[] points = new Point[] { P0, P1 };
190 private static Line toLine(Point p, NonFlattenValue nfv) {
191 return Line.makeLine(p, nfv.pointValue());
192 }
193
194 private static Line toLine(Point[] points) {
195 assertTrue(points.length == 2);
196 return Line.makeLine(points[0], points[1]);
197 }
198
199 static class T {
200 final Point[] points;
201 T(Point[] points) {
202 this.points = points;
203 }
204 }
205
206 interface I {
207 Line toLine(Point p, NonFlattenValue nfv);
208 }
209
210 static inline class ValueTest {
211 private final int value;
212 public ValueTest() { this.value = 0; }
213
214 public static void run() {
215 Runnable r = () -> {
216 System.out.println("called ValueTest::run");
217 };
218 r.run();
219 }
220 }
221
222 }
|