re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java)
authorAndrew Haley <aph@redhat.com>
Wed, 28 May 2008 15:12:47 +0000 (15:12 +0000)
committerAndrew Haley <aph@gcc.gnu.org>
Wed, 28 May 2008 15:12:47 +0000 (15:12 +0000)
2008-05-28  Andrew Haley  <aph@redhat.com>

* java/lang/Class.java (getSimpleName): Use getEnclosingClass().
* testsuite/libjava.lang/PR35020.java: New cases.
* testsuite/libjava.lang/PR35020.out: New cases.

From-SVN: r136103

libjava/ChangeLog
libjava/classpath/lib/java/lang/Class.class
libjava/java/lang/Class.java
libjava/testsuite/libjava.lang/PR35020.jar
libjava/testsuite/libjava.lang/PR35020.java
libjava/testsuite/libjava.lang/PR35020.out

index 37f12e2c8927cbb248c5f3bb4a26cb265b1edd1d..65abe270155d7ec958909ae481a0e73cff95a30b 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-28  Andrew Haley  <aph@redhat.com>
+
+       * java/lang/Class.java (getSimpleName): Use getEnclosingClass().        
+       * testsuite/libjava.lang/PR35020.java: New cases.
+       * testsuite/libjava.lang/PR35020.out: New cases.
+
 2008-05-22  Andrew Haley  <aph@redhat.com>
 
        PR libgcj/35020
index ce854558e542fb0e5114f54b01889a3be01df88d..2e4126b71d908a24a6fe3076178b7121ec078441 100644 (file)
Binary files a/libjava/classpath/lib/java/lang/Class.class and b/libjava/classpath/lib/java/lang/Class.class differ
index 868e370b819da70f334f261f1c59791175a2f858..a4e8ee5929e5a15e8dbec891d875e49ac2172108 100644 (file)
@@ -1078,26 +1078,24 @@ public final class Class<T>
     if (isAnonymousClass())
       return "";
     if (isArray())
-      {
-       return getComponentType().getSimpleName() + "[]";
-      }
+      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);
-      }
+    Class enclosingClass = getEnclosingClass();
+    if (enclosingClass == null)
+      // It's a top level class.
+      return fullName.substring(fullName.lastIndexOf(".") + 1);
 
-    int packagePos = fullName.lastIndexOf(".");
-    if (packagePos == -1)
-      return fullName;
-    else
-      return fullName.substring(packagePos + 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;
   }
 
   /**
index bedaed7ecdba7b3a38f6411f9e1d1c7d89b0873d..09c4ef4818d4230f674fcc2c8a2fdfbd9fe6ac45 100644 (file)
Binary files a/libjava/testsuite/libjava.lang/PR35020.jar and b/libjava/testsuite/libjava.lang/PR35020.jar differ
index 1850da79683cb0dfcc60310dd95b13aecd4cb459..ff5f6bf06f275c521e67ca69b7d7a4e0782dee20 100644 (file)
@@ -1,21 +1,30 @@
+class outer$inner
+{
+};
+
 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());
-   }
+  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 73eb0c917fc6263f5b8d70dfba2a25c535f2c9ab..9bf85e209d5bad9372de2773f1833956fa2ce59f 100644 (file)
@@ -4,3 +4,6 @@ Class
 int[]
 Object[][][][][][][][]
 
+PR35020$Inner
+outer$inner
+inner