View Javadoc

1   // Field.java, created Thu Jul  4  4:50:03 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.Common.java.lang.reflect;
5   
6   import joeq.Class.jq_Class;
7   import joeq.Class.jq_Field;
8   import joeq.Class.jq_InstanceField;
9   import joeq.Class.jq_NameAndDesc;
10  import joeq.Class.jq_Primitive;
11  import joeq.Class.jq_Reference;
12  import joeq.Class.jq_StaticField;
13  import joeq.Class.jq_Type;
14  import joeq.ClassLib.Common.ClassUtils;
15  import joeq.Main.jq;
16  import joeq.Runtime.Reflection;
17  import joeq.Runtime.TypeCheck;
18  import joeq.UTF.Utf8;
19  import jwutil.util.Assert;
20  import jwutil.util.Convert;
21  
22  /***
23   * Field
24   *
25   * @author  John Whaley <jwhaley@alum.mit.edu>
26   * @version $Id: Field.java 1985 2004-10-08 08:43:02Z joewhaley $
27   */
28  public class Field extends AccessibleObject {
29      
30      // additional instance field.
31      public final jq_Field jq_field;
32      
33      private java.lang.Class clazz;
34      private java.lang.String name;
35      private java.lang.Class type;
36      private int modifiers;
37      private int slot;
38      
39      private Field(jq_Field f) {
40          this.jq_field = f;
41      }
42      
43      private Field(java.lang.Class clazz,
44                    java.lang.String name,
45                    java.lang.Class type,
46                    int modifiers,
47                    int slot) {
48          this.clazz = clazz;
49          this.name = name;
50          this.type = type;
51          this.modifiers = modifiers;
52          this.slot = slot;
53          
54          jq_Class c = (jq_Class) Reflection.getJQType(clazz);
55          //if (c == null) return null;
56          jq_NameAndDesc nd = new jq_NameAndDesc(Utf8.get(name), Reflection.getJQType(type).getDesc());
57          nd = joeq.ClassLib.ClassLibInterface.convertClassLibNameAndDesc(c, nd);
58          jq_Field m = (jq_Field)c.getDeclaredMember(nd);
59          if (m == null) {
60              if (java.lang.reflect.Modifier.isStatic(modifiers))
61                  m = c.getOrCreateStaticField(nd);
62              else
63                  m = c.getOrCreateInstanceField(nd);
64          }
65          this.jq_field = m;
66      }
67      
68      // overridden implementations.
69      public java.lang.Class getDeclaringClass() {
70          jq_Field jq_f = this.jq_field;
71          return jq_f.getDeclaringClass().getJavaLangClassObject();
72      }
73      public String getName() {
74          jq_Field jq_f = this.jq_field;
75          return jq_f.getName().toString();
76      }
77      public int getModifiers() {
78          jq_Field jq_f = this.jq_field;
79          return jq_f.getAccessFlags();
80      }
81      public Class getType() {
82          jq_Field jq_f = this.jq_field;
83          return jq_f.getType().getJavaLangClassObject();
84      }
85      public boolean equals(Object obj) {
86          return this == obj;
87      }
88      
89      // native method implementations.
90      public java.lang.Object get(java.lang.Object obj)
91          throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException
92      {
93          jq_Field jq_f = this.jq_field;
94          jq_Type t = jq_f.getType();
95          if (jq_f.isStatic()) {
96              if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
97              jq_StaticField sf = (jq_StaticField)jq_f;
98              if (t.isReferenceType()) return Reflection.getstatic_A(sf);
99              if (t == jq_Primitive.INT) return new Integer(Reflection.getstatic_I(sf));
100             if (t == jq_Primitive.FLOAT) return new Float(Reflection.getstatic_F(sf));
101             if (t == jq_Primitive.LONG) return new Long(Reflection.getstatic_L(sf));
102             if (t == jq_Primitive.DOUBLE) return new Double(Reflection.getstatic_D(sf));
103             if (t == jq_Primitive.BOOLEAN) return Convert.getBoolean(Reflection.getstatic_Z(sf));
104             if (t == jq_Primitive.BYTE) return new Byte(Reflection.getstatic_B(sf));
105             if (t == jq_Primitive.SHORT) return new Short(Reflection.getstatic_S(sf));
106             if (t == jq_Primitive.CHAR) return new Character(Reflection.getstatic_C(sf));
107         } else {
108             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
109             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
110                 throw new IllegalArgumentException();
111             }
112             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
113             jq_InstanceField f = (jq_InstanceField)jq_f;
114             if (t.isReferenceType()) return Reflection.getfield_A(obj, f);
115             if (t == jq_Primitive.INT) return new Integer(Reflection.getfield_I(obj, f));
116             if (t == jq_Primitive.FLOAT) return new Float(Reflection.getfield_F(obj, f));
117             if (t == jq_Primitive.LONG) return new Long(Reflection.getfield_L(obj, f));
118             if (t == jq_Primitive.DOUBLE) return new Double(Reflection.getfield_D(obj, f));
119             if (t == jq_Primitive.BOOLEAN) return Convert.getBoolean(Reflection.getfield_Z(obj, f));
120             if (t == jq_Primitive.BYTE) return new Byte(Reflection.getfield_B(obj, f));
121             if (t == jq_Primitive.SHORT) return new Short(Reflection.getfield_S(obj, f));
122             if (t == jq_Primitive.CHAR) return new Character(Reflection.getfield_C(obj, f));
123         }
124         Assert.UNREACHABLE();
125         return null;
126     }
127 
128     public boolean getBoolean(java.lang.Object obj)
129         throws IllegalArgumentException, IllegalAccessException
130     {
131         jq_Field jq_f = this.jq_field;
132         jq_Type t = jq_f.getType();
133         if (jq_f.isStatic()) {
134             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
135             jq_StaticField sf = (jq_StaticField)jq_f;
136             if (t == jq_Primitive.BOOLEAN) return Reflection.getstatic_Z(sf);
137         } else {
138             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
139             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
140                 throw new IllegalArgumentException();
141             }
142             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
143             jq_InstanceField f = (jq_InstanceField)jq_f;
144             if (t == jq_Primitive.BOOLEAN) return Reflection.getfield_Z(obj, f);
145         }
146         Assert.UNREACHABLE();
147         return false;
148     }
149     
150     public byte getByte(java.lang.Object obj)
151         throws IllegalArgumentException, IllegalAccessException
152     {
153         jq_Field jq_f = this.jq_field;
154         jq_Type t = jq_f.getType();
155         if (jq_f.isStatic()) {
156             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
157             jq_StaticField sf = (jq_StaticField)jq_f;
158             if (t == jq_Primitive.BYTE) return Reflection.getstatic_B(sf);
159         } else {
160             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
161             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
162                 throw new IllegalArgumentException();
163             }
164             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
165             jq_InstanceField f = (jq_InstanceField)jq_f;
166             if (t == jq_Primitive.BYTE) return Reflection.getfield_B(obj, f);
167         }
168         Assert.UNREACHABLE();
169         return (byte)0;
170     }
171     
172     public char getChar(java.lang.Object obj)
173         throws IllegalArgumentException, IllegalAccessException
174     {
175         jq_Field jq_f = this.jq_field;
176         jq_Type t = jq_f.getType();
177         if (jq_f.isStatic()) {
178             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
179             jq_StaticField sf = (jq_StaticField)jq_f;
180             if (t == jq_Primitive.CHAR) return Reflection.getstatic_C(sf);
181         } else {
182             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
183             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
184                 throw new IllegalArgumentException();
185             }
186             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
187             jq_InstanceField f = (jq_InstanceField)jq_f;
188             if (t == jq_Primitive.CHAR) return Reflection.getfield_C(obj, f);
189         }
190         Assert.UNREACHABLE();
191         return (char)0;
192     }
193     
194     // byte -> short
195     public short getShort(java.lang.Object obj)
196         throws IllegalArgumentException, IllegalAccessException
197     {
198         jq_Field jq_f = this.jq_field;
199         jq_Type t = jq_f.getType();
200         if (jq_f.isStatic()) {
201             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
202             jq_StaticField sf = (jq_StaticField)jq_f;
203             if (t == jq_Primitive.SHORT) return Reflection.getstatic_S(sf);
204             if (t == jq_Primitive.BYTE) return (short)Reflection.getstatic_B(sf);
205         } else {
206             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
207             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
208                 throw new IllegalArgumentException();
209             }
210             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
211             jq_InstanceField f = (jq_InstanceField)jq_f;
212             if (t == jq_Primitive.SHORT) return Reflection.getfield_S(obj, f);
213             if (t == jq_Primitive.BYTE) return (short)Reflection.getfield_B(obj, f);
214         }
215         Assert.UNREACHABLE();
216         return (short)0;
217     }
218     
219     // byte -> int
220     // char -> int
221     // short -> int
222     public int getInt(java.lang.Object obj)
223         throws IllegalArgumentException, IllegalAccessException
224     {
225         jq_Field jq_f = this.jq_field;
226         jq_Type t = jq_f.getType();
227         if (jq_f.isStatic()) {
228             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
229             jq_StaticField sf = (jq_StaticField)jq_f;
230             if (t == jq_Primitive.INT) return Reflection.getstatic_I(sf);
231             if (t == jq_Primitive.BYTE) return (int)Reflection.getstatic_B(sf);
232             if (t == jq_Primitive.SHORT) return (int)Reflection.getstatic_S(sf);
233             if (t == jq_Primitive.CHAR) return (int)Reflection.getstatic_C(sf);
234         } else {
235             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
236             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
237                 throw new IllegalArgumentException();
238             }
239             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
240             jq_InstanceField f = (jq_InstanceField)jq_f;
241             if (t == jq_Primitive.INT) return Reflection.getfield_I(obj, f);
242             if (t == jq_Primitive.BYTE) return (int)Reflection.getfield_B(obj, f);
243             if (t == jq_Primitive.SHORT) return (int)Reflection.getfield_S(obj, f);
244             if (t == jq_Primitive.CHAR) return (int)Reflection.getfield_C(obj, f);
245         }
246         Assert.UNREACHABLE();
247         return 0;
248     }
249     
250     // byte -> long
251     // char -> long
252     // short -> long
253     // int -> long
254     public long getLong(java.lang.Object obj)
255         throws IllegalArgumentException, IllegalAccessException
256     {
257         jq_Field jq_f = this.jq_field;
258         jq_Type t = jq_f.getType();
259         if (jq_f.isStatic()) {
260             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
261             jq_StaticField sf = (jq_StaticField)jq_f;
262             if (t == jq_Primitive.LONG) return Reflection.getstatic_L(sf);
263             if (t == jq_Primitive.BYTE) return (long)Reflection.getstatic_B(sf);
264             if (t == jq_Primitive.SHORT) return (long)Reflection.getstatic_S(sf);
265             if (t == jq_Primitive.CHAR) return (long)Reflection.getstatic_C(sf);
266             if (t == jq_Primitive.INT) return (long)Reflection.getstatic_I(sf);
267         } else {
268             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
269             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
270                 throw new IllegalArgumentException();
271             }
272             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
273             jq_InstanceField f = (jq_InstanceField)jq_f;
274             if (t == jq_Primitive.LONG) return Reflection.getfield_L(obj, f);
275             if (t == jq_Primitive.BYTE) return (long)Reflection.getfield_B(obj, f);
276             if (t == jq_Primitive.SHORT) return (long)Reflection.getfield_S(obj, f);
277             if (t == jq_Primitive.CHAR) return (long)Reflection.getfield_C(obj, f);
278             if (t == jq_Primitive.INT) return (long)Reflection.getfield_I(obj, f);
279         }
280         Assert.UNREACHABLE();
281         return 0L;
282     }
283     
284     // byte -> float
285     // char -> float
286     // short -> float
287     // int -> float
288     // long -> float
289     public float getFloat(java.lang.Object obj)
290         throws IllegalArgumentException, IllegalAccessException
291     {
292         jq_Field jq_f = this.jq_field;
293         jq_Type t = jq_f.getType();
294         if (jq_f.isStatic()) {
295             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
296             jq_StaticField sf = (jq_StaticField)jq_f;
297             if (t == jq_Primitive.FLOAT) return Reflection.getstatic_F(sf);
298             if (t == jq_Primitive.BYTE) return (float)Reflection.getstatic_B(sf);
299             if (t == jq_Primitive.SHORT) return (float)Reflection.getstatic_S(sf);
300             if (t == jq_Primitive.CHAR) return (float)Reflection.getstatic_C(sf);
301             if (t == jq_Primitive.INT) return (float)Reflection.getstatic_I(sf);
302             if (t == jq_Primitive.LONG) return (float)Reflection.getstatic_L(sf);
303         } else {
304             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
305             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
306                 throw new IllegalArgumentException();
307             }
308             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
309             jq_InstanceField f = (jq_InstanceField)jq_f;
310             if (t == jq_Primitive.FLOAT) return Reflection.getfield_F(obj, f);
311             if (t == jq_Primitive.BYTE) return (float)Reflection.getfield_B(obj, f);
312             if (t == jq_Primitive.SHORT) return (float)Reflection.getfield_S(obj, f);
313             if (t == jq_Primitive.CHAR) return (float)Reflection.getfield_C(obj, f);
314             if (t == jq_Primitive.INT) return (float)Reflection.getfield_I(obj, f);
315             if (t == jq_Primitive.LONG) return (float)Reflection.getfield_L(obj, f);
316         }
317         Assert.UNREACHABLE();
318         return 0F;
319     }
320     
321     // byte -> double
322     // char -> double
323     // short -> double
324     // int -> double
325     // long -> double
326     // float -> double
327     public double getDouble(java.lang.Object obj)
328         throws IllegalArgumentException, IllegalAccessException
329     {
330         jq_Field jq_f = this.jq_field;
331         jq_Type t = jq_f.getType();
332         if (jq_f.isStatic()) {
333             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
334             jq_StaticField sf = (jq_StaticField)jq_f;
335             if (t == jq_Primitive.DOUBLE) return Reflection.getstatic_D(sf);
336             if (t == jq_Primitive.BYTE) return (double)Reflection.getstatic_B(sf);
337             if (t == jq_Primitive.SHORT) return (double)Reflection.getstatic_S(sf);
338             if (t == jq_Primitive.CHAR) return (double)Reflection.getstatic_C(sf);
339             if (t == jq_Primitive.INT) return (double)Reflection.getstatic_I(sf);
340             if (t == jq_Primitive.LONG) return (double)Reflection.getstatic_L(sf);
341             if (t == jq_Primitive.FLOAT) return (double)Reflection.getstatic_L(sf);
342         } else {
343             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
344             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
345                 throw new IllegalArgumentException();
346             }
347             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
348             jq_InstanceField f = (jq_InstanceField)jq_f;
349             if (t == jq_Primitive.DOUBLE) return Reflection.getfield_F(obj, f);
350             if (t == jq_Primitive.BYTE) return (double)Reflection.getfield_B(obj, f);
351             if (t == jq_Primitive.SHORT) return (double)Reflection.getfield_S(obj, f);
352             if (t == jq_Primitive.CHAR) return (double)Reflection.getfield_C(obj, f);
353             if (t == jq_Primitive.INT) return (double)Reflection.getfield_I(obj, f);
354             if (t == jq_Primitive.LONG) return (double)Reflection.getfield_L(obj, f);
355             if (t == jq_Primitive.FLOAT) return (double)Reflection.getfield_L(obj, f);
356         }
357         Assert.UNREACHABLE();
358         return 0F;
359     }
360     
361     public void set(java.lang.Object obj, java.lang.Object value)
362         throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException
363     {
364         jq_Field jq_f = this.jq_field;
365         jq_Type t = jq_f.getType();
366         if (jq_f.isStatic()) {
367             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
368             if (jq_f.isFinal()) {
369                 throw new IllegalAccessException();
370             }
371             jq_StaticField sf = (jq_StaticField)jq_f;
372             if (t.isReferenceType()) Reflection.putstatic_A(sf, value);
373             else if (t == jq_Primitive.INT) {
374                 int val = Convert.unwrapToInt(value);
375                 Reflection.putstatic_I(sf, val);
376             }
377             else if (t == jq_Primitive.FLOAT) {
378                 float val = Convert.unwrapToFloat(value);
379                 Reflection.putstatic_F(sf, val);
380             }
381             else if (t == jq_Primitive.LONG) {
382                 long val = Convert.unwrapToLong(value);
383                 Reflection.putstatic_L(sf, val);
384             }
385             else if (t == jq_Primitive.DOUBLE) {
386                 double val = Convert.unwrapToDouble(value);
387                 Reflection.putstatic_D(sf, val);
388             }
389             else if (t == jq_Primitive.BOOLEAN) {
390                 boolean val = Convert.unwrapToBoolean(value);
391                 Reflection.putstatic_Z(sf, val);
392             }
393             else if (t == jq_Primitive.BYTE) {
394                 byte val = Convert.unwrapToByte(value);
395                 Reflection.putstatic_B(sf, val);
396             }
397             else if (t == jq_Primitive.SHORT) {
398                 short val = Convert.unwrapToShort(value);
399                 Reflection.putstatic_S(sf, val);
400             }
401             else if (t == jq_Primitive.CHAR) {
402                 char val = Convert.unwrapToChar(value);
403                 Reflection.putstatic_C(sf, val);
404             }
405             else Assert.UNREACHABLE();
406         } else {
407             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
408             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
409                 throw new IllegalArgumentException();
410             }
411             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
412             if (!jq_f.isFinal()) {
413                 throw new IllegalAccessException();
414             }
415             jq_InstanceField f = (jq_InstanceField)jq_f;
416             if (t.isReferenceType()) {
417                 Reflection.getfield_A(obj, f);
418             }
419             else if (t == jq_Primitive.INT) {
420                 int val = Convert.unwrapToInt(value);
421                 Reflection.putfield_I(obj, f, val);
422             }
423             else if (t == jq_Primitive.FLOAT) {
424                 float val = Convert.unwrapToFloat(value);
425                 Reflection.putfield_F(obj, f, val);
426             }
427             else if (t == jq_Primitive.LONG) {
428                 long val = Convert.unwrapToLong(value);
429                 Reflection.putfield_L(obj, f, val);
430             }
431             else if (t == jq_Primitive.DOUBLE) {
432                 double val = Convert.unwrapToDouble(value);
433                 Reflection.putfield_D(obj, f, val);
434             }
435             else if (t == jq_Primitive.BOOLEAN) {
436                 boolean val = Convert.unwrapToBoolean(value);
437                 Reflection.putfield_Z(obj, f, val);
438             }
439             else if (t == jq_Primitive.BYTE) {
440                 byte val = Convert.unwrapToByte(value);
441                 Reflection.putfield_B(obj, f, val);
442             }
443             else if (t == jq_Primitive.SHORT) {
444                 short val = Convert.unwrapToShort(value);
445                 Reflection.putfield_S(obj, f, val);
446             }
447             else if (t == jq_Primitive.CHAR) {
448                 char val = Convert.unwrapToChar(value);
449                 Reflection.putfield_C(obj, f, val);
450             }
451             else Assert.UNREACHABLE();
452         }
453     }
454     
455     public void setBoolean(java.lang.Object obj, boolean val)
456         throws IllegalArgumentException, IllegalAccessException {
457         jq_Field jq_f = this.jq_field;
458         jq_Type t = jq_f.getType();
459         if (jq_f.isStatic()) {
460             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
461             if (jq_f.isFinal()) {
462                 throw new IllegalAccessException();
463             }
464             jq_StaticField sf = (jq_StaticField)jq_f;
465             if (t == jq_Primitive.BOOLEAN) {
466                 Reflection.putstatic_Z(sf, val);
467             }
468             else Assert.UNREACHABLE();
469         } else {
470             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
471             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
472                 throw new IllegalArgumentException();
473             }
474             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
475             if (!jq_f.isFinal()) {
476                 throw new IllegalAccessException();
477             }
478             jq_InstanceField f = (jq_InstanceField)jq_f;
479             if (t == jq_Primitive.BOOLEAN) {
480                 Reflection.putfield_Z(obj, f, val);
481             }
482             else Assert.UNREACHABLE();
483         }
484     }
485     
486     public void setByte(java.lang.Object obj, byte val)
487         throws IllegalArgumentException, IllegalAccessException {
488         jq_Field jq_f = this.jq_field;
489         jq_Type t = jq_f.getType();
490         if (jq_f.isStatic()) {
491             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
492             if (jq_f.isFinal()) {
493                 throw new IllegalAccessException();
494             }
495             jq_StaticField sf = (jq_StaticField)jq_f;
496             if (t == jq_Primitive.BYTE) {
497                 Reflection.putstatic_B(sf, val);
498             }
499             else if (t == jq_Primitive.SHORT) {
500                 Reflection.putstatic_S(sf, (short)val);
501             }
502             else if (t == jq_Primitive.INT) {
503                 Reflection.putstatic_I(sf, (int)val);
504             }
505             else if (t == jq_Primitive.LONG) {
506                 Reflection.putstatic_L(sf, (long)val);
507             }
508             else if (t == jq_Primitive.FLOAT) {
509                 Reflection.putstatic_F(sf, (float)val);
510             }
511             else if (t == jq_Primitive.DOUBLE) {
512                 Reflection.putstatic_D(sf, (double)val);
513             }
514             else Assert.UNREACHABLE();
515         } else {
516             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
517             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
518                 throw new IllegalArgumentException();
519             }
520             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
521             if (!jq_f.isFinal()) {
522                 throw new IllegalAccessException();
523             }
524             jq_InstanceField f = (jq_InstanceField)jq_f;
525             if (t == jq_Primitive.BYTE) {
526                 Reflection.putfield_B(obj, f, val);
527             }
528             else if (t == jq_Primitive.SHORT) {
529                 Reflection.putfield_S(obj, f, (short)val);
530             }
531             else if (t == jq_Primitive.INT) {
532                 Reflection.putfield_I(obj, f, (int)val);
533             }
534             else if (t == jq_Primitive.LONG) {
535                 Reflection.putfield_L(obj, f, (long)val);
536             }
537             else if (t == jq_Primitive.FLOAT) {
538                 Reflection.putfield_F(obj, f, (float)val);
539             }
540             else if (t == jq_Primitive.DOUBLE) {
541                 Reflection.putfield_D(obj, f, (double)val);
542             }
543             else Assert.UNREACHABLE();
544         }
545     }
546     
547     public void setChar(java.lang.Object obj, char val)
548         throws IllegalArgumentException, IllegalAccessException {
549         jq_Field jq_f = this.jq_field;
550         jq_Type t = jq_f.getType();
551         if (jq_f.isStatic()) {
552             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
553             if (jq_f.isFinal()) {
554                 throw new IllegalAccessException();
555             }
556             jq_StaticField sf = (jq_StaticField)jq_f;
557             if (t == jq_Primitive.CHAR) {
558                 Reflection.putstatic_C(sf, val);
559             }
560             else if (t == jq_Primitive.INT) {
561                 Reflection.putstatic_I(sf, (int)val);
562             }
563             else if (t == jq_Primitive.LONG) {
564                 Reflection.putstatic_L(sf, (long)val);
565             }
566             else if (t == jq_Primitive.FLOAT) {
567                 Reflection.putstatic_F(sf, (float)val);
568             }
569             else if (t == jq_Primitive.DOUBLE) {
570                 Reflection.putstatic_D(sf, (double)val);
571             }
572             else Assert.UNREACHABLE();
573         } else {
574             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
575             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
576                 throw new IllegalArgumentException();
577             }
578             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
579             if (!jq_f.isFinal()) {
580                 throw new IllegalAccessException();
581             }
582             jq_InstanceField f = (jq_InstanceField)jq_f;
583             if (t == jq_Primitive.CHAR) {
584                 Reflection.putfield_C(obj, f, val);
585             }
586             else if (t == jq_Primitive.INT) {
587                 Reflection.putfield_I(obj, f, (int)val);
588             }
589             else if (t == jq_Primitive.LONG) {
590                 Reflection.putfield_L(obj, f, (long)val);
591             }
592             else if (t == jq_Primitive.FLOAT) {
593                 Reflection.putfield_F(obj, f, (float)val);
594             }
595             else if (t == jq_Primitive.DOUBLE) {
596                 Reflection.putfield_D(obj, f, (double)val);
597             }
598             else Assert.UNREACHABLE();
599         }
600     }
601     
602     public void setShort(java.lang.Object obj, short val)
603         throws IllegalArgumentException, IllegalAccessException {
604         jq_Field jq_f = this.jq_field;
605         jq_Type t = jq_f.getType();
606         if (jq_f.isStatic()) {
607             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
608             if (jq_f.isFinal()) {
609                 throw new IllegalAccessException();
610             }
611             jq_StaticField sf = (jq_StaticField)jq_f;
612             if (t == jq_Primitive.SHORT) {
613                 Reflection.putstatic_S(sf, val);
614             }
615             else if (t == jq_Primitive.INT) {
616                 Reflection.putstatic_I(sf, (int)val);
617             }
618             else if (t == jq_Primitive.LONG) {
619                 Reflection.putstatic_L(sf, (long)val);
620             }
621             else if (t == jq_Primitive.FLOAT) {
622                 Reflection.putstatic_F(sf, (float)val);
623             }
624             else if (t == jq_Primitive.DOUBLE) {
625                 Reflection.putstatic_D(sf, (double)val);
626             }
627             else Assert.UNREACHABLE();
628         } else {
629             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
630             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
631                 throw new IllegalArgumentException();
632             }
633             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
634             if (!jq_f.isFinal()) {
635                 throw new IllegalAccessException();
636             }
637             jq_InstanceField f = (jq_InstanceField)jq_f;
638             if (t == jq_Primitive.SHORT) {
639                 Reflection.putfield_S(obj, f, val);
640             }
641             else if (t == jq_Primitive.INT) {
642                 Reflection.putfield_I(obj, f, (int)val);
643             }
644             else if (t == jq_Primitive.LONG) {
645                 Reflection.putfield_L(obj, f, (long)val);
646             }
647             else if (t == jq_Primitive.FLOAT) {
648                 Reflection.putfield_F(obj, f, (float)val);
649             }
650             else if (t == jq_Primitive.DOUBLE) {
651                 Reflection.putfield_D(obj, f, (double)val);
652             }
653             else Assert.UNREACHABLE();
654         }
655     }
656     
657     public void setInt(java.lang.Object obj, int val)
658         throws IllegalArgumentException, IllegalAccessException {
659         jq_Field jq_f = this.jq_field;
660         jq_Type t = jq_f.getType();
661         if (jq_f.isStatic()) {
662             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
663             if (jq_f.isFinal()) {
664                 throw new IllegalAccessException();
665             }
666             jq_StaticField sf = (jq_StaticField)jq_f;
667             if (t == jq_Primitive.INT) {
668                 Reflection.putstatic_I(sf, val);
669             }
670             else if (t == jq_Primitive.LONG) {
671                 Reflection.putstatic_L(sf, (long)val);
672             }
673             else if (t == jq_Primitive.FLOAT) {
674                 Reflection.putstatic_F(sf, (float)val);
675             }
676             else if (t == jq_Primitive.DOUBLE) {
677                 Reflection.putstatic_D(sf, (double)val);
678             }
679             else Assert.UNREACHABLE();
680         } else {
681             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
682             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
683                 throw new IllegalArgumentException();
684             }
685             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
686             if (!jq_f.isFinal()) {
687                 throw new IllegalAccessException();
688             }
689             jq_InstanceField f = (jq_InstanceField)jq_f;
690             if (t == jq_Primitive.INT) {
691                 Reflection.putfield_I(obj, f, val);
692             }
693             else if (t == jq_Primitive.LONG) {
694                 Reflection.putfield_L(obj, f, (long)val);
695             }
696             else if (t == jq_Primitive.FLOAT) {
697                 Reflection.putfield_F(obj, f, (float)val);
698             }
699             else if (t == jq_Primitive.DOUBLE) {
700                 Reflection.putfield_D(obj, f, (double)val);
701             }
702             else Assert.UNREACHABLE();
703         }
704     }
705     
706     public void setFloat(java.lang.Object obj, float val)
707         throws IllegalArgumentException, IllegalAccessException {
708         jq_Field jq_f = this.jq_field;
709         jq_Type t = jq_f.getType();
710         if (jq_f.isStatic()) {
711             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
712             if (jq_f.isFinal()) {
713                 throw new IllegalAccessException();
714             }
715             jq_StaticField sf = (jq_StaticField)jq_f;
716             if (t == jq_Primitive.FLOAT) {
717                 Reflection.putstatic_F(sf, val);
718             }
719             else if (t == jq_Primitive.DOUBLE) {
720                 Reflection.putstatic_D(sf, (double)val);
721             }
722             else Assert.UNREACHABLE();
723         } else {
724             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
725             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
726                 throw new IllegalArgumentException();
727             }
728             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
729             if (!jq_f.isFinal()) {
730                 throw new IllegalAccessException();
731             }
732             jq_InstanceField f = (jq_InstanceField)jq_f;
733             if (t == jq_Primitive.FLOAT) {
734                 Reflection.putfield_F(obj, f, val);
735             }
736             else if (t == jq_Primitive.DOUBLE) {
737                 Reflection.putfield_D(obj, f, (double)val);
738             }
739             else Assert.UNREACHABLE();
740         }
741     }
742     
743     public void setLong(java.lang.Object obj, long val)
744         throws IllegalArgumentException, IllegalAccessException {
745         jq_Field jq_f = this.jq_field;
746         jq_Type t = jq_f.getType();
747         if (jq_f.isStatic()) {
748             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
749             if (jq_f.isFinal()) {
750                 throw new IllegalAccessException();
751             }
752             jq_StaticField sf = (jq_StaticField)jq_f;
753             if (t == jq_Primitive.LONG) {
754                 Reflection.putstatic_L(sf, val);
755             }
756             else if (t == jq_Primitive.FLOAT) {
757                 Reflection.putstatic_F(sf, (float)val);
758             }
759             else if (t == jq_Primitive.DOUBLE) {
760                 Reflection.putstatic_D(sf, (double)val);
761             }
762             else Assert.UNREACHABLE();
763         } else {
764             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
765             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
766                 throw new IllegalArgumentException();
767             }
768             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
769             if (!jq_f.isFinal()) {
770                 throw new IllegalAccessException();
771             }
772             jq_InstanceField f = (jq_InstanceField)jq_f;
773             if (t == jq_Primitive.LONG) {
774                 Reflection.putfield_L(obj, f, val);
775             }
776             else if (t == jq_Primitive.FLOAT) {
777                 Reflection.putfield_F(obj, f, (float)val);
778             }
779             else if (t == jq_Primitive.DOUBLE) {
780                 Reflection.putfield_D(obj, f, (double)val);
781             }
782             else Assert.UNREACHABLE();
783         }
784     }
785     
786     public void setDouble(java.lang.Object obj, double val)
787         throws IllegalArgumentException, IllegalAccessException {
788         jq_Field jq_f = this.jq_field;
789         jq_Type t = jq_f.getType();
790         if (jq_f.isStatic()) {
791             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
792             if (jq_f.isFinal()) {
793                 throw new IllegalAccessException();
794             }
795             jq_StaticField sf = (jq_StaticField)jq_f;
796             if (t == jq_Primitive.DOUBLE) {
797                 Reflection.putstatic_D(sf, val);
798             }
799             else Assert.UNREACHABLE();
800         } else {
801             jq_Reference obj_t = jq_Reference.getTypeOf(obj);
802             if (!TypeCheck.isAssignable(obj_t, jq_f.getDeclaringClass())) {
803                 throw new IllegalArgumentException();
804             }
805             if (!this.isAccessible()) ClassUtils.checkCallerAccess(jq_f, 2);
806             if (!jq_f.isFinal()) {
807                 throw new IllegalAccessException();
808             }
809             jq_InstanceField f = (jq_InstanceField)jq_f;
810             if (t == jq_Primitive.DOUBLE) {
811                 Reflection.putfield_D(obj, f, val);
812             }
813             else Assert.UNREACHABLE();
814         }
815     }
816     
817     // additional methods.
818     // ONLY TO BE CALLED BY jq_Member CONSTRUCTOR!!!
819     public static java.lang.reflect.Field createNewField(jq_Field jq_field) {
820         Object o = new Field(jq_field);
821         return (java.lang.reflect.Field)o;
822     }
823     
824     public static void initNewField(Field o, jq_Field jq_field) {
825         if (!jq.RunningNative) return;
826         java.lang.String name = jq_field.getName().toString();
827         o.name = name;
828         java.lang.Class clazz = jq_field.getDeclaringClass().getJavaLangClassObject();
829         Assert._assert(clazz != null);
830         o.clazz = clazz;
831         java.lang.Class type = Reflection.getJDKType(jq_field.getType());
832         Assert._assert(type != null);
833         o.type = type;
834         int modifiers = jq_field.getAccessFlags();
835         o.modifiers = modifiers;
836     }
837 }