jamvm

view lib/java/lang/reflect/Field.java @ 395:387051b26a50

Make compatible with changes in GNU Classpath (CVS).
author rlougher
date Wed Jun 04 02:46:32 2008 +0100 (2008-06-04)
parents 768ab36fd30e
children
line source
1 /* java.lang.reflect.Field - reflection of Java fields
2 Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
38 /*
39 Robert Lougher 17/11/2003.
40 This Classpath reference implementation has been modified to work with JamVM.
41 */
44 package java.lang.reflect;
46 import gnu.java.lang.ClassHelper;
47 import gnu.java.lang.CPStringBuilder;
49 import gnu.java.lang.reflect.FieldSignatureParser;
50 import java.lang.annotation.Annotation;
52 /**
53 * The Field class represents a member variable of a class. It also allows
54 * dynamic access to a member, via reflection. This works for both
55 * static and instance fields. Operations on Field objects know how to
56 * do widening conversions, but throw {@link IllegalArgumentException} if
57 * a narrowing conversion would be necessary. You can query for information
58 * on this Field regardless of location, but get and set access may be limited
59 * by Java language access controls. If you can't do it in the compiler, you
60 * can't normally do it here either.<p>
61 *
62 * <B>Note:</B> This class returns and accepts types as Classes, even
63 * primitive types; there are Class types defined that represent each
64 * different primitive type. They are <code>java.lang.Boolean.TYPE,
65 * java.lang.Byte.TYPE,</code>, also available as <code>boolean.class,
66 * byte.class</code>, etc. These are not to be confused with the
67 * classes <code>java.lang.Boolean, java.lang.Byte</code>, etc., which are
68 * real classes.<p>
69 *
70 * Also note that this is not a serializable class. It is entirely feasible
71 * to make it serializable using the Externalizable interface, but this is
72 * on Sun, not me.
73 *
74 * @author John Keiser
75 * @author Eric Blake <ebb9@email.byu.edu>
76 * @see Member
77 * @see Class
78 * @see Class#getField(String)
79 * @see Class#getDeclaredField(String)
80 * @see Class#getFields()
81 * @see Class#getDeclaredFields()
82 * @since 1.1
83 * @status updated to 1.4
84 */
85 public final class Field
86 extends AccessibleObject implements Member
87 {
88 private Class declaringClass;
89 private Class type;
90 private String name;
91 private int slot;
93 /**
94 * This class is uninstantiable except natively.
95 */
96 private Field(Class declaringClass, Class type, String name, int slot)
97 {
98 this.declaringClass = declaringClass;
99 this.type = type;
100 this.name = name;
101 this.slot = slot;
102 }
104 /**
105 * Gets the class that declared this field, or the class where this field
106 * is a non-inherited member.
107 * @return the class that declared this member
108 */
109 public Class getDeclaringClass()
110 {
111 return declaringClass;
112 }
114 /**
115 * Gets the name of this field.
116 * @return the name of this field
117 */
118 public String getName()
119 {
120 return name;
121 }
123 /**
124 * Gets the modifiers this field uses. Use the <code>Modifier</code>
125 * class to interpret the values. A field can only have a subset of the
126 * following modifiers: public, private, protected, static, final,
127 * transient, and volatile.
128 *
129 * @return an integer representing the modifiers to this Member
130 * @see Modifier
131 */
132 public int getModifiers()
133 {
134 return getFieldModifiers(declaringClass, slot);
135 }
137 /**
138 * Return true if this field is synthetic, false otherwise.
139 * @since 1.5
140 */
141 public boolean isSynthetic()
142 {
143 return (getFieldModifiers(declaringClass, slot) & Modifier.SYNTHETIC) != 0;
144 }
146 /**
147 * Return true if this field represents an enum constant,
148 * false otherwise.
149 * @since 1.5
150 */
151 public boolean isEnumConstant()
152 {
153 return (getFieldModifiers(declaringClass, slot) & Modifier.ENUM) != 0;
154 }
156 /**
157 * Gets the type of this field.
158 * @return the type of this field
159 */
160 public Class getType() {
161 return type;
162 }
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 if (!(o instanceof Field))
176 return false;
177 Field that = (Field)o;
178 if (this.getDeclaringClass() != that.getDeclaringClass())
179 return false;
180 if (!this.getName().equals(that.getName()))
181 return false;
182 if (this.getType() != that.getType())
183 return false;
184 return true;
185 }
187 /**
188 * Get the hash code for the Field. The Field hash code is the hash code
189 * of its name XOR'd with the hash code of its class name.
190 *
191 * @return the hash code for the object.
192 */
193 public int hashCode()
194 {
195 return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
196 }
198 /**
199 * Get a String representation of the Field. A Field's String
200 * representation is "&lt;modifiers&gt; &lt;type&gt;
201 * &lt;class&gt;.&lt;fieldname&gt;".<br> Example:
202 * <code>public transient boolean gnu.parse.Parser.parseComplete</code>
203 *
204 * @return the String representation of the Field
205 */
206 public String toString()
207 {
208 // 64 is a reasonable buffer initial size for field
209 CPStringBuilder sb = new CPStringBuilder(64);
210 Modifier.toString(getModifiers(), sb).append(' ');
211 sb.append(ClassHelper.getUserName(getType())).append(' ');
212 sb.append(getDeclaringClass().getName()).append('.');
213 sb.append(getName());
214 return sb.toString();
215 }
217 public String toGenericString()
218 {
219 CPStringBuilder sb = new CPStringBuilder(64);
220 Modifier.toString(getModifiers(), sb).append(' ');
221 sb.append(getGenericType()).append(' ');
222 sb.append(getDeclaringClass().getName()).append('.');
223 sb.append(getName());
224 return sb.toString();
225 }
227 /**
228 * Get the value of this Field. If it is primitive, it will be wrapped
229 * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
230 *
231 * If the field is static, <code>o</code> will be ignored. Otherwise, if
232 * <code>o</code> is null, you get a <code>NullPointerException</code>,
233 * and if it is incompatible with the declaring class of the field, you
234 * get an <code>IllegalArgumentException</code>.<p>
235 *
236 * Next, if this Field enforces access control, your runtime context is
237 * evaluated, and you may have an <code>IllegalAccessException</code> if
238 * you could not access this field in similar compiled code. If the field
239 * is static, and its class is uninitialized, you trigger class
240 * initialization, which may end in a
241 * <code>ExceptionInInitializerError</code>.<p>
242 *
243 * Finally, the field is accessed, and primitives are wrapped (but not
244 * necessarily in new objects). This method accesses the field of the
245 * declaring class, even if the instance passed in belongs to a subclass
246 * which declares another field to hide this one.
247 *
248 * @param o the object to get the value of this Field from
249 * @return the value of the Field
250 * @throws IllegalAccessException if you could not normally access this field
251 * (i.e. it is not public)
252 * @throws IllegalArgumentException if <code>o</code> is not an instance of
253 * the class or interface declaring this field
254 * @throws NullPointerException if <code>o</code> is null and this field
255 * requires an instance
256 * @throws ExceptionInInitializerError if accessing a static field triggered
257 * class initialization, which then failed
258 * @see #getBoolean(Object)
259 * @see #getByte(Object)
260 * @see #getChar(Object)
261 * @see #getShort(Object)
262 * @see #getInt(Object)
263 * @see #getLong(Object)
264 * @see #getFloat(Object)
265 * @see #getDouble(Object)
266 */
267 public Object get(Object o) throws IllegalAccessException {
268 return getField(o, declaringClass, type, slot, flag);
269 }
271 /**
272 * Get the value of this boolean Field. If the field is static,
273 * <code>o</code> will be ignored.
274 *
275 * @param o the object to get the value of this Field from
276 * @return the value of the Field
277 * @throws IllegalAccessException if you could not normally access this field
278 * (i.e. it is not public)
279 * @throws IllegalArgumentException if this is not a boolean field of
280 * <code>o</code>, or if <code>o</code> is not an instance of the
281 * declaring class of this field
282 * @throws NullPointerException if <code>o</code> is null and this field
283 * requires an instance
284 * @throws ExceptionInInitializerError if accessing a static field triggered
285 * class initialization, which then failed
286 * @see #get(Object)
287 */
288 public boolean getBoolean(Object o)
289 throws IllegalAccessException {
290 return getZField(o, declaringClass, type, slot, flag, 1);
291 }
293 /**
294 * Get the value of this byte Field. If the field is static,
295 * <code>o</code> will be ignored.
296 *
297 * @param o the object to get the value of this Field from
298 * @return the value of the Field
299 * @throws IllegalAccessException if you could not normally access this field
300 * (i.e. it is not public)
301 * @throws IllegalArgumentException if this is not a byte field of
302 * <code>o</code>, or if <code>o</code> is not an instance of the
303 * declaring class of this field
304 * @throws NullPointerException if <code>o</code> is null and this field
305 * requires an instance
306 * @throws ExceptionInInitializerError if accessing a static field triggered
307 * class initialization, which then failed
308 * @see #get(Object)
309 */
310 public byte getByte(Object o)
311 throws IllegalAccessException {
312 return getBField(o, declaringClass, type, slot, flag, 2);
313 }
315 /**
316 * Get the value of this Field as a char. If the field is static,
317 * <code>o</code> will be ignored.
318 *
319 * @throws IllegalAccessException if you could not normally access this field
320 * (i.e. it is not public)
321 * @throws IllegalArgumentException if this is not a char field of
322 * <code>o</code>, or if <code>o</code> is not an instance
323 * of the declaring class of this field
324 * @throws NullPointerException if <code>o</code> is null and this field
325 * requires an instance
326 * @throws ExceptionInInitializerError if accessing a static field triggered
327 * class initialization, which then failed
328 * @see #get(Object)
329 */
330 public char getChar(Object o)
331 throws IllegalAccessException {
332 return getCField(o, declaringClass, type, slot, flag, 3);
333 }
335 /**
336 * Get the value of this Field as a short. If the field is static,
337 * <code>o</code> will be ignored.
338 *
339 * @param o the object to get the value of this Field from
340 * @return the value of the Field
341 * @throws IllegalAccessException if you could not normally access this field
342 * (i.e. it is not public)
343 * @throws IllegalArgumentException if this is not a byte or short
344 * field of <code>o</code>, or if <code>o</code> is not an instance
345 * of the declaring class of this field
346 * @throws NullPointerException if <code>o</code> is null and this field
347 * requires an instance
348 * @throws ExceptionInInitializerError if accessing a static field triggered
349 * class initialization, which then failed
350 * @see #get(Object)
351 */
352 public short getShort(Object o)
353 throws IllegalAccessException {
354 return getSField(o, declaringClass, type, slot, flag, 4);
355 }
357 /**
358 * Get the value of this Field as an int. If the field is static,
359 * <code>o</code> will be ignored.
360 *
361 * @param o the object to get the value of this Field from
362 * @return the value of the Field
363 * @throws IllegalAccessException if you could not normally access this field
364 * (i.e. it is not public)
365 * @throws IllegalArgumentException if this is not a byte, short, char, or
366 * int field of <code>o</code>, or if <code>o</code> is not an
367 * instance of the declaring class of this field
368 * @throws NullPointerException if <code>o</code> is null and this field
369 * requires an instance
370 * @throws ExceptionInInitializerError if accessing a static field triggered
371 * class initialization, which then failed
372 * @see #get(Object)
373 */
374 public int getInt(Object o)
375 throws IllegalAccessException {
376 return getIField(o, declaringClass, type, slot, flag, 5);
377 }
379 /**
380 * Get the value of this Field as a long. If the field is static,
381 * <code>o</code> will be ignored.
382 *
383 * @param o the object to get the value of this Field from
384 * @return the value of the Field
385 * @throws IllegalAccessException if you could not normally access this field
386 * (i.e. it is not public)
387 * @throws IllegalArgumentException if this is not a byte, short, char, int,
388 * or long field of <code>o</code>, or if <code>o</code> is not an
389 * instance of the declaring class of this field
390 * @throws NullPointerException if <code>o</code> is null and this field
391 * requires an instance
392 * @throws ExceptionInInitializerError if accessing a static field triggered
393 * class initialization, which then failed
394 * @see #get(Object)
395 */
396 public long getLong(Object o)
397 throws IllegalAccessException {
398 return getJField(o, declaringClass, type, slot, flag, 7);
399 }
401 /**
402 * Get the value of this Field as a float. If the field is static,
403 * <code>o</code> will be ignored.
404 *
405 * @param o the object to get the value of this Field from
406 * @return the value of the Field
407 * @throws IllegalAccessException if you could not normally access this field
408 * (i.e. it is not public)
409 * @throws IllegalArgumentException if this is not a byte, short, char, int,
410 * long, or float field of <code>o</code>, or if <code>o</code> is
411 * not an instance of the declaring class of this field
412 * @throws NullPointerException if <code>o</code> is null and this field
413 * requires an instance
414 * @throws ExceptionInInitializerError if accessing a static field triggered
415 * class initialization, which then failed
416 * @see #get(Object)
417 */
418 public float getFloat(Object o)
419 throws IllegalAccessException {
420 return getFField(o, declaringClass, type, slot, flag, 6);
421 }
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 return getDField(o, declaringClass, type, slot, flag, 8);
444 }
446 /**
447 * Set the value of this Field. If it is a primitive field, the value
448 * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p>
449 *
450 * If the field is static, <code>o</code> will be ignored. Otherwise, if
451 * <code>o</code> is null, you get a <code>NullPointerException</code>,
452 * and if it is incompatible with the declaring class of the field, you
453 * get an <code>IllegalArgumentException</code>.<p>
454 *
455 * Next, if this Field enforces access control, your runtime context is
456 * evaluated, and you may have an <code>IllegalAccessException</code> if
457 * you could not access this field in similar compiled code. This also
458 * occurs whether or not there is access control if the field is final.
459 * If the field is primitive, and unwrapping your argument fails, you will
460 * get an <code>IllegalArgumentException</code>; likewise, this error
461 * happens if <code>value</code> cannot be cast to the correct object type.
462 * If the field is static, and its class is uninitialized, you trigger class
463 * initialization, which may end in a
464 * <code>ExceptionInInitializerError</code>.<p>
465 *
466 * Finally, the field is set with the widened value. This method accesses
467 * the field of the declaring class, even if the instance passed in belongs
468 * to a subclass which declares another field to hide this one.
469 *
470 * @param o the object to set this Field on
471 * @param value the value to set this Field to
472 * @throws IllegalAccessException if you could not normally access this field
473 * (i.e. it is not public)
474 * @throws IllegalArgumentException if <code>value</code> cannot be
475 * converted by a widening conversion to the underlying type of
476 * the Field, or if <code>o</code> is not an instance of the class
477 * declaring this field
478 * @throws NullPointerException if <code>o</code> is null and this field
479 * requires an instance
480 * @throws ExceptionInInitializerError if accessing a static field triggered
481 * class initialization, which then failed
482 * @see #setBoolean(Object, boolean)
483 * @see #setByte(Object, byte)
484 * @see #setChar(Object, char)
485 * @see #setShort(Object, short)
486 * @see #setInt(Object, int)
487 * @see #setLong(Object, long)
488 * @see #setFloat(Object, float)
489 * @see #setDouble(Object, double)
490 */
491 public void set(Object o, Object value) throws IllegalAccessException {
492 setField(o, declaringClass, type, slot, flag, value);
493 }
495 /**
496 * Set this boolean Field. If the field is static, <code>o</code> will be
497 * ignored.
498 *
499 * @param o the object to set this Field on
500 * @param value the value to set this Field to
501 * @throws IllegalAccessException if you could not normally access this field
502 * (i.e. it is not public)
503 * @throws IllegalArgumentException if this is not a boolean field, or if
504 * <code>o</code> is not an instance of the class declaring this
505 * field
506 * @throws NullPointerException if <code>o</code> is null and this field
507 * requires an instance
508 * @throws ExceptionInInitializerError if accessing a static field triggered
509 * class initialization, which then failed
510 * @see #set(Object, Object)
511 */
512 public void setBoolean(Object o, boolean value) throws IllegalAccessException {
513 setZField(o, declaringClass, type, slot, flag, 1, value);
514 }
516 /**
517 * Set this byte Field. If the field is static, <code>o</code> will be
518 * ignored.
519 *
520 * @param o the object to set this Field on
521 * @param value the value to set this Field to
522 * @throws IllegalAccessException if you could not normally access this field
523 * (i.e. it is not public)
524 * @throws IllegalArgumentException if this is not a byte, short, int, long,
525 * float, or double field, or if <code>o</code> is not an instance
526 * of the class declaring this field
527 * @throws NullPointerException if <code>o</code> is null and this field
528 * requires an instance
529 * @throws ExceptionInInitializerError if accessing a static field triggered
530 * class initialization, which then failed
531 * @see #set(Object, Object)
532 */
533 public void setByte(Object o, byte value) throws IllegalAccessException {
534 setBField(o, declaringClass, type, slot, flag, 2, value);
535 }
537 /**
538 * Set this char Field. If the field is static, <code>o</code> will be
539 * ignored.
540 *
541 * @param o the object to set this Field on
542 * @param value the value to set this Field to
543 * @throws IllegalAccessException if you could not normally access this field
544 * (i.e. it is not public)
545 * @throws IllegalArgumentException if this is not a char, int, long,
546 * float, or double field, or if <code>o</code> is not an instance
547 * of the class declaring this field
548 * @throws NullPointerException if <code>o</code> is null and this field
549 * requires an instance
550 * @throws ExceptionInInitializerError if accessing a static field triggered
551 * class initialization, which then failed
552 * @see #set(Object, Object)
553 */
554 public void setChar(Object o, char value) throws IllegalAccessException {
555 setCField(o, declaringClass, type, slot, flag, 3, value);
556 }
558 /**
559 * Set this short Field. If the field is static, <code>o</code> will be
560 * ignored.
561 *
562 * @param o the object to set this Field on
563 * @param value the value to set this Field to
564 * @throws IllegalAccessException if you could not normally access this field
565 * (i.e. it is not public)
566 * @throws IllegalArgumentException if this is not a short, int, long,
567 * float, or double field, or if <code>o</code> is not an instance
568 * of the class declaring this field
569 * @throws NullPointerException if <code>o</code> is null and this field
570 * requires an instance
571 * @throws ExceptionInInitializerError if accessing a static field triggered
572 * class initialization, which then failed
573 * @see #set(Object, Object)
574 */
575 public void setShort(Object o, short value) throws IllegalAccessException {
576 setSField(o, declaringClass, type, slot, flag, 4, value);
577 }
579 /**
580 * Set this int Field. If the field is static, <code>o</code> will be
581 * ignored.
582 *
583 * @param o the object to set this Field on
584 * @param value the value to set this Field to
585 * @throws IllegalAccessException if you could not normally access this field
586 * (i.e. it is not public)
587 * @throws IllegalArgumentException if this is not an int, long, float, or
588 * double field, or if <code>o</code> is not an instance of the
589 * class declaring this field
590 * @throws NullPointerException if <code>o</code> is null and this field
591 * requires an instance
592 * @throws ExceptionInInitializerError if accessing a static field triggered
593 * class initialization, which then failed
594 * @see #set(Object, Object)
595 */
596 public void setInt(Object o, int value) throws IllegalAccessException {
597 setIField(o, declaringClass, type, slot, flag, 5, value);
598 }
600 /**
601 * Set this long Field. If the field is static, <code>o</code> will be
602 * ignored.
603 *
604 * @param o the object to set this Field on
605 * @param value the value to set this Field to
606 * @throws IllegalAccessException if you could not normally access this field
607 * (i.e. it is not public)
608 * @throws IllegalArgumentException if this is not a long, float, or double
609 * field, or if <code>o</code> is not an instance of the class
610 * declaring this field
611 * @throws NullPointerException if <code>o</code> is null and this field
612 * requires an instance
613 * @throws ExceptionInInitializerError if accessing a static field triggered
614 * class initialization, which then failed
615 * @see #set(Object, Object)
616 */
617 public void setLong(Object o, long value) throws IllegalAccessException {
618 setJField(o, declaringClass, type, slot, flag, 7, value);
619 }
621 /**
622 * Set this float Field. If the field is static, <code>o</code> will be
623 * ignored.
624 *
625 * @param o the object to set this Field on
626 * @param value the value to set this Field to
627 * @throws IllegalAccessException if you could not normally access this field
628 * (i.e. it is not public)
629 * @throws IllegalArgumentException if this is not a float or long field, or
630 * if <code>o</code> is not an instance of the class declaring this
631 * field
632 * @throws NullPointerException if <code>o</code> is null and this field
633 * requires an instance
634 * @throws ExceptionInInitializerError if accessing a static field triggered
635 * class initialization, which then failed
636 * @see #set(Object, Object)
637 */
638 public void setFloat(Object o, float value) throws IllegalAccessException {
639 setFField(o, declaringClass, type, slot, flag, 6, value);
640 }
642 /**
643 * Set this double Field. If the field is static, <code>o</code> will be
644 * ignored.
645 *
646 * @param o the object to set this Field on
647 * @param value the value to set this Field to
648 * @throws IllegalAccessException if you could not normally access this field
649 * (i.e. it is not public)
650 * @throws IllegalArgumentException if this is not a double field, or if
651 * <code>o</code> is not an instance of the class declaring this
652 * field
653 * @throws NullPointerException if <code>o</code> is null and this field
654 * requires an instance
655 * @throws ExceptionInInitializerError if accessing a static field triggered
656 * class initialization, which then failed
657 * @see #set(Object, Object)
658 */
659 public void setDouble(Object o, double value) throws IllegalAccessException {
660 setDField(o, declaringClass, type, slot, flag, 8, value);
661 }
663 /**
664 * Return the generic type of the field. If the field type is not a generic
665 * type, the method returns the same as <code>getType()</code>.
666 *
667 * @throws GenericSignatureFormatError if the generic signature does
668 * not conform to the format specified in the Virtual Machine
669 * specification, version 3.
670 * @since 1.5
671 */
672 public Type getGenericType()
673 {
674 String signature = getSignature(declaringClass, slot);
675 if (signature == null)
676 return getType();
677 FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(),
678 signature);
679 return p.getFieldType();
680 }
682 public Annotation getAnnotation(Class annoClass)
683 {
684 Annotation[] annos = getDeclaredAnnotations();
685 for (int i = 0; i < annos.length; i++)
686 if (annos[i].annotationType() == annoClass)
687 return annos[i];
688 return null;
689 }
691 public Annotation[] getDeclaredAnnotations()
692 {
693 return getDeclaredAnnotationsNative(declaringClass, slot);
694 }
696 /**
697 * Return the raw modifiers for this field.
698 * @return the field's modifiers
699 */
700 public native int getFieldModifiers(Class declaringClass, int slot);
702 /**
703 * Return the String in the Signature attribute for this field. If there
704 * is no Signature attribute, return null.
705 */
706 private native String getSignature(Class declaringClass, int slot);
708 private native Annotation[] getDeclaredAnnotationsNative(Class declaringClass, int slot);
710 private native void setField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, Object value)
711 throws IllegalAccessException;
712 private native double getDField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
713 private native int getIField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
714 private native long getJField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
715 private native boolean getZField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
716 private native float getFField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
717 private native char getCField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
718 private native short getSField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
719 private native byte getBField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no);
721 private native Object getField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck)
722 throws IllegalAccessException;
723 private native void setDField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, double v);
724 private native void setIField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, int i);
725 private native void setJField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, long j);
726 private native void setZField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, boolean z);
727 private native void setFField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, float f);
728 private native void setCField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, char c);
729 private native void setSField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, short s);
730 private native void setBField(Object o, Class declaringClass, Class type, int slot, boolean noAccessCheck, int type_no, byte b);
731 }