< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java

Print this page




 645                 }
 646             } else if (i < indexes.length) {
 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




 645                 }
 646             } else if (i < indexes.length) {
 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 && n == 0) {
 666             return;
 667         } else if (av == null) {
 668             throw new NullPointerException("null array reference");
 669         } else if (av instanceof Object[]) {
 670             int len = ((Object[])av).length;
 671             if (len == n)  return;
 672         } else {
 673             int len = java.lang.reflect.Array.getLength(av);
 674             if (len == n)  return;
 675         }
 676         // fall through to error:
 677         throw newIllegalArgumentException("array is not of length "+n);
 678     }
 679 
 680     /** Factory method:  Collect or filter selected argument(s). */
 681     static MethodHandle makeCollectArguments(MethodHandle target,
 682                 MethodHandle collector, int collectArgPos, boolean retainOriginalArgs) {
 683         MethodType targetType = target.type();          // (a..., c, [b...])=>r
 684         MethodType collectorType = collector.type();    // (b...)=>c
 685         int collectArgCount = collectorType.parameterCount();
 686         Class<?> collectValType = collectorType.returnType();
 687         int collectValCount = (collectValType == void.class ? 0 : 1);
 688         MethodType srcType = targetType                 // (a..., [b...])=>r


< prev index next >