Commit 9f8e4e84 by Andrew Haley Committed by Andrew Haley

re PR libgcj/35020 (Class.getSimpleName() differs from Sun Java)

2008-05-22  Andrew Haley  <aph@redhat.com>

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

From-SVN: r135771
parent 4799e6aa
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> 2008-05-20 David Daney <ddaney@avtrex.com>
PR libgcj/36252 PR libgcj/36252
......
...@@ -1075,22 +1075,27 @@ public final class Class<T> ...@@ -1075,22 +1075,27 @@ public final class Class<T>
*/ */
public String getSimpleName() public String getSimpleName()
{ {
StringBuffer sb = new StringBuffer(); if (isAnonymousClass())
Class klass = this; return "";
int arrayCount = 0; if (isArray())
while (klass.isArray())
{ {
klass = klass.getComponentType(); return getComponentType().getSimpleName() + "[]";
++arrayCount;
} }
if (! klass.isAnonymousClass()) String fullName = getName();
int pos = fullName.lastIndexOf("$");
if (pos == -1)
pos = 0;
else
{ {
String fullName = klass.getName(); ++pos;
sb.append(fullName, fullName.lastIndexOf(".") + 1, fullName.length()); while (Character.isDigit(fullName.charAt(pos)))
++pos;
} }
while (arrayCount-- > 0) int packagePos = fullName.lastIndexOf(".", pos);
sb.append("[]"); if (packagePos == -1)
return sb.toString(); return fullName.substring(pos);
else
return fullName.substring(packagePos + 1);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment