Index: java/lang/Class.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/lang/Class.java,v retrieving revision 1.22.2.13 diff -u -3 -p -u -r1.22.2.13 Class.java --- java/lang/Class.java 28 Apr 2005 23:00:13 -0000 1.22.2.13 +++ java/lang/Class.java 5 May 2005 22:23:31 -0000 @@ -1417,4 +1417,21 @@ public final class Class return VMClass.isAnnotation(this); } + /** + * Returns the simple name for this class, as used in the source + * code. For normal classes, this is the content returned by + * getName() which follows the last ".". Anonymous + * classes have no name, and so the result of calling this method is + * "". The simple name of an array consists of the simple name of + * its component type, followed by "[]". Thus, an array with the + * component type of an anonymous class has a simple name of simply + * "[]". + * + * @return the simple name for this class. + */ + public String getSimpleName() + { + return VMClass.getSimpleName(this); + } + } Index: vm/reference/java/lang/VMClass.java =================================================================== RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMClass.java,v retrieving revision 1.10.2.4 diff -u -3 -p -u -r1.10.2.4 VMClass.java --- vm/reference/java/lang/VMClass.java 28 Apr 2005 23:00:15 -0000 1.10.2.4 +++ vm/reference/java/lang/VMClass.java 5 May 2005 22:23:31 -0000 @@ -329,4 +329,26 @@ final class VMClass */ static native boolean isEnum(Class klass); + /** + * Returns the simple name for this class, as used in the source + * code. For normal classes, this is the content returned by + * getName() which follows the last ".". Anonymous + * classes have no name, and so the result of calling this method is + * "". The simple name of an array consists of the simple name of + * its component type, followed by "[]". Thus, an array with the + * component type of an anonymous class has a simple name of simply + * "[]". + * + * @return the simple name for this class. + */ + static String getSimpleName(Class klass) + { + if (klass.isArray()) + { + return klass.getComponentType().getSimpleName() + "[]"; + } + String fullName = klass.getName(); + return fullName.substring(fullName.lastIndexOf(".") + 1); + } + } // class VMClass