src/share/classes/java/lang/reflect/Parameter.java

Print this page

        

*** 42,52 **** public final class Parameter implements AnnotatedElement { private final String name; private final int modifiers; private final Executable executable; ! private int index; /** * Package-private constructor for {@code Parameter}. * * If method parameter data is present in the classfile, then the --- 42,52 ---- public final class Parameter implements AnnotatedElement { private final String name; private final int modifiers; private final Executable executable; ! private final int index; /** * Package-private constructor for {@code Parameter}. * * If method parameter data is present in the classfile, then the
*** 93,105 **** public int hashCode() { return executable.hashCode() ^ index; } /** ! * Returns a string representation of the parameter's modifiers, ! * its attributes, its type, its name, and a trailing ... if it is ! * a variadic parameter. * * @return A string representation of the parameter and associated * information. */ public String toString() { --- 93,110 ---- public int hashCode() { return executable.hashCode() ^ index; } /** ! * Returns a string describing this parameter. The format is the ! * modifiers for the parameter, if any, in canonical order as ! * recommended by <cite>The Java&trade; Language ! * Specification</cite>, followed by the fully- qualified type of ! * the parameter (excluding the last [] if the parameter is ! * variable arity), followed by "..." if the parameter is variable ! * arity, followed by a space, followed by the name of the ! * parameter. * * @return A string representation of the parameter and associated * information. */ public String toString() {
*** 116,126 **** sb.append(typename.replaceFirst("\\[\\]$", "...")); else sb.append(typename); sb.append(" "); ! sb.append(name); return sb.toString(); } /** --- 121,131 ---- sb.append(typename.replaceFirst("\\[\\]$", "...")); else sb.append(typename); sb.append(" "); ! sb.append(getName()); return sb.toString(); } /**
*** 141,154 **** public int getModifiers() { return modifiers; } /** ! * Returns the name of the parameter represented by this ! * {@code Parameter} object. */ public String getName() { return name; } /** * Returns a {@code Type} object that identifies the parameterized --- 146,171 ---- public int getModifiers() { return modifiers; } /** ! * Returns the name of the parameter. The names of the parameters ! * of a single executable must all the be distinct. When names ! * from the originating source are available, they are returned. ! * Otherwise, an implementation of this method is free to create a ! * name of this parameter, subject to the unquiness requirments. */ public String getName() { + // As per the spec, if a parameter has no name, return argX, + // where x is the index. + // + // Note: spec updates now outlaw empty strings as parameter + // names. The .equals("") is for compatibility with current + // JVM behavior. It may be removed at some point. + if(name == null || name.equals("")) + return "arg" + index; + else return name; } /** * Returns a {@code Type} object that identifies the parameterized
*** 188,211 **** } private transient volatile Class<?> parameterClassCache = null; /** ! * Returns {@code true} if this parameter is a synthesized ! * construct; returns {@code false} otherwise. * ! * @return true if and only if this parameter is a synthesized ! * construct as defined by ! * <cite>The Java&trade; Language Specification</cite>. */ ! public boolean isSynthesized() { ! return Modifier.isSynthesized(getModifiers()); } /** ! * Returns {@code true} if this parameter is a synthetic ! * construct; returns {@code false} otherwise. * * @jls 13.1 The Form of a Binary * @return true if and only if this parameter is a synthetic * construct as defined by * <cite>The Java&trade; Language Specification</cite>. --- 205,229 ---- } private transient volatile Class<?> parameterClassCache = null; /** ! * Returns {@code true} if this parameter is implicitly declared ! * in source code; returns {@code false} otherwise. * ! * @return true if and only if this parameter is implicitly ! * declared as defined by <cite>The Java&trade; Language ! * Specification</cite>. */ ! public boolean isImplicit() { ! return Modifier.isMandated(getModifiers()); } /** ! * Returns {@code true} if this parameter is neither implicitly ! * nor explicitly declared in source code; returns {@code false} ! * otherwise. * * @jls 13.1 The Form of a Binary * @return true if and only if this parameter is a synthetic * construct as defined by * <cite>The Java&trade; Language Specification</cite>.