re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java)
authorAndrew Haley <aph@redhat.com>
Thu, 22 May 2008 16:20:55 +0000 (16:20 +0000)
committerAndrew Haley <aph@gcc.gnu.org>
Thu, 22 May 2008 16:20:55 +0000 (16:20 +0000)
2008-05-22  Andrew Haley  <aph@redhat.com>

        PR libgcj/35020
        * java/lang/Class.java (getSimpleName): Import from GNU Classpath.

From-SVN: r135771

libjava/ChangeLog
libjava/classpath/lib/java/lang/Class$1.class
libjava/classpath/lib/java/lang/Class.class
libjava/java/lang/Class.java

index e8cd46e894755cde48fdee7904571928bb0718d3..52061d2c1edaa7cd82ab33a88d31895a42fce69b 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-22  Andrew Haley  <aph@redhat.com>
+
+       PR libgcj/35020
+       * java/lang/Class.java (getSimpleName): Import from GNU Classpath.
+
 2008-05-20  David Daney  <ddaney@avtrex.com>
 
        PR libgcj/36252
index 51ef8849385cda3875ba35c8353cd59c40f3e8e8..09e3e86f9954b60f48813dff60c6349d9a59a6f1 100644 (file)
Binary files a/libjava/classpath/lib/java/lang/Class$1.class and b/libjava/classpath/lib/java/lang/Class$1.class differ
index ffe072f5337a6bcc931dad981f40f1c6cad76519..bdcfcfe83bda48e1ab9fce5acf4427d4f3df4cc3 100644 (file)
Binary files a/libjava/classpath/lib/java/lang/Class.class and b/libjava/classpath/lib/java/lang/Class.class differ
index 691f983b0b55a424a6227e493f3e7848fb35aa36..d59e83ea4ec336c19f96d4c79090eb7ac1ee4dc5 100644 (file)
@@ -1075,22 +1075,27 @@ public final class Class<T>
    */
   public String getSimpleName()
   {
-    StringBuffer sb = new StringBuffer();
-    Class klass = this;
-    int arrayCount = 0;
-    while (klass.isArray())
+    if (isAnonymousClass())
+      return "";
+    if (isArray())
       {
-       klass = klass.getComponentType();
-       ++arrayCount;
+       return getComponentType().getSimpleName() + "[]";
       }
-    if (! klass.isAnonymousClass())
+    String fullName = getName();
+    int pos = fullName.lastIndexOf("$");
+    if (pos == -1)
+      pos = 0;
+    else
       {
-       String fullName = klass.getName();
-       sb.append(fullName, fullName.lastIndexOf(".") + 1, fullName.length());
+       ++pos;
+       while (Character.isDigit(fullName.charAt(pos)))
+         ++pos;
       }
-    while (arrayCount-- > 0)
-      sb.append("[]");
-    return sb.toString();
+    int packagePos = fullName.lastIndexOf(".", pos);
+    if (packagePos == -1)
+      return fullName.substring(pos);
+    else
+      return fullName.substring(packagePos + 1);
   }
 
   /**