277
284
static native void throwException(Throwable t);
287
* Returns the simple name for the specified class, as used in the source
288
* code. For normal classes, this is the content returned by
289
* <code>getName()</code> which follows the last ".". Anonymous
290
* classes have no name, and so the result of calling this method is
291
* "". The simple name of an array consists of the simple name of
292
* its component type, followed by "[]". Thus, an array with the
293
* component type of an anonymous class has a simple name of simply
296
* @param klass the class whose simple name should be returned.
297
* @return the simple name for this class.
299
static String getSimpleName(Class klass)
303
return getComponentType(klass).getSimpleName() + "[]";
305
String fullName = getName(klass);
306
return fullName.substring(fullName.lastIndexOf(".") + 1);
310
* Returns all annotations directly defined by the specified class. If
311
* there are no annotations associated with this class, then a zero-length
312
* array will be returned. The returned array may be modified by the client
313
* code, but this will have no effect on the annotation content of this
314
* class, and hence no effect on the return value of this method for
317
* @param klass the class whose annotations should be returned.
318
* @return the annotations directly defined by the specified class.
321
static native Annotation[] getDeclaredAnnotations(Class klass);
325
* Returns the canonical name of the specified class, as defined by section
326
* 6.7 of the Java language specification. Each package, top-level class,
327
* top-level interface and primitive type has a canonical name. A member
328
* class has a canonical name, if its parent class has one. Likewise,
329
* an array type has a canonical name, if its component type does.
330
* Local or anonymous classes do not have canonical names.
333
* The canonical name for top-level classes, top-level interfaces and
334
* primitive types is always the same as the fully-qualified name.
335
* For array types, the canonical name is the canonical name of its
336
* component type with `[]' appended.
339
* The canonical name of a member class always refers to the place where
340
* the class was defined, and is composed of the canonical name of the
341
* defining class and the simple name of the member class, joined by `.'.
342
* For example, if a <code>Person</code> class has an inner class,
343
* <code>M</code>, then both its fully-qualified name and canonical name
344
* is <code>Person.M</code>. A subclass, <code>Staff</code>, of
345
* <code>Person</code> refers to the same inner class by the fully-qualified
346
* name of <code>Staff.M</code>, but its canonical name is still
347
* <code>Person.M</code>.
350
* Where no canonical name is present, <code>null</code> is returned.
353
* @param klass the class whose canonical name should be retrieved.
354
* @return the canonical name of the class, or <code>null</code> if the
355
* class doesn't have a canonical name.
358
static String getCanonicalName(Class klass)
362
String componentName = getComponentType(klass).getCanonicalName();
363
if (componentName != null)
364
return componentName + "[]";
366
if (isMemberClass(klass))
368
String memberName = getDeclaringClass(klass).getCanonicalName();
369
if (memberName != null)
370
return memberName + "." + getSimpleName(klass);
372
if (isLocalClass(klass) || isAnonymousClass(klass))
374
return getName(klass);
378
* Returns the class which immediately encloses the specified class. If
379
* the class is a top-level class, this method returns <code>null</code>.
381
* @param klass the class whose enclosing class should be returned.
382
* @return the immediate enclosing class, or <code>null</code> if this is
386
static native Class getEnclosingClass(Class klass);
389
* Returns the constructor which immediately encloses the specified class.
390
* If the class is a top-level class, or a local or anonymous class
391
* immediately enclosed by a type definition, instance initializer
392
* or static initializer, then <code>null</code> is returned.
394
* @param klass the class whose enclosing constructor should be returned.
395
* @return the immediate enclosing constructor if the specified class is
396
* declared within a constructor. Otherwise, <code>null</code>
400
static native Constructor getEnclosingConstructor(Class klass);
403
* Returns the method which immediately encloses the specified class. If
404
* the class is a top-level class, or a local or anonymous class
405
* immediately enclosed by a type definition, instance initializer
406
* or static initializer, then <code>null</code> is returned.
408
* @param klass the class whose enclosing method should be returned.
409
* @return the immediate enclosing method if the specified class is
410
* declared within a method. Otherwise, <code>null</code>
414
static native Method getEnclosingMethod(Class klass);
417
* Returns the class signature as specified in Class File Format
418
* chapter in the VM specification, or null if the class is not
421
* @param klass the klass to test.
422
* @return a ClassSignature string.
425
static native String getClassSignature(Class klass);
428
* Returns true if the specified class represents an anonymous class.
430
* @param klass the klass to test.
431
* @return true if the specified class represents an anonymous class.
434
static native boolean isAnonymousClass(Class klass);
437
* Returns true if the specified class represents an local class.
439
* @param klass the klass to test.
440
* @return true if the specified class represents an local class.
443
static native boolean isLocalClass(Class klass);
446
* Returns true if the specified class represents an member class.
448
* @param klass the klass to test.
449
* @return true if the specified class represents an member class.
452
static native boolean isMemberClass(Class klass);
279
454
} // class VMClass