OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [vm/] [reference/] [java/] [lang/] [reflect/] [VMField.java] - Blame information for rev 780

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 780 jeremybenn
/* java.lang.reflect.Field - VM interface for 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 java.lang.annotation.Annotation;
42
 
43
final class VMField
44
{
45
  Class clazz;
46
  String name;
47
  int slot;
48
 
49
  /**
50
   * This field allows us to refer back to the main constructor instance.
51
   *  It is set by the constructor of Field.
52
   */
53
  Field f;
54
 
55
  VMField(Class clazz, String name, int slot)
56
  {
57
    this.clazz = clazz;
58
    this.name = name;
59
    this.slot = slot;
60
  }
61
 
62
  public Class getDeclaringClass()
63
  {
64
    return clazz;
65
  }
66
 
67
  public String getName()
68
  {
69
    return name;
70
  }
71
 
72
  /**
73
   * Return the raw modifiers for this field.
74
   * @return the field's modifiers
75
   */
76
  native int getModifiersInternal();
77
 
78
  /**
79
   * Gets the type of this field.
80
   * @return the type of this field
81
   */
82
  native Class getType();
83
 
84
  /**
85
   * Get the value of this Field.  If it is primitive, it will be wrapped
86
   * in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
87
   *
88
   * If the field is static, <code>o</code> will be ignored. Otherwise, if
89
   * <code>o</code> is null, you get a <code>NullPointerException</code>,
90
   * and if it is incompatible with the declaring class of the field, you
91
   * get an <code>IllegalArgumentException</code>.<p>
92
   *
93
   * Next, if this Field enforces access control, your runtime context is
94
   * evaluated, and you may have an <code>IllegalAccessException</code> if
95
   * you could not access this field in similar compiled code. If the field
96
   * is static, and its class is uninitialized, you trigger class
97
   * initialization, which may end in a
98
   * <code>ExceptionInInitializerError</code>.<p>
99
   *
100
   * Finally, the field is accessed, and primitives are wrapped (but not
101
   * necessarily in new objects). This method accesses the field of the
102
   * declaring class, even if the instance passed in belongs to a subclass
103
   * which declares another field to hide this one.
104
   *
105
   * @param o the object to get the value of this Field from
106
   * @return the value of the Field
107
   * @throws IllegalAccessException if you could not normally access this field
108
   *         (i.e. it is not public)
109
   * @throws IllegalArgumentException if <code>o</code> is not an instance of
110
   *         the class or interface declaring this field
111
   * @throws NullPointerException if <code>o</code> is null and this field
112
   *         requires an instance
113
   * @throws ExceptionInInitializerError if accessing a static field triggered
114
   *         class initialization, which then failed
115
   * @see #getBoolean(Object)
116
   * @see #getByte(Object)
117
   * @see #getChar(Object)
118
   * @see #getShort(Object)
119
   * @see #getInt(Object)
120
   * @see #getLong(Object)
121
   * @see #getFloat(Object)
122
   * @see #getDouble(Object)
123
   */
124
  native Object get(Object o)
125
    throws IllegalAccessException;
126
 
127
  /**
128
   * Get the value of this boolean Field. If the field is static,
129
   * <code>o</code> will be ignored.
130
   *
131
   * @param o the object to get the value of this Field from
132
   * @return the value of the Field
133
   * @throws IllegalAccessException if you could not normally access this field
134
   *         (i.e. it is not public)
135
   * @throws IllegalArgumentException if this is not a boolean field of
136
   *         <code>o</code>, or if <code>o</code> is not an instance of the
137
   *         declaring class of this field
138
   * @throws NullPointerException if <code>o</code> is null and this field
139
   *         requires an instance
140
   * @throws ExceptionInInitializerError if accessing a static field triggered
141
   *         class initialization, which then failed
142
   * @see #get(Object)
143
   */
144
  native boolean getBoolean(Object o)
145
    throws IllegalAccessException;
146
 
