1.1 --- a/emul/src/main/java/java/lang/Class.java Sat Dec 01 12:15:12 2012 +0100
1.2 +++ b/emul/src/main/java/java/lang/Class.java Sat Dec 01 12:35:30 2012 +0100
1.3 @@ -447,40 +447,57 @@
1.4 * @since 1.5
1.5 */
1.6 public String getSimpleName() {
1.7 - throw new UnsupportedOperationException();
1.8 -//// if (isArray())
1.9 -//// return getComponentType().getSimpleName()+"[]";
1.10 -////
1.11 -//// String simpleName = getSimpleBinaryName();
1.12 -//// if (simpleName == null) { // top level class
1.13 -//// simpleName = getName();
1.14 -//// return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
1.15 -//// }
1.16 -//// // According to JLS3 "Binary Compatibility" (13.1) the binary
1.17 -//// // name of non-package classes (not top level) is the binary
1.18 -//// // name of the immediately enclosing class followed by a '$' followed by:
1.19 -//// // (for nested and inner classes): the simple name.
1.20 -//// // (for local classes): 1 or more digits followed by the simple name.
1.21 -//// // (for anonymous classes): 1 or more digits.
1.22 -////
1.23 -//// // Since getSimpleBinaryName() will strip the binary name of
1.24 -//// // the immediatly enclosing class, we are now looking at a
1.25 -//// // string that matches the regular expression "\$[0-9]*"
1.26 -//// // followed by a simple name (considering the simple of an
1.27 -//// // anonymous class to be the empty string).
1.28 -////
1.29 -//// // Remove leading "\$[0-9]*" from the name
1.30 -//// int length = simpleName.length();
1.31 -//// if (length < 1 || simpleName.charAt(0) != '$')
1.32 -//// throw new InternalError("Malformed class name");
1.33 -//// int index = 1;
1.34 -//// while (index < length && isAsciiDigit(simpleName.charAt(index)))
1.35 -//// index++;
1.36 -//// // Eventually, this is the empty string iff this is an anonymous class
1.37 -//// return simpleName.substring(index);
1.38 + if (isArray())
1.39 + return getComponentType().getSimpleName()+"[]";
1.40 +
1.41 + String simpleName = getSimpleBinaryName();
1.42 + if (simpleName == null) { // top level class
1.43 + simpleName = getName();
1.44 + return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
1.45 + }
1.46 + // According to JLS3 "Binary Compatibility" (13.1) the binary
1.47 + // name of non-package classes (not top level) is the binary
1.48 + // name of the immediately enclosing class followed by a '$' followed by:
1.49 + // (for nested and inner classes): the simple name.
1.50 + // (for local classes): 1 or more digits followed by the simple name.
1.51 + // (for anonymous classes): 1 or more digits.
1.52 +
1.53 + // Since getSimpleBinaryName() will strip the binary name of
1.54 + // the immediatly enclosing class, we are now looking at a
1.55 + // string that matches the regular expression "\$[0-9]*"
1.56 + // followed by a simple name (considering the simple of an
1.57 + // anonymous class to be the empty string).
1.58 +
1.59 + // Remove leading "\$[0-9]*" from the name
1.60 + int length = simpleName.length();
1.61 + if (length < 1 || simpleName.charAt(0) != '$')
1.62 + throw new IllegalStateException("Malformed class name");
1.63 + int index = 1;
1.64 + while (index < length && isAsciiDigit(simpleName.charAt(index)))
1.65 + index++;
1.66 + // Eventually, this is the empty string iff this is an anonymous class
1.67 + return simpleName.substring(index);
1.68 }
1.69
1.70 /**
1.71 + * Returns the "simple binary name" of the underlying class, i.e.,
1.72 + * the binary name without the leading enclosing class name.
1.73 + * Returns {@code null} if the underlying class is a top level
1.74 + * class.
1.75 + */
1.76 + private String getSimpleBinaryName() {
1.77 + Class<?> enclosingClass = null; // XXX getEnclosingClass();
1.78 + if (enclosingClass == null) // top level class
1.79 + return null;
1.80 + // Otherwise, strip the enclosing class' name
1.81 + try {
1.82 + return getName().substring(enclosingClass.getName().length());
1.83 + } catch (IndexOutOfBoundsException ex) {
1.84 + throw new IllegalStateException("Malformed class name");
1.85 + }
1.86 + }
1.87 +
1.88 + /**
1.89 * Character.isDigit answers {@code true} to some non-ascii
1.90 * digits. This one does not.
1.91 */