Commit 71292a05 by Andrew Haley Committed by Andrew Haley

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

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

	* java/lang/Class.java (getSimpleName): Use getEnclosingClass().	
	* testsuite/libjava.lang/PR35020.java: New cases.
	* testsuite/libjava.lang/PR35020.out: New cases.

From-SVN: r136103
parent 38154e4f
2008-05-28 Andrew Haley <aph@redhat.com>
* 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 <aph@redhat.com> 2008-05-22 Andrew Haley <aph@redhat.com>
PR libgcj/35020 PR libgcj/35020
......
...@@ -1078,26 +1078,24 @@ public final class Class<T> ...@@ -1078,26 +1078,24 @@ public final class Class<T>
if (isAnonymousClass()) if (isAnonymousClass())
return ""; return "";
if (isArray()) if (isArray())
{
return getComponentType().getSimpleName() + "[]"; return getComponentType().getSimpleName() + "[]";
}
String fullName = getName(); String fullName = getName();
int pos = fullName.lastIndexOf("$"); Class enclosingClass = getEnclosingClass();
if (pos == -1) if (enclosingClass == null)
pos = 0; // It's a top level class.
else return fullName.substring(fullName.lastIndexOf(".") + 1);
{
++pos; 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))) while (Character.isDigit(fullName.charAt(pos)))
++pos; ++pos;
fullName = fullName.substring(pos); fullName = fullName.substring(pos);
}
int packagePos = fullName.lastIndexOf(".");
if (packagePos == -1)
return fullName; return fullName;
else
return fullName.substring(packagePos + 1);
} }
/** /**
......
class outer$inner
{
};
public class PR35020 public class PR35020
{ {
class PR35020$Inner
{
};
class inner class inner
{ {
} }
...@@ -16,6 +23,8 @@ public class PR35020 ...@@ -16,6 +23,8 @@ public class PR35020
return null; return null;
} }
}).getClass().getSimpleName()); }).getClass().getSimpleName());
System.out.println(PR35020$Inner.class.getSimpleName());
System.out.println(outer$inner.class.getSimpleName());
System.out.println(outer$inner.inner.class.getSimpleName());
} }
} }
...@@ -4,3 +4,6 @@ Class ...@@ -4,3 +4,6 @@ Class
int[] int[]
Object[][][][][][][][] Object[][][][][][][][]
PR35020$Inner
outer$inner
inner
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