147
  /**
148
   * Get the value of this byte Field. If the field is static,
149
   * <code>o</code> will be ignored.
150
   *
151
   * @param o the object to get the value of this Field from
152
   * @return the value of the Field
153
   * @throws IllegalAccessException if you could not normally access this field
154
   *         (i.e. it is not public)
155
   * @throws IllegalArgumentException if this is not a byte field of
156
   *         <code>o</code>, or if <code>o</code> is not an instance of the
157
   *         declaring class of this field
158
   * @throws NullPointerException if <code>o</code> is null and this field
159
   *         requires an instance
160
   * @throws ExceptionInInitializerError if accessing a static field triggered
161
   *         class initialization, which then failed
162
   * @see #get(Object)
163
   */
164
  native byte getByte(Object o)
165
    throws IllegalAccessException;
166
 
167
  /**
168
   * Get the value of this Field as a char. If the field is static,
169
   * <code>o</code> will be ignored.
170
   *
171
   * @param o the object to get the value of this Field from
172
   * @throws IllegalAccessException if you could not normally access this field
173
   *         (i.e. it is not public)
174
   * @throws IllegalArgumentException if this is not a char field of
175
   *         <code>o</code>, or if <code>o</code> is not an instance
176
   *         of the declaring class of this field
177
   * @throws NullPointerException if <code>o</code> is null and this field
178
   *         requires an instance
179
   * @throws ExceptionInInitializerError if accessing a static field triggered
180
   *         class initialization, which then failed
181
   * @see #get(Object)
182
   */
183
  native char getChar(Object o)
184
    throws IllegalAccessException;
185
 
186
  /**
187
   * Get the value of this Field as a short. If the field is static,
188
   * <code>o</code> will be ignored.
189
   *
190
   * @param o the object to get the value of this Field from
191
   * @return the value of the Field
192
   * @throws IllegalAccessException if you could not normally access this field
193
   *         (i.e. it is not public)
194
   * @throws IllegalArgumentException if this is not a byte or short
195
   *         field of <code>o</code>, or if <code>o</code> is not an instance
196
   *         of the declaring class of this field
197
   * @throws NullPointerException if <code>o</code> is null and this field
198
   *         requires an instance
199
   * @throws ExceptionInInitializerError if accessing a static field triggered
200
   *         class initialization, which then failed
201
   * @see #get(Object)
202
   */
203
  native short getShort(Object o)
204
    throws IllegalAccessException;
205
 
206
  /**
207
   * Get the value of this Field as an int. If the field is static,
208
   * <code>o</code> will be ignored.
209
   *
210
   * @param o the object to get the value of this Field from
211
   * @return the value of the Field
212
   * @throws IllegalAccessException if you could not normally access this field
213
   *         (i.e. it is not public)
214
   * @throws IllegalArgumentException if this is not a byte, short, char, or
215
   *         int field of <code>o</code>, or if <code>o</code> is not an
216
   *         instance of the declaring class of this field
217
   * @throws NullPointerException if <code>o</code> is null and this field
218
   *         requires an instance
219
   * @throws ExceptionInInitializerError if accessing a static field triggered
220
   *         class initialization, which then failed
221
   * @see #get(Object)
222
   */
223
  native int getInt(Object o)
224
    throws IllegalAccessException;
225
 
226
  /**
227
   * Get the value of this Field as a long. If the field is static,
228
   * <code>o</code> will be ignored.
229
   *
230
   * @param o the object to get the value of this Field from
231
   * @return the value of the Field
232
   * @throws IllegalAccessException if you could not normally access this field
233
   *         (i.e. it is not public)
234
   * @throws IllegalArgumentException if this is not a byte, short, char, int,
235
   *         or long field of <code>o</code>, or if <code>o</code> is not an
236
   *         instance of the declaring class of this field
237
   * @throws NullPointerException if <code>o</code> is null and this field
238
   *         requires an instance
239
   * @throws ExceptionInInitializerError if accessing a static field triggered
240
   *         class initialization, which then failed
241
   * @see #get(Object)
242
   */
243
  native long getLong(Object o)
