465 if (ilen == 0) |
465 if (ilen == 0) |
466 return dropParameterTypes(start, end); |
466 return dropParameterTypes(start, end); |
467 return dropParameterTypes(start, end).insertParameterTypes(start, ptypesToInsert); |
467 return dropParameterTypes(start, end).insertParameterTypes(start, ptypesToInsert); |
468 } |
468 } |
469 |
469 |
|
470 /** Replace the last arrayLength parameter types with the component type of arrayType. |
|
471 * @param arrayType any array type |
|
472 * @param arrayLength the number of parameter types to change |
|
473 * @return the resulting type |
|
474 */ |
|
475 /*non-public*/ MethodType asSpreaderType(Class<?> arrayType, int arrayLength) { |
|
476 assert(parameterCount() >= arrayLength); |
|
477 int spreadPos = ptypes.length - arrayLength; |
|
478 if (arrayLength == 0) return this; // nothing to change |
|
479 if (arrayType == Object[].class) { |
|
480 if (isGeneric()) return this; // nothing to change |
|
481 if (spreadPos == 0) { |
|
482 // no leading arguments to preserve; go generic |
|
483 MethodType res = genericMethodType(arrayLength); |
|
484 if (rtype != Object.class) { |
|
485 res = res.changeReturnType(rtype); |
|
486 } |
|
487 return res; |
|
488 } |
|
489 } |
|
490 Class<?> elemType = arrayType.getComponentType(); |
|
491 assert(elemType != null); |
|
492 for (int i = spreadPos; i < ptypes.length; i++) { |
|
493 if (ptypes[i] != elemType) { |
|
494 Class<?>[] fixedPtypes = ptypes.clone(); |
|
495 Arrays.fill(fixedPtypes, i, ptypes.length, elemType); |
|
496 return methodType(rtype, fixedPtypes); |
|
497 } |
|
498 } |
|
499 return this; // arguments check out; no change |
|
500 } |
|
501 |
470 /** |
502 /** |
471 * Finds or creates a method type with some parameter types omitted. |
503 * Finds or creates a method type with some parameter types omitted. |
472 * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
504 * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
473 * @param start the index (zero-based) of the first parameter type to remove |
505 * @param start the index (zero-based) of the first parameter type to remove |
474 * @param end the index (greater than {@code start}) of the first parameter type after not to remove |
506 * @param end the index (greater than {@code start}) of the first parameter type after not to remove |
570 * as {@code type.generic()}. |
602 * as {@code type.generic()}. |
571 * @return a version of the original type with all types replaced |
603 * @return a version of the original type with all types replaced |
572 */ |
604 */ |
573 public MethodType generic() { |
605 public MethodType generic() { |
574 return genericMethodType(parameterCount()); |
606 return genericMethodType(parameterCount()); |
|
607 } |
|
608 |
|
609 /*non-public*/ boolean isGeneric() { |
|
610 return this == erase() && !hasPrimitives(); |
575 } |
611 } |
576 |
612 |
577 /** |
613 /** |
578 * Converts all primitive types to their corresponding wrapper types. |
614 * Converts all primitive types to their corresponding wrapper types. |
579 * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |
615 * Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[]) methodType}. |