Tom Tromey wrote:
>
> The test class is something like:
>
> public class Foo$What { }
>
> The simple name of this is "Foo$What", not "What".
Ahh, *that's* what you're talking about.
Fixed thusly.
Andrew.
2008-05-28 Andrew Haley <[EMAIL PROTECTED]>
* java/lang/Class.java (getSimpleName): Use getEnclosingClass().
* testsuite/libjava.lang/PR35020.java: New cases.
* testsuite/libjava.lang/PR35020.out: New cases.
Index: java/lang/Class.java
===================================================================
*** java/lang/Class.java (revision 135801)
--- java/lang/Class.java (working copy)
***************
*** 1077,1104 ****
{
if (isAnonymousClass())
return "";
if (isArray())
! {
! return getComponentType().getSimpleName() + "[]";
! }
String fullName = getName();
! int pos = fullName.lastIndexOf("$");
! if (pos == -1)
! pos = 0;
! else
! {
! ++pos;
! while (Character.isDigit(fullName.charAt(pos)))
! ++pos;
! fullName = fullName.substring(pos);
! }
! int packagePos = fullName.lastIndexOf(".");
! if (packagePos == -1)
! return fullName;
! else
! return fullName.substring(packagePos + 1);
}
/**
* Returns the class which immediately encloses this class. If this class
--- 1077,1102 ----
{
if (isAnonymousClass())
return "";
if (isArray())
! return getComponentType().getSimpleName() + "[]";
!
String fullName = getName();
! Class enclosingClass = getEnclosingClass();
! if (enclosingClass == null)
! // It's a top level class.
! return fullName.substring(fullName.lastIndexOf(".") + 1);
!
! fullName = fullName.substring(enclosingClass.getName().length());
!
! // We've carved off the enclosing class name; now we must have '$'
! // followed optionally by digits, followed by the class name.
! int pos = 1;
! while (Character.isDigit(fullName.charAt(pos)))
! ++pos;
! fullName = fullName.substring(pos);
! return fullName;
}
/**
* Returns the class which immediately encloses this class. If this class
Index: testsuite/libjava.lang/PR35020.java
===================================================================
*** testsuite/libjava.lang/PR35020.java (revision 135801)
--- testsuite/libjava.lang/PR35020.java (working copy)
***************
*** 1,21 ****
public class PR35020
{
! class inner
! {
! }
! public static void main(String[] args)
! {
! System.out.println(inner.class.getSimpleName());
! System.out.println(PR35020.class.getSimpleName());
! System.out.println(Class.class.getSimpleName());
! System.out.println((new int[7]).getClass().getSimpleName());
! System.out.println((new
Object[1][1][1][1][1][1][1][1]).getClass().getSimpleName());
! System.out.println((new java.security.PrivilegedAction()
! {
! public Object run() {
! return null;
! }
! }).getClass().getSimpleName());
! }
}
-
--- 1,31 ----
+ class outer$inner
+ {
+ public class inner{};
+ };
+
public class PR35020
{
! class PR35020$Inner
! {
! };
! class inner
! {
! }
! public static void main(String[] args)
! {
! System.out.println(inner.class.getSimpleName());
! System.out.println(PR35020.class.getSimpleName());
! System.out.println(Class.class.getSimpleName());
! System.out.println((new int[7]).getClass().getSimpleName());
! System.out.println((new
Object[1][1][1][1][1][1][1][1]).getClass().getSimpleName());
! System.out.println((new java.security.PrivilegedAction()
! {
! public Object run() {
! return null;
! }
! }).getClass().getSimpleName());
! System.out.println(PR35020$Inner.class.getSimpleName());
! System.out.println(outer$inner.class.getSimpleName());
! System.out.println(outer$inner.inner.class.getSimpleName());
! }
}
Index: testsuite/libjava.lang/PR35020.out
===================================================================
*** testsuite/libjava.lang/PR35020.out (revision 135801)
--- testsuite/libjava.lang/PR35020.out (working copy)
***************
*** 3,6 ****
--- 3,9 ----
Class
int[]
Object[][][][][][][][]
+ PR35020$Inner
+ outer$inner
+ inner