244
    throws IllegalAccessException;
245
 
246
  /**
247
   * Get the value of this Field as a float. If the field is static,
248
   * <code>o</code> will be ignored.
249
   *
250
   * @param o the object to get the value of this Field from
251
   * @return the value of the Field
252
   * @throws IllegalAccessException if you could not normally access this field
253
   *         (i.e. it is not public)
254
   * @throws IllegalArgumentException if this is not a byte, short, char, int,
255
   *         long, or float field of <code>o</code>, or if <code>o</code> is
256
   *         not an instance of the declaring class of this field
257
   * @throws NullPointerException if <code>o</code> is null and this field
258
   *         requires an instance
259
   * @throws ExceptionInInitializerError if accessing a static field triggered
260
   *         class initialization, which then failed
261
   * @see #get(Object)
262
   */
263
  native float getFloat(Object o)
264
    throws IllegalAccessException;
265
 
266
  /**
267
   * Get the value of this Field as a double. If the field is static,
268
   * <code>o</code> will be ignored.
269
   *
270
   * @param o the object to get the value of this Field from
271
   * @return the value of the Field
272
   * @throws IllegalAccessException if you could not normally access this field
273
   *         (i.e. it is not public)
274
   * @throws IllegalArgumentException if this is not a byte, short, char, int,
275
   *         long, float, or double field of <code>o</code>, or if
276
   *         <code>o</code> is not an instance of the declaring class of this
277
   *         field
278
   * @throws NullPointerException if <code>o</code> is null and this field
279
   *         requires an instance
280
   * @throws ExceptionInInitializerError if accessing a static field triggered
281
   *         class initialization, which then failed
282
   * @see #get(Object)
283
   */
284
  native double getDouble(Object o)
285
    throws IllegalAccessException;
286
 
287
  /**
288
   * Set the value of this Field.  If it is a primitive field, the value
289
   * will be unwrapped from the passed object (boolean = java.lang.Boolean).<p>
290
   *
291
   * If the field is static, <code>o</code> will be ignored. Otherwise, if
292
   * <code>o</code> is null, you get a <code>NullPointerException</code>,
293
   * and if it is incompatible with the declaring class of the field, you
294
   * get an <code>IllegalArgumentException</code>.<p>
295
   *
296
   * Next, if this Field enforces access control, your runtime context is
297
   * evaluated, and you may have an <code>IllegalAccessException</code> if
298
   * you could not access this field in similar compiled code. This also
299
   * occurs whether or not there is access control if the field is final.
300
   * If the field is primitive, and unwrapping your argument fails, you will
301
   * get an <code>IllegalArgumentException</code>; likewise, this error
302
   * happens if <code>value</code> cannot be cast to the correct object type.
303
   * If the field is static, and its class is uninitialized, you trigger class
304
   * initialization, which may end in a
305
   * <code>ExceptionInInitializerError</code>.<p>
306
   *
307
   * Finally, the field is set with the widened value. This method accesses
308
   * the field of the declaring class, even if the instance passed in belongs
309
   * to a subclass which declares another field to hide this one.
310
   *
311
   * @param o the object to set this Field on
312
   * @param value the value to set this Field to
313
   * @throws IllegalAccessException if you could not normally access this field
314
   *         (i.e. it is not public)
315
   * @throws IllegalArgumentException if <code>value</code> cannot be
316
   *         converted by a widening conversion to the underlying type of
317
   *         the Field, or if <code>o</code> is not an instance of the class
318
   *         declaring 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 #setBoolean(Object, boolean)
324
   * @see #setByte(Object, byte)
325
   * @see #setChar(Object, char)
326
   * @see #setShort(Object, short)
327
   * @see #setInt(Object, int)
328
   * @see #setLong(Object, long)
329
   * @see #setFloat(Object, float)
330
   * @see #setDouble(Object, double)
331
   */
332
  native void set(Object o, Object value)
333
    throws IllegalAccessException;
334
 
