~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to vm/reference/java/lang/VMClass.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* VMClass.java -- VM Specific Class methods
2
 
   Copyright (C) 2003, 2004 Free Software Foundation
 
2
   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
3
3
 
4
4
This file is part of GNU Classpath.
5
5
 
37
37
 
38
38
package java.lang;
39
39
 
 
40
import java.lang.annotation.Annotation;
 
41
import java.lang.reflect.Array;
40
42
import java.lang.reflect.Constructor;
41
43
import java.lang.reflect.Field;
42
44
import java.lang.reflect.Method;
 
45
import java.lang.reflect.Modifier;
 
46
import java.lang.reflect.Type;
 
47
import java.lang.reflect.TypeVariable;
43
48
 
44
49
/*
45
50
 * This class is a reference version, mainly for compiling a class library
49
54
 
50
55
/**
51
56
 *
52
 
 * @author Etienne Gagnon <etienne.gagnon@uqam.ca>
53
 
 * @author Archie Cobbs <archie@dellroad.org>
54
 
 * @author C. Brian Jones <cbj@gnu.org>
 
57
 * @author Etienne Gagnon (etienne.gagnon@uqam.ca)
 
58
 * @author Archie Cobbs (archie@dellroad.org)
 
59
 * @author C. Brian Jones (cbj@gnu.org)
 
60
 * @author Tom Tromey (tromey@cygnus.com)
 
61
 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
55
62
 */
56
63
final class VMClass 
57
64
{
188
195
   * @param ignoreInnerClassesAttrib if set, return the real modifiers, not
189
196
   * the ones specified in the InnerClasses attribute.
190
197
   * @return the modifiers of this class
191
 
   * @see Modifer
 
198
   * @see Modifier
192
199
   * @since 1.1
193
200
   */
194
201
  static native int getModifiers(Class klass, boolean ignoreInnerClassesAttrib);
207
214
   * Like <code>getDeclaredClasses()</code> but without the security checks.
208
215
   *
209
216
   * @param klass the Class object that's calling us
210
 
   * @param pulicOnly Only public classes should be returned
 
217
   * @param publicOnly Only public classes should be returned
211
218
   */
212
219
  static native Class[] getDeclaredClasses(Class klass, boolean publicOnly);
213
220
 
215
222
   * Like <code>getDeclaredFields()</code> but without the security checks.
216
223
   *
217
224
   * @param klass the Class object that's calling us
218
 
   * @param pulicOnly Only public fields should be returned
 
225
   * @param publicOnly Only public fields should be returned
219
226
   */
220
227
  static native Field[] getDeclaredFields(Class klass, boolean publicOnly);
221
228
 
223
230
   * Like <code>getDeclaredMethods()</code> but without the security checks.
224
231
   *
225
232
   * @param klass the Class object that's calling us
226
 
   * @param pulicOnly Only public methods should be returned
 
233
   * @param publicOnly Only public methods should be returned
227
234
   */
228
235
  static native Method[] getDeclaredMethods(Class klass, boolean publicOnly);
229
236
 
232
239
   * the security checks.
233
240
   *
234
241
   * @param klass the Class object that's calling us
235
 
   * @param pulicOnly Only public constructors should be returned
 
242
   * @param publicOnly Only public constructors should be returned
236
243
   */
237
244
  static native Constructor[] getDeclaredConstructors(Class klass, boolean publicOnly);
238
245
 
276
283
   */
277
284
  static native void throwException(Throwable t);
278
285
 
 
286
  /**
 
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
 
294
   * "[]".
 
295
   *
 
296
   * @param klass the class whose simple name should be returned. 
 
297
   * @return the simple name for this class.
 
298
   */
 
299
  static String getSimpleName(Class klass)
 
300
  {
 
301
    if (isArray(klass))
 
302
      {
 
303
        return getComponentType(klass).getSimpleName() + "[]";
 
304
      }
 
305
    String fullName = getName(klass);
 
306
    return fullName.substring(fullName.lastIndexOf(".") + 1);
 
307
  }
 
308
 
 
309
  /**
 
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
 
315
   * future callers.
 
316
   *
 
317
   * @param klass the class whose annotations should be returned.
 
318
   * @return the annotations directly defined by the specified class.
 
319
   * @since 1.5
 
320
   */
 
321
  static native Annotation[] getDeclaredAnnotations(Class klass);
 
322
 
 
323
  /**
 
324
   * <p>
 
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.
 
331
   * </p>
 
332
   * <p>
 
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.  
 
337
   * </p>
 
338
   * <p>
 
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>.
 
348
   * </p>
 
349
   * <p>
 
350
   * Where no canonical name is present, <code>null</code> is returned.
 
351
   * </p>
 
352
   *
 
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.
 
356
   * @since 1.5
 
357
   */
 
358
  static String getCanonicalName(Class klass)
 
359
  {
 
360
    if (isArray(klass))
 
361
      {
 
362
        String componentName = getComponentType(klass).getCanonicalName();
 
363
        if (componentName != null)
 
364
          return componentName + "[]";
 
365
      }
 
366
    if (isMemberClass(klass))
 
367
      {
 
368
        String memberName = getDeclaringClass(klass).getCanonicalName();
 
369
        if (memberName != null)
 
370
          return memberName + "." + getSimpleName(klass);
 
371
      }
 
372
    if (isLocalClass(klass) || isAnonymousClass(klass))
 
373
      return null;
 
374
    return getName(klass);
 
375
  }
 
376
 
 
377
  /**
 
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>.
 
380
   *
 
381
   * @param klass the class whose enclosing class should be returned.
 
382
   * @return the immediate enclosing class, or <code>null</code> if this is
 
383
   *         a top-level class.
 
384
   * @since 1.5
 
385
   */
 
386
  static native Class getEnclosingClass(Class klass);
 
387
 
 
388
  /**
 
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.
 
393
   *
 
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>
 
397
   *         is returned.
 
398
   * @since 1.5
 
399
   */
 
400
  static native Constructor getEnclosingConstructor(Class klass);
 
401
 
 
402
  /**
 
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.
 
407
   *
 
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>
 
411
   *         is returned.
 
412
   * @since 1.5
 
413
   */
 
414
  static native Method getEnclosingMethod(Class klass);
 
415
 
 
416
  /**
 
417
   * Returns the class signature as specified in Class File Format
 
418
   * chapter in the VM specification, or null if the class is not
 
419
   * generic.
 
420
   *
 
421
   * @param klass the klass to test.
 
422
   * @return a ClassSignature string.
 
423
   * @since 1.5
 
424
   */
 
425
  static native String getClassSignature(Class klass);
 
426
 
 
427
  /**
 
428
   * Returns true if the specified class represents an anonymous class.
 
429
   *
 
430
   * @param klass the klass to test.
 
431
   * @return true if the specified class represents an anonymous class.
 
432
   * @since 1.5
 
433
   */
 
434
  static native boolean isAnonymousClass(Class klass);
 
435
 
 
436
  /**
 
437
   * Returns true if the specified class represents an local class.
 
438
   *
 
439
   * @param klass the klass to test.
 
440
   * @return true if the specified class represents an local class.
 
441
   * @since 1.5
 
442
   */
 
443
  static native boolean isLocalClass(Class klass);
 
444
 
 
445
  /**
 
446
   * Returns true if the specified class represents an member class.
 
447
   *
 
448
   * @param klass the klass to test. 
 
449
   * @return true if the specified class represents an member class.
 
450
   * @since 1.5
 
451
   */
 
452
  static native boolean isMemberClass(Class klass);
 
453
 
279
454
} // class VMClass