From: Andrew Haley Date: Wed, 28 May 2008 15:12:47 +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=71292a05408898d2e37ef5442083d1819ead741a;p=gcc.git re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java) 2008-05-28 Andrew Haley * java/lang/Class.java (getSimpleName): Use getEnclosingClass(). * testsuite/libjava.lang/PR35020.java: New cases. * testsuite/libjava.lang/PR35020.out: New cases. From-SVN: r136103 --- diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 37f12e2c892..65abe270155 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,9 @@ +2008-05-28 Andrew Haley + + * 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 PR libgcj/35020 diff --git a/libjava/classpath/lib/java/lang/Class.class b/libjava/classpath/lib/java/lang/Class.class index ce854558e54..2e4126b71d9 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 868e370b819..a4e8ee5929e 100644 --- a/libjava/java/lang/Class.java +++ b/libjava/java/lang/Class.java @@ -1078,26 +1078,24 @@ public final class Class 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; } /** diff --git a/libjava/testsuite/libjava.lang/PR35020.jar b/libjava/testsuite/libjava.lang/PR35020.jar index bedaed7ecdb..09c4ef4818d 100644 Binary files a/libjava/testsuite/libjava.lang/PR35020.jar and b/libjava/testsuite/libjava.lang/PR35020.jar differ diff --git a/libjava/testsuite/libjava.lang/PR35020.java b/libjava/testsuite/libjava.lang/PR35020.java index 1850da79683..ff5f6bf06f2 100644 --- a/libjava/testsuite/libjava.lang/PR35020.java +++ b/libjava/testsuite/libjava.lang/PR35020.java @@ -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()); + } } - diff --git a/libjava/testsuite/libjava.lang/PR35020.out b/libjava/testsuite/libjava.lang/PR35020.out index 73eb0c917fc..9bf85e209d5 100644 --- a/libjava/testsuite/libjava.lang/PR35020.out +++ b/libjava/testsuite/libjava.lang/PR35020.out @@ -4,3 +4,6 @@ Class int[] Object[][][][][][][][] +PR35020$Inner +outer$inner +inner