647 indexes[i] = argIndex;
648 }
649 }
650 assert(nameCursor == names.length-1); // leave room for the final call
651
652 // Build argument array for the call.
653 Name[] targetArgs = new Name[targetType.parameterCount()];
654 for (int i = 0; i < targetType.parameterCount(); i++) {
655 int idx = indexes[i];
656 targetArgs[i] = names[idx];
657 }
658 names[names.length - 1] = new Name(target, (Object[]) targetArgs);
659
660 LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.SPREAD);
661 return SimpleMethodHandle.make(srcType, form);
662 }
663
664 static void checkSpreadArgument(Object av, int n) {
665 if (av == null) {
666 if (n == 0) return;
667 } else if (av instanceof Object[]) {
668 int len = ((Object[])av).length;
669 if (len == n) return;
670 } else {
671 int len = java.lang.reflect.Array.getLength(av);
672 if (len == n) return;
673 }
674 // fall through to error:
675 throw newIllegalArgumentException("array is not of length "+n);
676 }
677
678 /** Factory method: Collect or filter selected argument(s). */
679 static MethodHandle makeCollectArguments(MethodHandle target,
680 MethodHandle collector, int collectArgPos, boolean retainOriginalArgs) {
681 MethodType targetType = target.type(); // (a..., c, [b...])=>r
682 MethodType collectorType = collector.type(); // (b...)=>c
683 int collectArgCount = collectorType.parameterCount();
684 Class<?> collectValType = collectorType.returnType();
685 int collectValCount = (collectValType == void.class ? 0 : 1);
686 MethodType srcType = targetType // (a..., [b...])=>r
|
647 indexes[i] = argIndex;
648 }
649 }
650 assert(nameCursor == names.length-1); // leave room for the final call
651
652 // Build argument array for the call.
653 Name[] targetArgs = new Name[targetType.parameterCount()];
654 for (int i = 0; i < targetType.parameterCount(); i++) {
655 int idx = indexes[i];
656 targetArgs[i] = names[idx];
657 }
658 names[names.length - 1] = new Name(target, (Object[]) targetArgs);
659
660 LambdaForm form = new LambdaForm(lambdaType.parameterCount(), names, Kind.SPREAD);
661 return SimpleMethodHandle.make(srcType, form);
662 }
663
664 static void checkSpreadArgument(Object av, int n) {
665 if (av == null) {
666 if (n == 0) return;
667 throw new NullPointerException("null array reference");
668 } else if (av instanceof Object[]) {
669 int len = ((Object[])av).length;
670 if (len == n) return;
671 } else {
672 int len = java.lang.reflect.Array.getLength(av);
673 if (len == n) return;
674 }
675 // fall through to error:
676 throw newIllegalArgumentException("array is not of length "+n);
677 }
678
679 /** Factory method: Collect or filter selected argument(s). */
680 static MethodHandle makeCollectArguments(MethodHandle target,
681 MethodHandle collector, int collectArgPos, boolean retainOriginalArgs) {
682 MethodType targetType = target.type(); // (a..., c, [b...])=>r
683 MethodType collectorType = collector.type(); // (b...)=>c
684 int collectArgCount = collectorType.parameterCount();
685 Class<?> collectValType = collectorType.returnType();
686 int collectValCount = (collectValType == void.class ? 0 : 1);
687 MethodType srcType = targetType // (a..., [b...])=>r
|