-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathJNIField.swift
344 lines (301 loc) · 23.7 KB
/
JNIField.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//
// JNIField.swift
// SwiftJava
//
// Created by John Holdsworth on 17/07/2016.
// Copyright (c) 2016 John Holdsworth. All rights reserved.
//
// Static functions related to accessing static and instance fields
//
public class JNIField {
static func getStaticFieldID( _ fieldName: UnsafePointer<Int8>, _ fieldSig: UnsafePointer<Int8>,
_ fieldCache: UnsafeMutablePointer<jfieldID?>,
_ className: UnsafePointer<Int8>, _ classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) {
JNI.CachedFindClass( className, classCache, file, line )
fieldCache.pointee = JNI.api.GetStaticFieldID( JNI.env, classCache.pointee, fieldName, fieldSig )
if fieldCache.pointee == nil {
JNI.report( "Failed to lookup static field \(String(cString: fieldName))")
}
}
static func getFieldID( _ fieldName: UnsafePointer<Int8>, _ fieldSig: UnsafePointer<Int8>,
_ fieldCache: UnsafeMutablePointer<jfieldID?>, _ object: jobject?,
_ locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
let clazz = JNI.GetObjectClass( object, locals, file, line )
fieldCache.pointee = JNI.api.GetFieldID( JNI.env, clazz, fieldName, fieldSig )
if fieldCache.pointee == nil {
JNI.report( "Failed to lookup field \(String(cString: fieldName))")
}
}
public static func GetStaticObjectField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jobject? {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticObjectField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticBooleanField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jboolean {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticBooleanField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticByteField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jbyte {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticByteField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticCharField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jchar {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticCharField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticShortField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jshort {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticShortField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticIntField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jint {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticIntField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticLongField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jlong {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticLongField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticFloatField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jfloat {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticFloatField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetStaticDoubleField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>,
_ file: StaticString = #file, _ line: Int = #line ) -> jdouble {
var locals = [jobject]()
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
return JNI.check( JNI.api.GetStaticDoubleField( JNI.env, classCache.pointee, fieldCache.pointee ), &locals, file, line )
}
public static func GetBooleanField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jboolean {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetBooleanField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetByteField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jbyte {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetByteField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetCharField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jchar {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetCharField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetShortField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jshort {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetShortField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetIntField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jint {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetIntField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetLongField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jlong {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetLongField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetFloatField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jfloat {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetFloatField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetDoubleField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jdouble {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetDoubleField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func GetObjectField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?,
_ file: StaticString = #file, _ line: Int = #line ) -> jobject? {
var locals = [jobject]()
getFieldID( fieldName, fieldType, fieldCache, object, &locals, file, line )
return JNI.check( JNI.api.GetObjectField( JNI.env, object, fieldCache.pointee ), &locals, file, line )
}
public static func SetStaticBooleanField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jboolean,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticBooleanField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticByteField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jbyte,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticByteField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticCharField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jchar,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticCharField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticShortField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jshort,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticShortField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticIntField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jint,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticIntField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticLongField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jlong,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticLongField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticFloatField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jfloat,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticFloatField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticDoubleField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jdouble,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticDoubleField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetStaticObjectField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, className: UnsafePointer<Int8>,
classCache: UnsafeMutablePointer<jclass?>, value: jobject?,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getStaticFieldID( fieldName, fieldType, fieldCache, className, classCache, file, line )
JNI.check( JNI.api.SetStaticObjectField( JNI.env, classCache.pointee, fieldCache.pointee, value ), locals, file, line )
}
public static func SetBooleanField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jboolean,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetBooleanField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetByteField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jbyte,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetByteField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetCharField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jchar,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetCharField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetShortField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jshort,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetShortField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetIntField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jint,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetIntField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetLongField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jlong,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetLongField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetFloatField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jfloat,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetFloatField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetDoubleField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jdouble,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetDoubleField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
public static func SetObjectField( fieldName: UnsafePointer<Int8>, fieldType: UnsafePointer<Int8>,
fieldCache: UnsafeMutablePointer<jfieldID?>, object: jobject?, value: jobject?,
locals: UnsafeMutablePointer<[jobject]>,
_ file: StaticString = #file, _ line: Int = #line ) {
getFieldID( fieldName, fieldType, fieldCache, object, locals, file, line )
JNI.check( JNI.api.SetObjectField( JNI.env, object, fieldCache.pointee, value ), locals, file, line )
}
}