-
Notifications
You must be signed in to change notification settings - Fork 6
/
JNIMethods.swift.gyb
120 lines (91 loc) · 4.3 KB
/
JNIMethods.swift.gyb
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
//===--- JNIMethods.swift.gyb ---------------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import CJNI
%{
jTypes = [
('Void', 'Void'), # returning Void is also valid in swift
('Object', 'jobject'),
('Boolean', 'jboolean'),
('Byte', 'jbyte'),
('Char', 'jchar'),
('Short', 'jshort'),
('Int', 'jint'),
('Long', 'jlong'),
('Float', 'jfloat'),
('Double', 'jdouble')
]
}%
public extension JNI {
% # Standard Java method calls
public func GetMethodID(targetClass: jclass, methodName name: String, methodSignature sig: String) -> jmethodID? {
let env = self._env
let result = env.memory.memory.GetMethodID(env, targetClass, name, sig)
return (result == nil) ? .None : result
}
%for (TypeName, type) in jTypes:
public func Call${TypeName}Method(obj: jobject, _ methodID: jmethodID, _ args: jvalue...) -> ${type} {
return Call${TypeName}MethodA(obj, _ methodID: methodID, _ args: args)
}
@available(*, unavailable, message="CVaListPointers are not supported, use `Call${TypeName}Method` or `Call${TypeName}MethodA` instead")
public func Call${TypeName}MethodV(obj: jobject, _ methodID: jmethodID, _ args: CVaListPointer) -> ${type} {
// let env = self._env
// return env.memory.memory.Call${TypeName}MethodV(env, obj, methodID, args)
return ${type}()
}
public func Call${TypeName}MethodA(obj: jobject, _ methodID: jmethodID, _ args: [jvalue]) -> ${type} {
let env = self._env
var mutableArgs = args
return env.memory.memory.Call${TypeName}MethodA(env, obj, methodID, &mutableArgs)
}
%end #standard methods
% # Nonvirtual Java method calls
%for (TypeName, type) in jTypes:
public func CallNonvirtual${TypeName}Method(obj: jobject, _ targetClass: jclass, _ methodID: jmethodID, _ args: jvalue...) -> ${type} {
return self.CallNonvirtual${TypeName}MethodA(obj, _ targetClass: targetClass, _ methodID: methodID, _ args: args)
}
@available(*, unavailable, message="CVaListPointers are not supported, use `CallNonvirtual${TypeName}Method` or `CallNonvirtual${TypeName}MethodA` instead")
public func CallNonvirtual${TypeName}MethodV(obj: jobject, _ targetClass: jclass, _ methodID: jmethodID, _ args: CVaListPointer) -> ${type} {
// let env = self._env
// return env.memory.memory.CallNonvirtual${TypeName}MethodV(env, obj, methodID, args)
return ${type}()
}
public func CallNonvirtual${TypeName}MethodA(obj: jobject, _ targetClass: jclass, _ methodID: jmethodID, _ args: [jvalue]) -> ${type} {
let env = self._env
var mutableArgs = args
return env.memory.memory.CallNonvirtual${TypeName}MethodA(env, obj, targetClass, methodID, &mutableArgs)
}
%end #nonvirtual methods
%# Static Java method calls
public func GetStaticMethodID(targetClass: jclass, _ name: String, _ sig: String) -> jmethodID {
let env = self._env
return env.memory.memory.GetStaticMethodID(env, targetClass, name, sig)
}
%for (TypeName, type) in jTypes:
public func CallStatic${TypeName}Method(targetClass: jclass, _ methodID: jmethodID, _ args: jvalue...) -> ${type} {
return CallStatic${TypeName}MethodA(targetClass, _ methodID: methodID, _ args: args)
}
@available(*, unavailable, message="CVaListPointers are not supported, use `CallStatic${TypeName}Method` or `CallStatic${TypeName}MethodA` instead")
public func CallStatic${TypeName}MethodV(targetClass: jclass, _ methodID: jmethodID, _ args: CVaListPointer) -> ${type} {
// let env = self._env
// return env.memory.memory.CallStatic${TypeName}MethodV(env, class, methodID, args)
return ${type}()
}
public func CallStatic${TypeName}MethodA(targetClass: jclass, _ methodID: jmethodID, _ args: [jvalue]) -> ${type} {
let env = self._env
var mutableArgs = args
return env.memory.memory.CallStatic${TypeName}MethodA(env, targetClass, methodID, &mutableArgs)
}
%end #static methods
}
// ${'Local Variables'}:
// eval: (read-only-mode 1)
// End: