From: Andrew Haley Date: Thu, 22 May 2008 16:20:55 +0000 (+0000) Subject: re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f8e4e845ba0240f599fd541c5cee10cf8654cc5;p=gcc.git re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java) 2008-05-22 Andrew Haley PR libgcj/35020 * java/lang/Class.java (getSimpleName): Import from GNU Classpath. From-SVN: r135771 --- diff --git a/libjava/ChangeLog b/libjava/ChangeLog index e8cd46e8947..52061d2c1ed 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2008-05-22 Andrew Haley + + PR libgcj/35020 + * java/lang/Class.java (getSimpleName): Import from GNU Classpath. + 2008-05-20 David Daney PR libgcj/36252 diff --git a/libjava/classpath/lib/java/lang/Class$1.class b/libjava/classpath/lib/java/lang/Class$1.class index 51ef8849385..09e3e86f995 100644 Binary files a/libjava/classpath/lib/java/lang/Class$1.class and b/libjava/classpath/lib/java/lang/Class$1.class differ diff --git a/libjava/classpath/lib/java/lang/Class.class b/libjava/classpath/lib/java/lang/Class.class index ffe072f5337..bdcfcfe83bd 100644 Binary files a/libjava/classpath/lib/java/lang/Class.class and b/libjava/classpath/lib/java/lang/Class.class differ diff --git a/libjava/java/lang/Class.java b/libjava/java/lang/Class.java index 691f983b0b5..d59e83ea4ec 100644 --- a/libjava/java/lang/Class.java +++ b/libjava/java/lang/Class.java @@ -1075,22 +1075,27 @@ public final class Class */ 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); } /**