From 71292a05408898d2e37ef5442083d1819ead741a Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Wed, 28 May 2008 15:12:47 +0000 Subject: [PATCH] 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 --- libjava/ChangeLog | 6 +++ libjava/classpath/lib/java/lang/Class.class | Bin 15551 -> 15545 bytes libjava/java/lang/Class.java | 34 +++++++-------- libjava/testsuite/libjava.lang/PR35020.jar | Bin 1856 -> 3559 bytes libjava/testsuite/libjava.lang/PR35020.java | 45 ++++++++++++-------- libjava/testsuite/libjava.lang/PR35020.out | 3 ++ 6 files changed, 52 insertions(+), 36 deletions(-) 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 ce854558e542fb0e5114f54b01889a3be01df88d..2e4126b71d908a24a6fe3076178b7121ec078441 100644 GIT binary patch delta 628 zcmY*VNla5w6g`*TO9#KjQmV8L(Kv)s#8`pf`b&`%1dPba5K$9}skN~!B*g_LMnjYh zarHEsYBa9gl92r9ihxu=a9%n^Hk!Cml(oLZm76=Ad(IuEN1u#Nz7Iw{AbM)h9Qp{p zOnRiVa5gto%oZ}K++eZjqGtqZ^x!Hj7?h<&LO?yF8h4L}mgt3(mX#5zZGK6w2+nM= zBb&*N5V$TC9w4~RUCiZ<4d&AXZ~8x3f@64SYB*E~xhvoR0~l6co1$0hZJOVccZ{Z;MXGc|Mo%+0y>K#Nw3iW zf{8f2(X|TnBS>#CrH5|R9frpA9lC!L^iye0tu|i@-quUpfx#vC_$~r`4lN&JPmYPU3{RP25ijV*R delta 671 zcmY*UTS(J!6#mY3PP@3Y-84<3$ilT!TIO_fTK&DG+2yS;lm3jkmeYyTz#t}4K?L>i ze~3nfKKUvLqEA7ZrZ&60CREg0(L-syRln$|mvhc{IUncDjXW8ddRy$V(ma96?HHwJ z4oc7>!D~#AC(~x9=d@y>WrF*PepRnZ>izL5?Xo_oM~7mA4qBxb1WO{_l!zyW2wb80 zI<2&((kcnop5bKjwB8pZmW9RR8p%VQvijtGv-18Uj!Cu zM1dTITaKw54OP;NptK+?ttz7pF=4HrzB44_VyWte2j9=j~xd(^b JH*VHf{{bmfmVW>M 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 bedaed7ecdba7b3a38f6411f9e1d1c7d89b0873d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12HwTf4@tA~~=8#RwVnLXMk^)goV`T$6 QoPiYxi-F;?ofX6b0L_5QDgXcg 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 -- 2.30.2