* Merged with tip.
[cacao.git] / src / classes / gnu / java / lang / reflect / Field.java
1 /* java.lang.reflect.Field - reflection of Java fields
2    Copyright (C) 1998, 2001, 2005, 2008 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38
39 package java.lang.reflect;
40
41 import gnu.java.lang.ClassHelper;
42 import gnu.java.lang.CPStringBuilder;
43
44 import gnu.java.lang.reflect.FieldSignatureParser;
45
46 import java.lang.annotation.Annotation;
47
48 /**
49  * The Field class represents a member variable of a class. It also allows
50  * dynamic access to a member, via reflection. This works for both
51  * static and instance fields. Operations on Field objects know how to
52  * do widening conversions, but throw {@link IllegalArgumentException} if
53  * a narrowing conversion would be necessary. You can query for information
54  * on this Field regardless of location, but get and set access may be limited
55  * by Java language access controls. If you can't do it in the compiler, you
56  * can't normally do it here either.<p>
57  *
58  * <B>Note:</B> This class returns and accepts types as Classes, even
59  * primitive types; there are Class types defined that represent each
60  * different primitive type.  They are <code>java.lang.Boolean.TYPE,
61  * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
62  * byte.class</code>, etc.  These are not to be confused with the
63  * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
64  * real classes.<p>
65  *
66  * Also note that this is not a serializable class.  It is entirely feasible
67  * to make it serializable using the Externalizable interface, but this is
68  * on Sun, not me.
69  *
70  * @author John Keiser
71  * @author Eric Blake <ebb9@email.byu.edu>
72  * @see Member
73  * @see Class
74  * @see Class#getField(String)
75  * @see Class#getDeclaredField(String)
76  * @see Class#getFields()
77  * @see Class#getDeclaredFields()
78  * @since 1.1
79  * @status updated to 1.4
80  */
81 public final class Field
82 extends AccessibleObject implements Member
83 {
84   static final int FIELD_MODIFIERS
85     = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
86       | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
87       | Modifier.VOLATILE;
88
89   private FieldSignatureParser p;
90
91   VMField f;
92
93   /**
94    * This class is uninstantiable outside the package.
95    */
96   Field(VMField f)
97   {
98     this.f = f;
99     f.f = this;
100   }
101
102   /**
103    * Gets the class that declared this field, or the class where this field
104    * is a non-inherited member.
105    * @return the class that declared this member
106    */
107   @SuppressWarnings("unchecked")
108   public Class<?> getDeclaringClass()
109   {
110     return (Class<?>) f.getDeclaringClass();
111   }
112
113   /**
114    * Gets the name of this field.
115    * @return the name of this field
116    */
117   public String getName()
118   {
119     return f.getName();
120   }
121
122   /**
123    * Gets the modifiers this field uses.  Use the <code>Modifier</code>
124    * class to interpret the values.  A field can only have a subset of the
125    * following modifiers: public, private, protected, static, final,
126    * transient, and volatile.
127    *
128    * @return an integer representing the modifiers to this Member
129    * @see Modifier
130    */
131   public int getModifiers()
132   {
133     return f.getModifiersInternal() & FIELD_MODIFIERS;
134   }
135
136   /**
137    * Return true if this field is synthetic, false otherwise.
138    * @since 1.5
139    */
140   public boolean isSynthetic()
141   {
142     return (f.getModifiersInternal() & Modifier.SYNTHETIC) != 0;
143   }
144
145   /**
146    * Return true if this field represents an enum constant,
147    * false otherwise.
148    * @since 1.5
149    */
150   public boolean isEnumConstant()
151   {
152     return (f.getModifiersInternal() & Modifier.ENUM) != 0;
153   }
154
155   /**
156    * Gets the type of this field.
157    * @return the type of this field
158    */
159   public Class<?> getType()
160   {
161     return f.getType();
162   }
163
164   /**
165    * Compare two objects to see if they are semantically equivalent.
166    * Two Fields are semantically equivalent if they have the same declaring
167    * class, name, and type. Since you can't creat a Field except through
168    * the VM, this is just the == relation.
169    *
170    * @param o the object to compare to
171    * @return <code>true</code> if they are equal; <code>false</code> if not
172    */
173   public boolean equals(Object o)
174   {
175     return f.equals(o);
176   }
177
178   /**
179    * Get the hash code for the Field. The Field hash code is the hash code
180    * of its name XOR'd with the hash code of its class name.
181    *
182    * @return the hash code for the object.
183    */
184   public int hashCode()
185   {
186     return f.getDeclaringClass().getName().hashCode() ^ f.getName().hashCode();
187   }
188
189   /**
190    * Get a String representation of the Field. A Field's String
191    * representation is "&lt;modifiers&gt; &lt;type&gt;
192    * &lt;class&gt;.&lt;fieldname&gt;".<br> Example:
193    * <code>public transient boolean gnu.parse.Parser.parseComplete</code>
194    *
195    * @return the String representation of the Field
196    */
197   public String toString()
198   {
199     // 64 is a reasonable buffer initial size for field
200     CPStringBuilder sb = new CPStringBuilder(64);
201     Modifier.toString(getModifiers(), sb).append(' ');
202     sb.append(ClassHelper.getUserName(getType())).append(' ');
203     sb.append(getDeclaringClass().getName()).append('.');
204     sb.append(getName());
205     return sb.toString();
206   }
207
208   public String toGenericString()
209   {
210     CPStringBuilder sb = new CPStringBuilder(64);
211     Modifier.toString(getModifiers(), sb).append(' ');
212     sb.append(getGenericType()).append(' ');
213     sb.append(getDeclaringClass().getName()).append('.');
214     sb.append(getName());
215     return sb.toString();
216   }
217
218   /**
219    * Get the value of this Field.  If it is primitive, it will be wrapped
220    * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
221    *
222    * If the field is static, <code>o</code> will be ignored. Otherwise, if
223    * <code>o</code> is null, you get a <code>NullPointerException</code>,
224    * and if it is incompatible with the declaring class of the field, you
225    * get an <code>IllegalArgumentException</code>.<p>
226    *
227    * Next, if this Field enforces access control, your runtime context is
228    * evaluated, and you may have an <code>IllegalAccessException</code> if
229    * you could not access this field in similar compiled code. If the field
230    * is static, and its class is uninitialized, you trigger class
231    * initialization, which may end in a
232    * <code>ExceptionInInitializerError</code>.<p>
233    *
234    * Finally, the field is accessed, and primitives are wrapped (but not
235    * necessarily in new objects). This method accesses the field of the
236    * declaring class, even if the instance passed in belongs to a subclass
237    * which declares another field to hide this one.
238    *
239    * @param o the object to get the value of this Field from
240    * @return the value of the Field
241    * @throws IllegalAccessException if you could not normally access this field
242    *         (i.e. it is not public)
243    * @throws IllegalArgumentException if <code>o</code> is not an instance of
244    *         the class or interface declaring this field
245    * @throws NullPointerException if <code>o</code> is null and this field
246    *         requires an instance
247    * @throws ExceptionInInitializerError if accessing a static field triggered
248    *         class initialization, which then failed
249    * @see #getBoolean(Object)
250    * @see #getByte(Object)
251    * @see #getChar(Object)
252    * @see #getShort(Object)
253    * @see #getInt(Object)
254    * @see #getLong(Object)
255    * @see #getFloat(Object)
256    * @see #getDouble(Object)
257    */
258   public Object get(Object o)
259     throws IllegalAccessException
260   {
261     return f.get(o);
262   }
263
264   /**
265    * Get the value of this boolean Field. If the field is static,
266    * <code>o</code> will be ignored.
267    *
268    * @param o the object to get the value of this Field from
269    * @return the value of the Field
270    * @throws IllegalAccessException if you could not normally access this field
271    *         (i.e. it is not public)
272    * @throws IllegalArgumentException if this is not a boolean field of
273    *         <code>o</code>, or if <code>o</code> is not an instance of the
274    *         declaring class of this field
275    * @throws NullPointerException if <code>o</code> is null and this field
276    *         requires an instance
277    * @throws ExceptionInInitializerError if accessing a static field triggered
278    *         class initialization, which then failed
279    * @see #get(Object)
280    */
281   public boolean getBoolean(Object o)
282     throws IllegalAccessException
283   {
284     return f.getBoolean(o);
285   }
286
287   /**
288    * Get the value of this byte Field. If the field is static,
289    * <code>o</code> will be ignored.
290    *
291    * @param o the object to get the value of this Field from
292    * @return the value of the Field
293    * @throws IllegalAccessException if you could not normally access this field
294    *         (i.e. it is not public)
295    * @throws IllegalArgumentException if this is not a byte field of
296    *         <code>o</code>, or if <code>o</code> is not an instance of the
297    *         declaring class of this field
298    * @throws NullPointerException if <code>o</code> is null and this field
299    *         requires an instance
300    * @throws ExceptionInInitializerError if accessing a static field triggered
301    *         class initialization, which then failed
302    * @see #get(Object)
303    */
304   public byte getByte(Object o)
305     throws IllegalAccessException
306   {
307     return f.getByte(o);
308   }
309
310   /**
311    * Get the value of this Field as a char. If the field is static,
312    * <code>o</code> will be ignored.
313    *
314    * @throws IllegalAccessException if you could not normally access this field
315    *         (i.e. it is not public)
316    * @throws IllegalArgumentException if this is not a char field of
317    *         <code>o</code>, or if <code>o</code> is not an instance
318    *         of the declaring class of this field
319    * @throws NullPointerException if <code>o</code> is null and this field
320    *         requires an instance
321    * @throws ExceptionInInitializerError if accessing a static field triggered
322    *         class initialization, which then failed
323    * @see #get(Object)
324    */
325   public char getChar(Object o)
326     throws IllegalAccessException
327   {
328     return f.getChar(o);
329   }
330
331   /**
332    * Get the value of this Field as a short. If the field is static,
333    * <code>o</code> will be ignored.
334    *
335    * @param o the object to get the value of this Field from
336    * @return the value of the Field
337    * @throws IllegalAccessException if you could not normally access this field
338    *         (i.e. it is not public)
339    * @throws IllegalArgumentException if this is not a byte or short
340    *         field of <code>o</code>, or if <code>o</code> is not an instance
341    *         of the declaring class of this field
342    * @throws NullPointerException if <code>o</code> is null and this field
343    *         requires an instance
344    * @throws ExceptionInInitializerError if accessing a static field triggered
345    *         class initialization, which then failed
346    * @see #get(Object)
347    */
348   public short getShort(Object o)
349     throws IllegalAccessException
350   {
351     return f.getShort(o);
352   }
353
354   /**
355    * Get the value of this Field as an int. If the field is static,
356    * <code>o</code> will be ignored.
357    *
358    * @param o the object to get the value of this Field from
359    * @return the value of the Field
360    * @throws IllegalAccessException if you could not normally access this field
361    *         (i.e. it is not public)
362    * @throws IllegalArgumentException if this is not a byte, short, char, or
363    *         int field of <code>o</code>, or if <code>o</code> is not an
364    *         instance of the declaring class of this field
365    * @throws NullPointerException if <code>o</code> is null and this field
366    *         requires an instance
367    * @throws ExceptionInInitializerError if accessing a static field triggered
368    *         class initialization, which then failed
369    * @see #get(Object)
370    */
371   public int getInt(Object o)
372     throws IllegalAccessException
373   {
374     return f.getInt(o);
375   }
376
377   /**
378    * Get the value of this Field as a long. If the field is static,
379    * <code>o</code> will be ignored.
380    *
381    * @param o the object to get the value of this Field from
382    * @return the value of the Field
383    * @throws IllegalAccessException if you could not normally access this field
384    *         (i.e. it is not public)
385    * @throws IllegalArgumentException if this is not a byte, short, char, int,
386    *         or long field of <code>o</code>, or if <code>o</code> is not an
387    *         instance of the declaring class of this field
388    * @throws NullPointerException if <code>o</code> is null and this field
389    *         requires an instance
390    * @throws ExceptionInInitializerError if accessing a static field triggered
391    *         class initialization, which then failed
392    * @see #get(Object)
393    */
394   public long getLong(Object o)
395     throws IllegalAccessException
396   {
397     return f.getLong(o);
398   }
399
400   /**
401    * Get the value of this Field as a float. If the field is static,
402    * <code>o</code> will be ignored.
403    *
404    * @param o the object to get the value of this Field from
405    * @return the value of the Field
406    * @throws IllegalAccessException if you could not normally access this field
407    *         (i.e. it is not public)
408    * @throws IllegalArgumentException if this is not a byte, short, char, int,
409    *         long, or float field of <code>o</code>, or if <code>o</code> is
410    *         not an instance of the declaring class of this field
411    * @throws NullPointerException if <code>o</code> is null and this field
412    *         requires an instance
413    * @throws ExceptionInInitializerError if accessing a static field triggered
414    *         class initialization, which then failed
415    * @see #get(Object)
416    */
417   public float getFloat(Object o)
418     throws IllegalAccessException
419   {
420     return f.getFloat(o);
421   }
422
423   /**
424    * Get the value of this Field as a double. If the field is static,
425    * <code>o</code> will be ignored.
426    *
427    * @param o the object to get the value of this Field from
428    * @return the value of the Field
429    * @throws IllegalAccessException if you could not normally access this field
430    *         (i.e. it is not public)
431    * @throws IllegalArgumentException if this is not a byte, short, char, int,
432    *         long, float, or double field of <code>o</code>, or if
433    *         <code>o</code> is not an instance of the declaring class of this
434    *         field
435    * @throws NullPointerException if <code>o</code> is null and this field
436    *         requires an instance
437    * @throws ExceptionInInitializerError if accessing a static field triggered
438    *         class initialization, which then failed
439    * @see #get(Object)
440    */
441   public double getDouble(Object o)
442     throws IllegalAccessException
443   {
444     return f.getDouble(o);
445   }
446
447   /**
448    * Set the value of this Field.  If it is a primitive field, the value
449    * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p>
450    *
451    * If the field is static, <code>o</code> will be ignored. Otherwise, if
452    * <code>o</code> is null, you get a <code>NullPointerException</code>,
453    * and if it is incompatible with the declaring class of the field, you
454    * get an <code>IllegalArgumentException</code>.<p>
455    *
456    * Next, if this Field enforces access control, your runtime context is
457    * evaluated, and you may have an <code>IllegalAccessException</code> if
458    * you could not access this field in similar compiled code. This also
459    * occurs whether or not there is access control if the field is final.
460    * If the field is primitive, and unwrapping your argument fails, you will
461    * get an <code>IllegalArgumentException</code>; likewise, this error
462    * happens if <code>value</code> cannot be cast to the correct object type.
463    * If the field is static, and its class is uninitialized, you trigger class
464    * initialization, which may end in a
465    * <code>ExceptionInInitializerError</code>.<p>
466    *
467    * Finally, the field is set with the widened value. This method accesses
468    * the field of the declaring class, even if the instance passed in belongs
469    * to a subclass which declares another field to hide this one.
470    *
471    * @param o the object to set this Field on
472    * @param value the value to set this Field to
473    * @throws IllegalAccessException if you could not normally access this field
474    *         (i.e. it is not public)
475    * @throws IllegalArgumentException if <code>value</code> cannot be
476    *         converted by a widening conversion to the underlying type of
477    *         the Field, or if <code>o</code> is not an instance of the class
478    *         declaring this field
479    * @throws NullPointerException if <code>o</code> is null and this field
480    *         requires an instance
481    * @throws ExceptionInInitializerError if accessing a static field triggered
482    *         class initialization, which then failed
483    * @see #setBoolean(Object, boolean)
484    * @see #setByte(Object, byte)
485    * @see #setChar(Object, char)
486    * @see #setShort(Object, short)
487    * @see #setInt(Object, int)
488    * @see #setLong(Object, long)
489    * @see #setFloat(Object, float)
490    * @see #setDouble(Object, double)
491    */
492   public void set(Object o, Object value)
493     throws IllegalAccessException
494   {
495     f.set(o, value);
496   }
497
498   /**
499    * Set this boolean Field. If the field is static, <code>o</code> will be
500    * ignored.
501    *
502    * @param o the object to set this Field on
503    * @param value the value to set this Field to
504    * @throws IllegalAccessException if you could not normally access this field
505    *         (i.e. it is not public)
506    * @throws IllegalArgumentException if this is not a boolean field, or if
507    *         <code>o</code> is not an instance of the class declaring this
508    *         field
509    * @throws NullPointerException if <code>o</code> is null and this field
510    *         requires an instance
511    * @throws ExceptionInInitializerError if accessing a static field triggered
512    *         class initialization, which then failed
513    * @see #set(Object, Object)
514    */
515   public void setBoolean(Object o, boolean value)
516     throws IllegalAccessException
517   {
518     f.setBoolean(o, value);
519   }
520
521   /**
522    * Set this byte Field. If the field is static, <code>o</code> will be
523    * ignored.
524    *
525    * @param o the object to set this Field on
526    * @param value the value to set this Field to
527    * @throws IllegalAccessException if you could not normally access this field
528    *         (i.e. it is not public)
529    * @throws IllegalArgumentException if this is not a byte, short, int, long,
530    *         float, or double field, or if <code>o</code> is not an instance
531    *         of the class declaring this field
532    * @throws NullPointerException if <code>o</code> is null and this field
533    *         requires an instance
534    * @throws ExceptionInInitializerError if accessing a static field triggered
535    *         class initialization, which then failed
536    * @see #set(Object, Object)
537    */
538   public void setByte(Object o, byte value)
539     throws IllegalAccessException
540   {
541     f.setByte(o, value);
542   }
543
544   /**
545    * Set this char Field. If the field is static, <code>o</code> will be
546    * ignored.
547    *
548    * @param o the object to set this Field on
549    * @param value the value to set this Field to
550    * @throws IllegalAccessException if you could not normally access this field
551    *         (i.e. it is not public)
552    * @throws IllegalArgumentException if this is not a char, int, long,
553    *         float, or double field, or if <code>o</code> is not an instance
554    *         of the class declaring this field
555    * @throws NullPointerException if <code>o</code> is null and this field
556    *         requires an instance
557    * @throws ExceptionInInitializerError if accessing a static field triggered
558    *         class initialization, which then failed
559    * @see #set(Object, Object)
560    */
561   public void setChar(Object o, char value)
562     throws IllegalAccessException
563   {
564     f.setChar(o, value);
565   }
566
567   /**
568    * Set this short Field. If the field is static, <code>o</code> will be
569    * ignored.
570    *
571    * @param o the object to set this Field on
572    * @param value the value to set this Field to
573    * @throws IllegalAccessException if you could not normally access this field
574    *         (i.e. it is not public)
575    * @throws IllegalArgumentException if this is not a short, int, long,
576    *         float, or double field, or if <code>o</code> is not an instance
577    *         of the class declaring this field
578    * @throws NullPointerException if <code>o</code> is null and this field
579    *         requires an instance
580    * @throws ExceptionInInitializerError if accessing a static field triggered
581    *         class initialization, which then failed
582    * @see #set(Object, Object)
583    */
584   public void setShort(Object o, short value)
585     throws IllegalAccessException
586   {
587     f.setShort(o, value);
588   }
589
590   /**
591    * Set this int Field. If the field is static, <code>o</code> will be
592    * ignored.
593    *
594    * @param o the object to set this Field on
595    * @param value the value to set this Field to
596    * @throws IllegalAccessException if you could not normally access this field
597    *         (i.e. it is not public)
598    * @throws IllegalArgumentException if this is not an int, long, float, or
599    *         double field, or if <code>o</code> is not an instance of the
600    *         class declaring this field
601    * @throws NullPointerException if <code>o</code> is null and this field
602    *         requires an instance
603    * @throws ExceptionInInitializerError if accessing a static field triggered
604    *         class initialization, which then failed
605    * @see #set(Object, Object)
606    */
607   public void setInt(Object o, int value)
608     throws IllegalAccessException
609   {
610     f.setInt(o, value);
611   }
612
613   /**
614    * Set this long Field. If the field is static, <code>o</code> will be
615    * ignored.
616    *
617    * @param o the object to set this Field on
618    * @param value the value to set this Field to
619    * @throws IllegalAccessException if you could not normally access this field
620    *         (i.e. it is not public)
621    * @throws IllegalArgumentException if this is not a long, float, or double
622    *         field, or if <code>o</code> is not an instance of the class
623    *         declaring this field
624    * @throws NullPointerException if <code>o</code> is null and this field
625    *         requires an instance
626    * @throws ExceptionInInitializerError if accessing a static field triggered
627    *         class initialization, which then failed
628    * @see #set(Object, Object)
629    */
630   public void setLong(Object o, long value)
631     throws IllegalAccessException
632   {
633     f.setLong(o, value);
634   }
635
636   /**
637    * Set this float Field. If the field is static, <code>o</code> will be
638    * ignored.
639    *
640    * @param o the object to set this Field on
641    * @param value the value to set this Field to
642    * @throws IllegalAccessException if you could not normally access this field
643    *         (i.e. it is not public)
644    * @throws IllegalArgumentException if this is not a float or long field, or
645    *         if <code>o</code> is not an instance of the class declaring this
646    *         field
647    * @throws NullPointerException if <code>o</code> is null and this field
648    *         requires an instance
649    * @throws ExceptionInInitializerError if accessing a static field triggered
650    *         class initialization, which then failed
651    * @see #set(Object, Object)
652    */
653   public void setFloat(Object o, float value)
654     throws IllegalAccessException
655   {
656     f.setFloat(o, value);
657   }
658
659   /**
660    * Set this double Field. If the field is static, <code>o</code> will be
661    * ignored.
662    *
663    * @param o the object to set this Field on
664    * @param value the value to set this Field to
665    * @throws IllegalAccessException if you could not normally access this field
666    *         (i.e. it is not public)
667    * @throws IllegalArgumentException if this is not a double field, or if
668    *         <code>o</code> is not an instance of the class declaring this
669    *         field
670    * @throws NullPointerException if <code>o</code> is null and this field
671    *         requires an instance
672    * @throws ExceptionInInitializerError if accessing a static field triggered
673    *         class initialization, which then failed
674    * @see #set(Object, Object)
675    */
676   public void setDouble(Object o, double value)
677     throws IllegalAccessException
678   {
679     f.setDouble(o, value);
680   }
681
682   /**
683    * Return the generic type of the field. If the field type is not a generic
684    * type, the method returns the same as <code>getType()</code>.
685    *
686    * @throws GenericSignatureFormatError if the generic signature does
687    *         not conform to the format specified in the Virtual Machine
688    *         specification, version 3.
689    * @since 1.5
690    */
691   public Type getGenericType()
692   {
693     if (p == null)
694       {
695         String signature = f.getSignature();
696         if (signature == null)
697           return getType();
698         p = new FieldSignatureParser(getDeclaringClass(),
699                                      signature);
700       }
701     return p.getFieldType();
702   }
703
704   /**
705    * Returns the element's annotation for the specified annotation type,
706    * or <code>null</code> if no such annotation exists.
707    *
708    * @param annotationClass the type of annotation to look for.
709    * @return this element's annotation for the specified type, or
710    *         <code>null</code> if no such annotation exists.
711    * @throws NullPointerException if the annotation class is <code>null</code>.
712    */
713   @SuppressWarnings("unchecked")
714   public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
715   {
716     return (T) f.getAnnotation(annotationClass);
717   }
718
719   /**
720    * Returns all annotations directly defined by the element.  If there are
721    * no annotations directly associated with the element, then a zero-length
722    * array will be returned.  The returned array may be modified by the client
723    * code, but this will have no effect on the annotation content of this
724    * class, and hence no effect on the return value of this method for
725    * future callers.
726    *
727    * @return the annotations directly defined by the element.
728    * @since 1.5
729    */
730   public Annotation[] getDeclaredAnnotations()
731   {
732     return f.getDeclaredAnnotations();
733   }
734
735 }