summaryrefslogtreecommitdiff
path: root/packages/classpath/files/SimpleName.diff
blob: ff2bec0f1cb9216fe2a4e94ef80ccc2d16582471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Index: vm/reference/java/lang/VMClass.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/java/lang/VMClass.java,v
retrieving revision 1.20
diff -u -r1.20 VMClass.java
--- vm/reference/java/lang/VMClass.java	18 Sep 2007 21:52:38 -0000	1.20
+++ vm/reference/java/lang/VMClass.java	19 Apr 2008 15:19:00 -0000
@@ -296,27 +296,43 @@
    */
   static String getSimpleName(Class klass)
   {
+    int arrayCount = 0;
+    while (klass.isArray())
+      {
+        klass = klass.getComponentType();
+        ++arrayCount;
+      }
+    // now klass is the component type
+    
+    String simpleComponentName = null;
     if (isAnonymousClass(klass))
-      return "";
-    if (isArray(klass))
       {
-	return getComponentType(klass).getSimpleName() + "[]";
+        simpleComponentName = "";
       }
-    String fullName = getName(klass);
-    int pos = fullName.lastIndexOf("$");
-    if (pos == -1)
-      pos = 0;
     else
       {
-	++pos;
-	while (Character.isDigit(fullName.charAt(pos)))
-	  ++pos;
+        String fullName = getName(klass);
+        int pos = fullName.lastIndexOf("$");
+        if (pos != -1) 
+          { //inner class or local class
+            // skip digits of local classes
+            while (Character.isDigit(fullName.charAt(pos+1)))
+              pos++;
+          } 
+        else 
+          {
+            pos = fullName.lastIndexOf(".");
+          }
+        simpleComponentName = fullName.substring(pos+1);
       }
-    int packagePos = fullName.lastIndexOf(".", pos);
-    if (packagePos == -1)
-      return fullName.substring(pos);
-    else
-      return fullName.substring(packagePos + 1);
+    
+    if (arrayCount == 0)
+      return simpleComponentName;
+    
+    StringBuffer sb = new StringBuffer(simpleComponentName);
+    while (arrayCount-- > 0)
+      sb.append("[]");
+    return sb.toString();        
   }
 
   /**