468 } |
468 } |
469 static List<MethodType> allMethodTypes(int argc, Class<?>... types) { |
469 static List<MethodType> allMethodTypes(int argc, Class<?>... types) { |
470 return allMethodTypes(argc, argc, types); |
470 return allMethodTypes(argc, argc, types); |
471 } |
471 } |
472 |
472 |
473 interface RandomInterface { } |
|
474 |
|
475 MethodHandle toString_MH; |
473 MethodHandle toString_MH; |
476 |
474 |
477 @Test |
475 @Test |
478 public void testReferenceConversions() throws Throwable { |
476 public void testReferenceConversions() throws Throwable { |
479 startTest("testReferenceConversions"); |
477 startTest("testReferenceConversions"); |
480 toString_MH = LOOKUP. |
478 toString_MH = LOOKUP. |
481 findVirtual(Object.class, "toString", MethodType.methodType(String.class)); |
479 findVirtual(Object.class, "toString", MethodType.methodType(String.class)); |
482 Object[] args = { "one", "two" }; |
480 Object[] args = { "one", "two" }; |
483 for (MethodType type : allMethodTypes(2, Object.class, String.class, RandomInterface.class)) { |
481 for (MethodType type : allMethodTypes(2, Object.class, String.class, CharSequence.class)) { |
484 testReferenceConversions(type, args); |
482 testReferenceConversions(type, args); |
485 } |
483 } |
486 } |
484 } |
487 public void testReferenceConversions(MethodType type, Object... args) throws Throwable { |
485 public void testReferenceConversions(MethodType type, Object... args) throws Throwable { |
488 countTest(); |
486 countTest(); |
489 if (verbosity > 3) System.out.println("target type: "+type); |
487 int nargs = args.length; |
|
488 List<Object> argList = Arrays.asList(args); |
|
489 String expectString = argList.toString(); |
|
490 if (verbosity > 3) System.out.println("target type: "+type+expectString); |
490 MethodHandle mh = callable(type.parameterList()); |
491 MethodHandle mh = callable(type.parameterList()); |
491 MethodHandle tsdrop = MethodHandles.dropArguments(toString_MH, 1, type.parameterList()); |
492 mh = MethodHandles.filterReturnValue(mh, toString_MH); |
492 mh = MethodHandles.foldArguments(tsdrop, mh); |
|
493 mh = mh.asType(type); |
493 mh = mh.asType(type); |
494 Object res = mh.invoke((String)args[0], (Object)args[1]); |
494 Object res = null; |
|
495 if (nargs == 2) { |
|
496 res = mh.invoke((Object)args[0], (Object)args[1]); |
|
497 assertEquals(expectString, res); |
|
498 res = mh.invoke((String)args[0], (Object)args[1]); |
|
499 assertEquals(expectString, res); |
|
500 res = mh.invoke((Object)args[0], (String)args[1]); |
|
501 assertEquals(expectString, res); |
|
502 res = mh.invoke((String)args[0], (String)args[1]); |
|
503 assertEquals(expectString, res); |
|
504 res = mh.invoke((String)args[0], (CharSequence)args[1]); |
|
505 assertEquals(expectString, res); |
|
506 res = mh.invoke((CharSequence)args[0], (Object)args[1]); |
|
507 assertEquals(expectString, res); |
|
508 res = (String) mh.invoke((Object)args[0], (Object)args[1]); |
|
509 assertEquals(expectString, res); |
|
510 res = (String) mh.invoke((String)args[0], (Object)args[1]); |
|
511 assertEquals(expectString, res); |
|
512 res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]); |
|
513 assertEquals(expectString, res); |
|
514 } else { |
|
515 assert(false); // write this code |
|
516 } |
495 //System.out.println(res); |
517 //System.out.println(res); |
496 assertEquals(Arrays.asList(args).toString(), res); |
518 } |
497 } |
519 |
498 |
520 |
499 |
521 @Test |
500 @Test @Ignore("known failure pending 6939861") |
|
501 public void testBoxConversions() throws Throwable { |
522 public void testBoxConversions() throws Throwable { |
502 startTest("testBoxConversions"); |
523 startTest("testBoxConversions"); |
503 countTest(); |
524 countTest(); |
504 Object[] args = { 1, 2 }; |
525 Object[] args = { 1, 2 }; |
505 MethodHandle mh = callable(Object.class, int.class); |
526 MethodHandle mh = callable(Object.class, int.class); |
506 Object res; List resl; |
527 Object res; List resl; int resi; |
507 res = resl = (List) mh.invoke((int)args[0], (Object)args[1]); |
528 res = resl = (List) mh.invoke((int)args[0], (Object)args[1]); |
508 //System.out.println(res); |
529 //System.out.println(res); |
509 assertEquals(Arrays.asList(args), res); |
530 assertEquals(Arrays.asList(args), res); |
|
531 mh = MethodHandles.identity(int.class); |
|
532 mh = MethodHandles.dropArguments(mh, 1, int.class); |
|
533 res = resi = (int) mh.invoke((Object) args[0], (Object) args[1]); |
|
534 assertEquals(args[0], res); |
|
535 res = resi = (int) mh.invoke((int) args[0], (Object) args[1]); |
|
536 assertEquals(args[0], res); |
510 } |
537 } |
511 |
538 |
512 } |
539 } |