< prev index next >

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

Print this page
rev 13106 : 8139885: implement JEP 274: enhanced method handles

*** 467,482 **** return dropParameterTypes(start, end).insertParameterTypes(start, ptypesToInsert); } /** Replace the last arrayLength parameter types with the component type of arrayType. * @param arrayType any array type * @param arrayLength the number of parameter types to change * @return the resulting type */ ! /*non-public*/ MethodType asSpreaderType(Class<?> arrayType, int arrayLength) { assert(parameterCount() >= arrayLength); ! int spreadPos = ptypes.length - arrayLength; if (arrayLength == 0) return this; // nothing to change if (arrayType == Object[].class) { if (isGeneric()) return this; // nothing to change if (spreadPos == 0) { // no leading arguments to preserve; go generic --- 467,483 ---- return dropParameterTypes(start, end).insertParameterTypes(start, ptypesToInsert); } /** Replace the last arrayLength parameter types with the component type of arrayType. * @param arrayType any array type + * @param pos position at which to spread * @param arrayLength the number of parameter types to change * @return the resulting type */ ! /*non-public*/ MethodType asSpreaderType(Class<?> arrayType, int pos, int arrayLength) { assert(parameterCount() >= arrayLength); ! int spreadPos = pos; if (arrayLength == 0) return this; // nothing to change if (arrayType == Object[].class) { if (isGeneric()) return this; // nothing to change if (spreadPos == 0) { // no leading arguments to preserve; go generic
*** 487,500 **** return res; } } Class<?> elemType = arrayType.getComponentType(); assert(elemType != null); ! for (int i = spreadPos; i < ptypes.length; i++) { if (ptypes[i] != elemType) { Class<?>[] fixedPtypes = ptypes.clone(); ! Arrays.fill(fixedPtypes, i, ptypes.length, elemType); return methodType(rtype, fixedPtypes); } } return this; // arguments check out; no change } --- 488,501 ---- return res; } } Class<?> elemType = arrayType.getComponentType(); assert(elemType != null); ! for (int i = spreadPos; i < spreadPos + arrayLength; i++) { if (ptypes[i] != elemType) { Class<?>[] fixedPtypes = ptypes.clone(); ! Arrays.fill(fixedPtypes, i, spreadPos + arrayLength, elemType); return methodType(rtype, fixedPtypes); } } return this; // arguments check out; no change }
*** 510,525 **** return ptype; } /** Delete the last parameter type and replace it with arrayLength copies of the component type of arrayType. * @param arrayType any array type * @param arrayLength the number of parameter types to insert * @return the resulting type */ ! /*non-public*/ MethodType asCollectorType(Class<?> arrayType, int arrayLength) { assert(parameterCount() >= 1); ! assert(lastParameterType().isAssignableFrom(arrayType)); MethodType res; if (arrayType == Object[].class) { res = genericMethodType(arrayLength); if (rtype != Object.class) { res = res.changeReturnType(rtype); --- 511,528 ---- return ptype; } /** Delete the last parameter type and replace it with arrayLength copies of the component type of arrayType. * @param arrayType any array type + * @param pos position at which to insert parameters * @param arrayLength the number of parameter types to insert * @return the resulting type */ ! /*non-public*/ MethodType asCollectorType(Class<?> arrayType, int pos, int arrayLength) { assert(parameterCount() >= 1); ! assert(pos < ptypes.length); ! assert(ptypes[pos].isAssignableFrom(arrayType)); MethodType res; if (arrayType == Object[].class) { res = genericMethodType(arrayLength); if (rtype != Object.class) { res = res.changeReturnType(rtype);
*** 530,540 **** res = methodType(rtype, Collections.nCopies(arrayLength, elemType)); } if (ptypes.length == 1) { return res; } else { ! return res.insertParameterTypes(0, parameterList().subList(0, ptypes.length-1)); } } /** * Finds or creates a method type with some parameter types omitted. --- 533,547 ---- res = methodType(rtype, Collections.nCopies(arrayLength, elemType)); } if (ptypes.length == 1) { return res; } else { ! // insert after (if need be), then before ! if (pos < parameterList().size() - 1) { ! res = res.insertParameterTypes(arrayLength, parameterList().subList(pos + 1, parameterList().size())); ! } ! return res.insertParameterTypes(0, parameterList().subList(0, pos)); } } /** * Finds or creates a method type with some parameter types omitted.
< prev index next >