1 #include <jni.h>
2 #include <stdlib.h>
3 #include "mixedjava.h"
4
5 //
6 // Instance Field Access
7 //
8
9
10 /*
11 * Class: MixedJava
12 * Method: set_field_f1
13 * Signature: (I)V
14 */
15 JNIEXPORT void JNICALL
Java_MixedJava_set_1field_1f1(JNIEnv * env,jobject obj,jint val)16 Java_MixedJava_set_1field_1f1 (JNIEnv *env, jobject obj, jint val){
17 jclass obj_class = (*env)->GetObjectClass(env, obj);
18 jfieldID obj_field1 = (*env)->GetFieldID(env, obj_class, "f1", "I");
19 (*env)->SetIntField(env, obj, obj_field1, val);
20 }
21
22 /*
23 * Class: MixedJava
24 * Method: get_field_f1
25 * Signature: ()I
26 */
27 JNIEXPORT jint JNICALL
Java_MixedJava_get_1field_1f1(JNIEnv * env,jobject obj)28 Java_MixedJava_get_1field_1f1(JNIEnv *env, jobject obj){
29 jclass obj_class = (*env)->GetObjectClass(env, obj);
30 jfieldID obj_field1 = (*env)->GetFieldID(env, obj_class, "f1", "I");
31 jint value = (*env)->GetIntField(env, obj, obj_field1);
32 return value;
33 }
34
35 /*
36 * Class: MixedJava
37 * Method: get_field_f2
38 * Signature: ()I
39 */
40 JNIEXPORT jint JNICALL
Java_MixedJava_get_1field_1f2(JNIEnv * env,jobject obj)41 Java_MixedJava_get_1field_1f2(JNIEnv *env, jobject obj){
42 jclass obj_class = (*env)->GetObjectClass(env, obj);
43 jfieldID obj_field1 = (*env)->GetFieldID(env, obj_class, "f2", "I");
44 jint value = (*env)->GetIntField(env, obj, obj_field1);
45 return value;
46 }
47
48 //
49 // Static Field Access
50 //
51
52 /*
53 * Class: MixedJava
54 * Method: get_static_field
55 * Signature: ()I
56 */
57 JNIEXPORT jint JNICALL
Java_MixedJava_get_1static_1field(JNIEnv * env,jclass cls)58 Java_MixedJava_get_1static_1field(JNIEnv *env, jclass cls){
59 jfieldID field_id = (*env)->GetStaticFieldID(env, cls, "s1", "I");
60 jint value = (*env)->GetStaticIntField(env, cls, field_id);
61 return value;
62 }
63
64 /*
65 * Class: MixedJava
66 * Method: set_static_field
67 * Signature: (I)V
68 */
69 JNIEXPORT void JNICALL
Java_MixedJava_set_1static_1field(JNIEnv * env,jclass cls,jint val)70 Java_MixedJava_set_1static_1field(JNIEnv *env, jclass cls, jint val){
71 jfieldID field_id = (*env)->GetStaticFieldID(env, cls, "s2", "I");
72 (*env)->SetStaticIntField(env, cls, field_id, val);
73 }
74
75 /*
76 * Class: MixedJava
77 * Method: get_static_field_access_subclass
78 * Signature: ()I
79 */
80 JNIEXPORT jint JNICALL
Java_MixedJava_get_1static_1field_1access_1subclass(JNIEnv * env,jclass cls)81 Java_MixedJava_get_1static_1field_1access_1subclass(JNIEnv *env, jclass cls){
82 jclass sub_cls = (*env)->FindClass(env, "SubMixedJava");
83
84 jfieldID field_id = (*env)->GetStaticFieldID(env, sub_cls, "s2", "I");
85 jint value = (*env)->GetStaticIntField(env, sub_cls, field_id);
86
87 jfieldID field_id_2 = (*env)->GetStaticFieldID(env, sub_cls, "s1", "I");
88 (*env)->SetStaticIntField(env, sub_cls, field_id_2, 10);
89
90 jfieldID field_id_3 = (*env)->GetStaticFieldID(env, sub_cls, "s3", "I");
91 (*env)->SetStaticIntField(env, sub_cls, field_id_3, 30);
92 return value;
93 }
94