cc2ba02f78c6e172b9842db8b893b4cb3a3db014
[cacao.git] / src / native / vm / Field.c
1 /* native/vm/Field.c - java/lang/reflect/Field
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30
31    $Id: Field.c 1621 2004-11-30 13:06:55Z twisti $
32
33 */
34
35
36 #include "native/jni.h"
37 #include "native/native.h"
38 #include "native/include/java_lang_Object.h"
39 #include "native/include/java_lang_Class.h"
40 #include "native/include/java_lang_reflect_Field.h"
41 #include "vm/builtin.h"
42 #include "vm/exceptions.h"
43 #include "vm/loader.h"
44 #include "vm/tables.h"
45
46
47 /*
48  * Class:     java/lang/reflect/Field
49  * Method:    get
50  * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
51  */
52 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
53 {
54         jfieldID target_fid;   /* the JNI-fieldid of the wrapping object */
55         jfieldID fid;          /* the JNI-fieldid of the field containing the value */
56         jobject o;               /* the object for wrapping the primitive type */
57         classinfo *c = (classinfo *) this->declaringClass;
58         int st = (this->flag & ACC_STATIC); /* true if field is static */
59
60         /* get the fieldid of the field represented by this Field-object */
61         fid = class_findfield_approx((classinfo *) this->declaringClass,javastring_toutf(this->name, false));
62
63         /* The fieldid is used to retrieve the value, for primitive types a new 
64            object for wrapping the primitive type is created.  */
65         if (st || obj)
66                 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
67                 case 'I':
68                         /* create wrapping class */
69                         c = class_java_lang_Integer;
70                         o = builtin_new(c);
71                         /* get fieldid to store the value */
72                         target_fid = (*env)->GetFieldID(env, c, "value", "I");
73                         if (!target_fid)
74                                 break;
75                                    
76                         if (st)
77                         /* static field */
78                                 SetIntField(env,o,target_fid, (*env)->GetStaticIntField(env, c, fid));
79                         else
80                                 /* instance field */
81                                 SetIntField(env,o,target_fid, (*env)->GetIntField(env,(jobject) obj, fid));
82
83                         /* return the wrapped object */            
84                         return (java_lang_Object *) o;
85
86                 case 'J':
87                         c = class_java_lang_Long;
88                         o = builtin_new(c);
89                         target_fid = (*env)->GetFieldID(env, c, "value", "J");
90                         if (!target_fid)
91                                 break;
92                                    
93                         if (st)
94                                 SetLongField(env,o,target_fid, (*env)->GetStaticLongField(env, c, fid));
95                         else
96                                 SetLongField(env,o,target_fid, (*env)->GetLongField(env,(jobject)  obj, fid));
97
98                         return (java_lang_Object *) o;
99
100                 case 'F':
101                         c = class_java_lang_Float;
102                         o = builtin_new(c);
103                         target_fid = (*env)->GetFieldID(env, c, "value", "F");
104                         if (!target_fid)
105                                 break;
106                                    
107                         if (st)
108                                 SetFloatField(env,o,target_fid, (*env)->GetStaticFloatField(env, c, fid));
109                         else
110                                 SetFloatField(env,o,target_fid, (*env)->GetFloatField(env, (jobject) obj, fid));
111
112                         return (java_lang_Object *) o;
113
114                 case 'D':
115                         c = class_java_lang_Double;
116                         o = builtin_new(c);
117                         target_fid = (*env)->GetFieldID(env, c, "value", "D");
118                         if (!target_fid)
119                                 break;
120                                    
121                         if (st)
122                                 SetDoubleField(env,o,target_fid, (*env)->GetStaticDoubleField(env, c, fid));
123                         else
124                                 SetDoubleField(env,o,target_fid, (*env)->GetDoubleField(env, (jobject) obj, fid));
125
126                         return (java_lang_Object *) o;
127
128                 case 'B':
129                         c = class_java_lang_Byte;
130                         o = builtin_new(c);
131                         target_fid = (*env)->GetFieldID(env, c, "value", "B");
132                         if (!target_fid)
133                                 break;
134                                    
135                         if (st)
136                                 SetByteField(env,o,target_fid, (*env)->GetStaticByteField(env, c, fid));
137                         else
138                                 SetByteField(env,o,target_fid, (*env)->GetByteField(env, (jobject) obj, fid));
139
140                         return (java_lang_Object *) o;
141
142                 case 'C':
143                         c = class_java_lang_Character;
144                         o = builtin_new(c);
145                         target_fid = (*env)->GetFieldID(env, c, "value", "C");
146                         if (!target_fid)
147                                 break;
148                                    
149                         if (st)
150                                 SetCharField(env,o,target_fid, (*env)->GetStaticCharField(env, c, fid));
151                         else
152                                 SetCharField(env,o,target_fid, (*env)->GetCharField(env, (jobject) obj, fid));
153
154                         return (java_lang_Object *) o;
155
156                 case 'S':
157                         c = class_java_lang_Short;
158                         o = builtin_new(c);
159                         target_fid = (*env)->GetFieldID(env, c, "value", "S");
160                         if (!target_fid)
161                                 break;
162                                    
163                         if (st)
164                                 SetShortField(env,o,target_fid, (*env)->GetStaticShortField(env, c, fid));
165                         else
166                                 SetShortField(env,o,target_fid, (*env)->GetShortField(env, (jobject) obj, fid));
167
168                         return (java_lang_Object *) o;
169
170                 case 'Z':
171                         c = class_java_lang_Boolean;
172                         o = builtin_new(c);
173                         target_fid = (*env)->GetFieldID(env, c, "value", "Z");
174                         if (!target_fid)
175                                 break;
176                                    
177                         if (st)
178                                 SetBooleanField(env,o,target_fid, (*env)->GetStaticBooleanField(env, c, fid));
179                         else
180                                 SetBooleanField(env,o,target_fid, (*env)->GetBooleanField(env, (jobject) obj, fid));
181
182                         return (java_lang_Object *) o;
183
184                 case '[':
185                 case 'L':
186                         if (st)
187                         /* static field */
188                                 return (java_lang_Object*) (*env)->GetStaticObjectField(env, c, fid);
189                         else
190                                 /* instance field */
191                                 return (java_lang_Object*) (*env)->GetObjectField(env, (jobject) obj, fid);
192                 }
193
194         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
195
196         return NULL;
197 }
198
199
200 /*
201  * Class:     java/lang/reflect/Field
202  * Method:    getBoolean
203  * Signature: (Ljava/lang/Object;)Z
204  */
205 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
206 {
207         jfieldID fid;
208
209         if (this->declaringClass && obj) {
210                 /* get the fieldid represented by the field-object */
211                 fid = class_findfield_approx((classinfo *) this->declaringClass,
212                                                                          javastring_toutf(this->name, false));
213
214                 if (fid)
215                         /* call the JNI-function to retrieve the field */ 
216                         return (*env)->GetBooleanField(env, (jobject) obj, fid);
217         }
218
219         /* raise exception */
220         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
221
222         return 0;
223 }
224
225
226 /*
227  * Class:     java/lang/reflect/Field
228  * Method:    getByte
229  * Signature: (Ljava/lang/Object;)B
230  */
231 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
232 {
233         jfieldID fid;
234
235         if (this->declaringClass && obj) {
236                 fid = class_findfield_approx((classinfo *) this->declaringClass,
237                                                                          javastring_toutf(this->name, false));
238
239                 if (fid)
240                         return (*env)->GetByteField(env, (jobject) obj, fid);
241         }
242
243         /* raise exception */
244         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
245
246         return 0;
247 }
248
249
250 /*
251  * Class:     java/lang/reflect/Field
252  * Method:    getChar
253  * Signature: (Ljava/lang/Object;)C
254  */
255 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
256 {
257         jfieldID fid;
258
259         if (this->declaringClass && obj) {
260                 fid = class_findfield_approx((classinfo *) this->declaringClass,
261                                                                          javastring_toutf(this->name, false));
262
263                 if (fid)
264                         return (*env)->GetCharField (env, (jobject) obj, fid);
265         }
266
267         /* raise exception */
268         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
269
270         return 0;
271 }
272
273
274 /*
275  * Class:     java/lang/reflect/Field
276  * Method:    getDouble
277  * Signature: (Ljava/lang/Object;)D
278  */
279 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
280 {
281         jfieldID fid;
282
283         if (this->declaringClass && obj) {
284                 fid = class_findfield_approx((classinfo *) this->declaringClass,
285                                                                          javastring_toutf(this->name, false));
286
287                 if (fid)
288                         return (*env)->GetDoubleField(env, (jobject) obj, fid);
289         }
290
291         /* raise exception */
292         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
293
294         return 0;
295 }
296
297
298 /*
299  * Class:     java/lang/reflect/Field
300  * Method:    getFloat
301  * Signature: (Ljava/lang/Object;)F
302  */
303 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
304 {
305         jfieldID fid;
306
307         if (this->declaringClass && obj) {
308                 fid = class_findfield_approx((classinfo *) this->declaringClass,
309                                                                          javastring_toutf(this->name, false));
310
311                 if (fid)
312                         return (*env)->GetFloatField(env, (jobject) obj, fid);
313         }
314
315         /* raise exception */
316         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
317
318         return 0;
319 }
320
321
322 /*
323  * Class:     java/lang/reflect/Field
324  * Method:    getInt
325  * Signature: (Ljava/lang/Object;)I
326  */
327 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *obj)
328 {
329         jfieldID fid;
330
331         if (this->declaringClass && obj) {
332                 fid = class_findfield_approx((classinfo *) this->declaringClass,
333                                                                          javastring_toutf(this->name, false));
334
335                 if (fid)
336                         return (*env)->GetIntField(env, (jobject) obj, fid);
337         }
338
339         /* raise exception */
340         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
341
342         return 0;
343 }
344
345
346 /*
347  * Class:     java/lang/reflect/Field
348  * Method:    getLong
349  * Signature: (Ljava/lang/Object;)J
350  */
351 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
352 {
353         jfieldID fid;
354
355         if (this->declaringClass && obj) {
356                 fid = class_findfield_approx((classinfo *) this->declaringClass,
357                                                                          javastring_toutf(this->name, false));
358
359                 if (fid)
360                         return (*env)->GetLongField(env, (jobject) obj, fid);
361         }
362
363         /* raise exception */
364         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
365
366         return 0;
367 }
368
369
370 /*
371  * Class:     java/lang/reflect/Field
372  * Method:    getShort
373  * Signature: (Ljava/lang/Object;)S
374  */
375 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj)
376 {
377         jfieldID fid;
378
379         if (this->declaringClass && obj) {
380                 fid = class_findfield_approx((classinfo *) this->declaringClass,
381                                                                          javastring_toutf(this->name, false));
382
383                 if (fid)
384                         return (*env)->GetShortField(env, (jobject) obj, fid);
385         }
386
387         /* raise exception */
388         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
389
390         return 0;
391 }
392
393
394 /*
395  * Class:     java/lang/reflect/Field
396  * Method:    set
397  * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
398  */
399 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, java_lang_Object *val)
400 {
401         jfieldID source_fid;  /* the field containing the value to be written */
402         jfieldID fid;         /* the field to be written */
403         classinfo *c;
404         int st = (this->flag & ACC_STATIC); /* true if the field is static */
405
406         fid = class_findfield_approx((classinfo *) this->declaringClass,
407                                                                  javastring_toutf(this->name, false));
408
409         if (val && (st || obj)) {
410
411                 c = val->header.vftbl->class;
412
413                 /* The fieldid is used to set the new value, for primitive types the value
414                    has to be retrieved from the wrapping object */  
415                 switch ((((classinfo *) this->declaringClass)->fields[this->slot]).descriptor->text[0]) {
416                 case 'I':
417                         /* illegal argument specified */
418                         if (c != class_java_lang_Integer)
419                                 break;
420                         /* determine the field to read the value */
421                         source_fid = (*env)->GetFieldID(env, c, "value", "I");
422                         if (!source_fid)
423                                 break;
424                                    
425                         /* set the new value */
426                         if (st)
427                         /* static field */
428                                 (*env)->SetStaticIntField(env, c, fid, GetIntField(env, (jobject) val, source_fid));
429                         else
430                                 /* instance field */
431                                 (*env)->SetIntField(env, (jobject) obj, fid, GetIntField(env, (jobject) val, source_fid));
432
433                         return;
434
435                 case 'J':
436                         if (c != class_java_lang_Long)
437                                 break;
438                         source_fid = (*env)->GetFieldID(env, c, "value", "J");
439                         if (!source_fid)
440                                 break;
441                                    
442                         if (st)
443                                 (*env)->SetStaticLongField(env, c, fid, GetLongField(env, (jobject) val, source_fid));
444                         else
445                                 (*env)->SetLongField(env, (jobject) obj, fid, GetLongField(env, (jobject) val, source_fid));
446
447                         return;
448
449                 case 'F':
450                         if (c != class_java_lang_Float)
451                                 break;
452                         source_fid = (*env)->GetFieldID(env, c, "value", "F");
453                         if (!source_fid)
454                                 break;
455                                    
456                         if (st)
457                                 (*env)->SetStaticFloatField(env, c, fid, GetFloatField(env, (jobject) val, source_fid));
458                         else
459                                 (*env)->SetFloatField(env, (jobject) obj, fid, GetFloatField(env, (jobject) val, source_fid));
460
461                         return;
462
463                 case 'D':
464                         if (c != class_java_lang_Double)
465                                 break;
466                         source_fid = (*env)->GetFieldID(env, c, "value", "D");
467                         if (!source_fid) break;
468                                    
469                         if (st)
470                                 (*env)->SetStaticDoubleField(env, c, fid, GetDoubleField(env,(jobject) val,source_fid));
471                         else
472                                 (*env)->SetDoubleField(env, (jobject) obj, fid, GetDoubleField(env,(jobject) val,source_fid));
473
474                         return;
475
476                 case 'B':
477                         if (c != class_java_lang_Byte)
478                                 break;
479                         source_fid = (*env)->GetFieldID(env, c, "value", "B");
480                         if (!source_fid)
481                                 break;
482                                    
483                         if (st)
484                                 (*env)->SetStaticByteField(env, c, fid, GetByteField(env, (jobject) val, source_fid));
485                         else
486                                 (*env)->SetByteField(env, (jobject) obj, fid, GetByteField(env, (jobject) val, source_fid));
487
488                         return;
489
490                 case 'C':
491                         if (c != class_java_lang_Character)
492                                 break;
493                         source_fid = (*env)->GetFieldID(env, c, "value", "C");
494                         if (!source_fid)
495                                 break;
496                                    
497                         if (st)
498                                 (*env)->SetStaticCharField(env, c, fid, GetCharField(env, (jobject) val, source_fid));
499                         else
500                                 (*env)->SetCharField(env, (jobject) obj, fid, GetCharField(env, (jobject) val, source_fid));
501
502                         return;
503
504                 case 'S':
505                         if (c != class_java_lang_Short)
506                                 break;
507                         source_fid = (*env)->GetFieldID(env, c, "value", "S");
508                         if (!source_fid)
509                                 break;
510                                    
511                         if (st)
512                                 (*env)->SetStaticShortField(env, c, fid, GetShortField(env, (jobject) val, source_fid));
513                         else
514                                 (*env)->SetShortField(env, (jobject) obj, fid, GetShortField(env, (jobject) val, source_fid));
515
516                         return;
517
518                 case 'Z':
519                         if (c != class_java_lang_Boolean)
520                                 break;
521                         source_fid = (*env)->GetFieldID(env, c, "value", "Z");
522                         if (!source_fid)
523                                 break;
524                                    
525                         if (st)
526                                 (*env)->SetStaticBooleanField(env, c, fid, GetBooleanField(env, (jobject) val, source_fid));
527                         else
528                                 (*env)->SetBooleanField(env, (jobject) obj, fid, GetBooleanField(env, (jobject) val, source_fid));
529
530                         return;
531
532                 case '[':
533                 case 'L':
534                         if (st)
535                                 (*env)->SetStaticObjectField(env, c, fid, (jobject) val);
536                         else
537                                 (*env)->SetObjectField(env, (jobject) obj, fid, (jobject) val);
538
539                         return;
540                 }
541         }
542
543         /* raise exception */
544         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
545 }
546
547
548 /*
549  * Class:     java/lang/reflect/Field
550  * Method:    setBoolean
551  * Signature: (Ljava/lang/Object;Z)V
552  */
553 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
554 {
555         jfieldID fid;
556
557         if (this->declaringClass && obj) {
558                 fid = class_findfield_approx((classinfo *) this->declaringClass,
559                                                                          javastring_toutf(this->name, false));
560
561                 if (fid) {
562                         (*env)->SetBooleanField(env, (jobject) obj, fid, val);
563                         return;
564                 }
565         }
566
567         /* raise exception */
568         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
569 }
570
571
572 /*
573  * Class:     java/lang/reflect/Field
574  * Method:    setByte
575  * Signature: (Ljava/lang/Object;B)V
576  */
577 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
578 {
579         jfieldID fid;
580
581         if (this->declaringClass && obj) {
582                 fid = class_findfield_approx((classinfo *) this->declaringClass,
583                                                                          javastring_toutf(this->name, false));
584
585                 if (fid) {
586                         (*env)->SetByteField(env, (jobject) obj, fid, val);
587                         return;
588                 }
589         }
590
591         /* raise exception */
592         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
593 }
594
595
596 /*
597  * Class:     java/lang/reflect/Field
598  * Method:    setChar
599  * Signature: (Ljava/lang/Object;C)V
600  */
601 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
602 {
603         jfieldID fid;
604
605         if (this->declaringClass && obj) {
606                 fid = class_findfield_approx((classinfo *) this->declaringClass,
607                                                                          javastring_toutf(this->name, false));
608
609                 if (fid) {
610                         (*env)->SetCharField(env, (jobject) obj, fid, val);
611                         return;
612                 }
613         }
614
615         /* raise exception */
616         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
617 }
618
619
620 /*
621  * Class:     java/lang/reflect/Field
622  * Method:    setDouble
623  * Signature: (Ljava/lang/Object;D)V
624  */
625 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, double val)
626 {
627         jfieldID fid;
628
629         if (this->declaringClass && obj) {
630                 fid = class_findfield_approx((classinfo *) this->declaringClass,
631                                                                          javastring_toutf(this->name, false));
632
633                 if (fid) {
634                         (*env)->SetDoubleField(env, (jobject) obj, fid, val);
635                         return;
636                 } 
637         }
638
639         /* raise exception */
640         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
641 }
642
643
644 /*
645  * Class:     java/lang/reflect/Field
646  * Method:    setFloat
647  * Signature: (Ljava/lang/Object;F)V
648  */
649 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, float val)
650 {
651         jfieldID fid;
652
653         if (this->declaringClass && obj) {
654                 fid = class_findfield_approx((classinfo *) this->declaringClass,
655                                                                          javastring_toutf(this->name, false));
656
657                 if (fid) {
658                         (*env)->SetFloatField(env, (jobject) obj, fid, val);
659                         return;
660                 }
661         }
662
663         /* raise exception */
664         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
665 }
666
667
668 /*
669  * Class:     java/lang/reflect/Field
670  * Method:    setInt
671  * Signature: (Ljava/lang/Object;I)V
672  */
673 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
674 {
675         jfieldID fid;
676
677         if (this->declaringClass && obj) {
678                 fid = class_findfield_approx((classinfo *) this->declaringClass,
679                                                                          javastring_toutf(this->name, false));
680
681                 if (fid) {
682                         (*env)->SetIntField(env, (jobject) obj, fid, val);
683                         return;
684                 }
685         }
686
687         /* raise exception */
688         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
689 }
690
691
692 /*
693  * Class:     java/lang/reflect/Field
694  * Method:    setLong
695  * Signature: (Ljava/lang/Object;J)V
696  */
697 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s8 val)
698 {
699         jfieldID fid;
700
701         if (this->declaringClass && obj) {
702                 fid = class_findfield_approx((classinfo *) this->declaringClass,
703                                                                          javastring_toutf(this->name, false));
704
705                 if (fid) {
706                         (*env)->SetLongField(env, (jobject) obj, fid, val);
707                         return;
708                 }
709         }
710
711         /* raise exception */
712         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
713 }
714
715
716 /*
717  * Class:     java/lang/reflect/Field
718  * Method:    setShort
719  * Signature: (Ljava/lang/Object;S)V
720  */
721 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *obj, s4 val)
722 {
723         jfieldID fid;
724
725         if (this->declaringClass && obj) {
726                 fid = class_findfield_approx((classinfo *) this->declaringClass,
727                                                                          javastring_toutf(this->name, false));
728
729                 if (fid) {
730                         (*env)->SetShortField(env, (jobject) obj, fid, val);
731                         return;
732                 }
733         }
734
735         /* raise exception */
736         *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
737 }
738
739
740 /*
741  * Class:     java_lang_reflect_Field
742  * Method:    getType
743  * Signature: ()Ljava/lang/Class;
744  */
745 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
746 {
747         utf *desc = (((classinfo *) this->declaringClass)->fields[this->slot]).descriptor;
748
749         if (!desc)
750                 return NULL;
751
752         return (java_lang_Class *) class_from_descriptor(desc->text, utf_end(desc), NULL, CLASSLOAD_LOAD);
753 }
754
755
756 /*
757  * Class:     java_lang_reflect_Field
758  * Method:    getModifiers
759  * Signature: ()I
760  */
761 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
762 {
763         return (((classinfo *) this->declaringClass)->fields[this->slot]).flags;
764 }
765
766
767 /*
768  * These are local overrides for various environment variables in Emacs.
769  * Please do not remove this and leave it at the end of the file, where
770  * Emacs will automagically detect them.
771  * ---------------------------------------------------------------------
772  * Local variables:
773  * mode: c
774  * indent-tabs-mode: t
775  * c-basic-offset: 4
776  * tab-width: 4
777  * End:
778  */