33
33
import java .util .Map ;
34
34
35
35
import jdk .internal .reflect .ConstantPool ;
36
+ import sun .invoke .util .Wrapper ;
36
37
import sun .reflect .annotation .AnnotationType ;
37
38
38
39
/**
@@ -57,14 +58,14 @@ public final class Class<T> implements Serializable, GenericDeclaration, Type, A
57
58
58
59
// we init this on demand (from MJIEnv) since it's not used too often
59
60
private static Annotation [] emptyAnnotations ; // = new Annotation[0];
60
-
61
+
61
62
private String name ;
62
63
63
64
// set by VM
64
65
private transient Module module ;
65
66
66
67
private ClassLoader classLoader ;
67
-
68
+
68
69
/**
69
70
* search global id of the corresponding ClassInfo, which factors in the classloader
70
71
*/
@@ -95,7 +96,7 @@ private Class() {}
95
96
public native Class <?> getComponentType ();
96
97
97
98
public native Field [] getFields () throws SecurityException ;
98
-
99
+
99
100
public native Field getDeclaredField (String fieldName ) throws NoSuchFieldException ,
100
101
SecurityException ;
101
102
@@ -110,7 +111,7 @@ public native Method getMethod (String mthName, Class<?>... paramTypes)
110
111
public native Method [] getDeclaredMethods () throws SecurityException ;
111
112
112
113
public native Method [] getMethods () throws SecurityException ;
113
-
114
+
114
115
public native Constructor <?>[] getDeclaredConstructors () throws SecurityException ;
115
116
116
117
public native Constructor <?>[] getConstructors () throws SecurityException ;
@@ -182,7 +183,7 @@ public String getPackageName() {
182
183
T [] getEnumConstantsShared () {
183
184
return getEnumConstants ();
184
185
}
185
-
186
+
186
187
// lazy initialized map for field name -> Enum constants
187
188
// <2do> we should move this to the native side, since Enum constants don't change
188
189
private transient Map <String , T > enumConstantDirectory = null ;
@@ -229,16 +230,33 @@ public String getName () {
229
230
public String getSimpleName () {
230
231
int idx ; // <2do> not really - inner classes?
231
232
Class <?> enclosingClass = getEnclosingClass ();
232
-
233
+
233
234
if (enclosingClass !=null ){
234
235
idx = enclosingClass .getName ().length ();
235
236
} else {
236
237
idx = name .lastIndexOf ('.' );
237
238
}
238
-
239
+
239
240
return name .substring (idx +1 );
240
241
}
241
242
243
+ public String descriptorString (){
244
+ if (isPrimitive ()){
245
+ return Wrapper .forPrimitiveType (this ).basicTypeString ();
246
+ }
247
+
248
+ if (isArray ()){
249
+ return "[" + getComponentType ().descriptorString ();
250
+ }else {
251
+ String name = getName ().replace ('.' , '/' );
252
+
253
+ StringBuilder s = new StringBuilder (name .length ()+2 );
254
+ s .append ('L' ).append (name ).append (';' );
255
+
256
+ return s .toString ();
257
+ }
258
+ }
259
+
242
260
static native Class <?> getPrimitiveClass (String clsName );
243
261
244
262
/**
0 commit comments