335
  /**
336
   * Set this boolean Field. If the field is static, <code>o</code> will be
337
   * ignored.
338
   *
339
   * @param o the object to set this Field on
340
   * @param value the value to set this Field to
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 boolean field, or if
344
   *         <code>o</code> is not an instance of the class declaring this
345
   *         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 #set(Object, Object)
351
   */
352
  native void setBoolean(Object o, boolean value)
353
    throws IllegalAccessException;
354
 
355
  /**
356
   * Set this byte Field. If the field is static, <code>o</code> will be
357
   * ignored.
358
   *
359
   * @param o the object to set this Field on
360
   * @param value the value to set this Field to
361
   * @throws IllegalAccessException if you could not normally access this field
362
   *         (i.e. it is not public)
363
   * @throws IllegalArgumentException if this is not a byte, short, int, long,
364
   *         float, or double field, or if <code>o</code> is not an instance
365
   *         of the class declaring this field
366
   * @throws NullPointerException if <code>o</code> is null and this field
367
   *         requires an instance
368
   * @throws ExceptionInInitializerError if accessing a static field triggered
369
   *         class initialization, which then failed
370
   * @see #set(Object, Object)
371
   */
372
  native void setByte(Object o, byte value)
373
    throws IllegalAccessException;
374
 
375
  /**
376
   * Set this char Field. If the field is static, <code>o</code> will be
377
   * ignored.
378
   *
379
   * @param o the object to set this Field on
380
   * @param value the value to set this Field to
381
   * @throws IllegalAccessException if you could not normally access this field
382
   *         (i.e. it is not public)
383
   * @throws IllegalArgumentException if this is not a char, int, long,
384
   *         float, or double field, or if <code>o</code> is not an instance
385
   *         of the class declaring this field
386
   * @throws NullPointerException if <code>o</code> is null and this field
387
   *         requires an instance
388
   * @throws ExceptionInInitializerError if accessing a static field triggered
389
   *         class initialization, which then failed
390
   * @see #set(Object, Object)
391
   */
392
  native void setChar(Object o, char value)
393
    throws IllegalAccessException;
394
 
395
  /**
396
   * Set this short Field. If the field is static, <code>o</code> will be
397
   * ignored.
398
   *
399
   * @param o the object to set this Field on
400
   * @param value the value to set this Field to
401
   * @throws IllegalAccessException if you could not normally access this field
402
   *         (i.e. it is not public)
403
   * @throws IllegalArgumentException if this is not a short, int, long,
404
   *         float, or double field, or if <code>o</code> is not an instance
405
   *         of the class declaring this field
406
   * @throws NullPointerException if <code>o</code> is null and this field
407
   *         requires an instance
408
   * @throws ExceptionInInitializerError if accessing a static field triggered
409
   *         class initialization, which then failed
410
   * @see #set(Object, Object)
411
   */
412
  native void setShort(Object o, short value)
413
    throws IllegalAccessException;
414
 
415
  /**
416
   * Set this int Field. If the field is static, <code>o</code> will be
417
   * ignored.
418
   *
419
   * @param o the object to set this Field on
420
   * @param value the value to set this Field to
421
   * @throws IllegalAccessException if you could not normally access this field
422
   *         (i.e. it is not public)
423
   * @throws IllegalArgumentException if this is not an int, long, float, or
424
   *         double field, or if <code>o</code> is not an instance of the
425
   *         class declaring this field
426
   * @throws NullPointerException if <code>o</code> is null and this field
427
   *         requires an instance
428
   * @throws ExceptionInInitializerError if accessing a static field triggered
429
   *         class initialization, which then failed
430
   * @see #set(Object, Object)
431
   */
432
  native void setInt(Object o, int value)
433
    throws IllegalAccessException;
434
 
