--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java Thu Nov 19 19:46:46 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java Fri Nov 20 15:34:12 2015 +0100
@@ -469,12 +469,13 @@
/** 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 arrayLength) {
+ /*non-public*/ MethodType asSpreaderType(Class<?> arrayType, int pos, int arrayLength) {
assert(parameterCount() >= arrayLength);
- int spreadPos = ptypes.length - arrayLength;
+ int spreadPos = pos;
if (arrayLength == 0) return this; // nothing to change
if (arrayType == Object[].class) {
if (isGeneric()) return this; // nothing to change
@@ -489,10 +490,10 @@
}
Class<?> elemType = arrayType.getComponentType();
assert(elemType != null);
- for (int i = spreadPos; i < ptypes.length; i++) {
+ for (int i = spreadPos; i < spreadPos + arrayLength; i++) {
if (ptypes[i] != elemType) {
Class<?>[] fixedPtypes = ptypes.clone();
- Arrays.fill(fixedPtypes, i, ptypes.length, elemType);
+ Arrays.fill(fixedPtypes, i, spreadPos + arrayLength, elemType);
return methodType(rtype, fixedPtypes);
}
}
@@ -512,12 +513,14 @@
/** 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 arrayLength) {
+ /*non-public*/ MethodType asCollectorType(Class<?> arrayType, int pos, int arrayLength) {
assert(parameterCount() >= 1);
- assert(lastParameterType().isAssignableFrom(arrayType));
+ assert(pos < ptypes.length);
+ assert(ptypes[pos].isAssignableFrom(arrayType));
MethodType res;
if (arrayType == Object[].class) {
res = genericMethodType(arrayLength);
@@ -532,7 +535,11 @@
if (ptypes.length == 1) {
return res;
} else {
- return res.insertParameterTypes(0, parameterList().subList(0, ptypes.length-1));
+ // 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));
}
}