diff -r 9bd55fcb7f90 -r a0ad195efe2c jdk/src/share/classes/java/dyn/MethodType.java --- a/jdk/src/share/classes/java/dyn/MethodType.java Thu Dec 16 00:32:15 2010 -0800 +++ b/jdk/src/share/classes/java/dyn/MethodType.java Thu Dec 16 15:59:27 2010 -0800 @@ -56,21 +56,33 @@ *

* This type can be created only by factory methods. * All factory methods may cache values, though caching is not guaranteed. + * Some factory methods are static, while others are virtual methods which + * modify precursor method types, e.g., by changing a selected parameter. + *

+ * Factory methods which operate on groups of parameter types + * are systematically presented in two versions, so that both Java arrays and + * Java lists can be used to work with groups of parameter types. + * The query methods {@code parameterArray} and {@code parameterList} + * also provide a choice between arrays and lists. *

* {@code MethodType} objects are sometimes derived from bytecode instructions * such as {@code invokedynamic}, specifically from the type descriptor strings associated * with the instructions in a class file's constant pool. - * When this occurs, any classes named in the descriptor strings must be loaded. - * (But they need not be initialized.) - * This loading may occur at any time before the {@code MethodType} object is first derived. *

- * Like classes and strings, method types can be represented directly - * in a class file's constant pool as constants to be loaded by {@code ldc} bytecodes. - * Loading such a constant causes its component classes to be loaded as necessary. + * Like classes and strings, method types can also be represented directly + * in a class file's constant pool as constants. The may be loaded by an {@code ldc} + * instruction which refers to a suitable {@code CONSTANT_MethodType} constant pool entry. + * The entry refers to a {@code CONSTANT_Utf8} spelling for the descriptor string. + * For more details, see the package summary. + *

+ * When the JVM materializes a {@code MethodType} from a descriptor string, + * all classes named in the descriptor must be accessible, and will be loaded. + * (But the classes need not be initialized, as is the case with a {@code CONSTANT_Class}.) + * This loading may occur at any time before the {@code MethodType} object is first derived. * @author John Rose, JSR 292 EG */ public final -class MethodType implements java.lang.reflect.Type { +class MethodType { private final Class rtype; private final Class[] ptypes; private MethodTypeForm form; // erased form, plus cached data about primitives @@ -301,6 +313,14 @@ } /** Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[])}. + * @param ptypesToInsert zero or more a new parameter types to insert after the end of the parameter list + * @return the same type, except with the selected parameter(s) appended + */ + public MethodType appendParameterTypes(List> ptypesToInsert) { + return insertParameterTypes(parameterCount(), ptypesToInsert); + } + + /** Convenience method for {@link #methodType(java.lang.Class, java.lang.Class[])}. * @param num the position (zero-based) of the inserted parameter type(s) * @param ptypesToInsert zero or more a new parameter types to insert into the parameter list * @return the same type, except with the selected parameter(s) inserted @@ -508,7 +528,9 @@ * parenthesis enclosed, comma separated list of type names, * followed immediately by the return type. *

- * If a type name is array, it the base type followed + * Each type is represented by its + * {@link java.lang.Class#getSimpleName simple name}. + * If a type name name is array, it the base type followed * by [], rather than the Class.getName of the array type. */ @Override @@ -517,35 +539,13 @@ sb.append("("); for (int i = 0; i < ptypes.length; i++) { if (i > 0) sb.append(","); - putName(sb, ptypes[i]); + sb.append(ptypes[i].getSimpleName()); } sb.append(")"); - putName(sb, rtype); + sb.append(rtype.getSimpleName()); return sb.toString(); } - static void putName(StringBuilder sb, Class cls) { - int brackets = 0; - while (cls.isArray()) { - cls = cls.getComponentType(); - brackets++; - } - String n = cls.getName(); - /* - if (n.startsWith("java.lang.")) { - String nb = n.substring("java.lang.".length()); - if (nb.indexOf('.') < 0) n = nb; - } else if (n.indexOf('.') < 0) { - n = "."+n; // anonymous package - } - */ - sb.append(n); - while (brackets > 0) { - sb.append("[]"); - brackets--; - } - } - /// Queries which have to do with the bytecode architecture /** The number of JVM stack slots required to invoke a method