435
  /**
436
   * Set this long Field. If the field is static, <code>o</code> will be
437
   * ignored.
438
   *
439
   * @param o the object to set this Field on
440
   * @param value the value to set this Field to
441
   * @throws IllegalAccessException if you could not normally access this field
442
   *         (i.e. it is not public)
443
   * @throws IllegalArgumentException if this is not a long, float, or double
444
   *         field, or if <code>o</code> is not an instance of the class
445
   *         declaring this field
446
   * @throws NullPointerException if <code>o</code> is null and this field
447
   *         requires an instance
448
   * @throws ExceptionInInitializerError if accessing a static field triggered
449
   *         class initialization, which then failed
450
   * @see #set(Object, Object)
451
   */
452
  native void setLong(Object o, long value)
453
    throws IllegalAccessException;
454
 
455
  /**
456
   * Set this float Field. If the field is static, <code>o</code> will be
457
   * ignored.
458
   *
459
   * @param o the object to set this Field on
460
   * @param value the value to set this Field to
461
   * @throws IllegalAccessException if you could not normally access this field
462
   *         (i.e. it is not public)
463
   * @throws IllegalArgumentException if this is not a float or long field, or
464
   *         if <code>o</code> is not an instance of the class declaring this
465
   *         field
466
   * @throws NullPointerException if <code>o</code> is null and this field
467
   *         requires an instance
468
   * @throws ExceptionInInitializerError if accessing a static field triggered
469
   *         class initialization, which then failed
470
   * @see #set(Object, Object)
471
   */
472
  native void setFloat(Object o, float value)
473
    throws IllegalAccessException;
474
 
475
  /**
476
   * Set this double Field. If the field is static, <code>o</code> will be
477
   * ignored.
478
   *
479
   * @param o the object to set this Field on
480
   * @param value the value to set this Field to
481
   * @throws IllegalAccessException if you could not normally access this field
482
   *         (i.e. it is not public)
483
   * @throws IllegalArgumentException if this is not a double field, or if
484
   *         <code>o</code> is not an instance of the class declaring this
485
   *         field
486
   * @throws NullPointerException if <code>o</code> is null and this field
487
   *         requires an instance
488
   * @throws ExceptionInInitializerError if accessing a static field triggered
489
   *         class initialization, which then failed
490
   * @see #set(Object, Object)
491
   */
492
  native void setDouble(Object o, double value)
493
    throws IllegalAccessException;
494
 
495
  /**
496
   * Return the String in the Signature attribute for this field. If there
497
   * is no Signature attribute, return null.
498
   *
499
   */
500
  native String getSignature();
501
 
502
  /**
503
   * Compare two objects to see if they are semantically equivalent.
504
   * Two Fields are semantically equivalent if they have the same declaring
505
   * class, name, and type. Since you can't create a Field except through
506
   * the VM, this is just the == relation.
507
   *
508
   * @param o the object to compare to
509
   * @return <code>true</code> if they are equal; <code>false</code> if not
510
   */
511
  public boolean equals(Object o)
512
  {
513
    if (!(o instanceof Field))
514
      return false;
515
    Field that = (Field)o;
516
    if (clazz != that.getDeclaringClass())
517
      return false;
518
    if (!name.equals(that.getName()))
519
      return false;
520
    if (getType() != that.getType())
521
      return false;
522
    return true;
523
  }
524
 
525
  /**
526
   * Returns the element's annotation for the specified annotation type,
527
   * or <code>null</code> if no such annotation exists.
528
   *
529
   * @param annotationClass the type of annotation to look for.
530
   * @return this element's annotation for the specified type, or
531
   *         <code>null</code> if no such annotation exists.
532
   * @throws NullPointerException if the annotation class is <code>null</code>.
533
   */
534
  native Annotation getAnnotation(Class annotationClass);
535
 
536
  /**
537
   * Returns all annotations directly defined by the element.  If there are
538
   * no annotations directly associated with the element, then a zero-length
539
   * array will be returned.  The returned array may be modified by the client
540
   * code, but this will have no effect on the annotation content of this
541
   * class, and hence no effect on the return value of this method for
542
   * future callers.
543
   *
544
   * @return the annotations directly defined by the element.
545
   * @since 1.5
546
   */
547
  native Annotation[] getDeclaredAnnotations();
548
 
549
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.