oo_bindgen/backend/java/jni/conversion/
jni_java_type.rs

1use crate::model::*;
2
3/// The string argument is not used in `call_method_unchecked` in the jni crate
4const OBJECT_TYPE: &str = "jni::signature::JavaType::Object(String::new())";
5
6pub(crate) trait JniJavaType {
7    fn jni_java_type(&self) -> &'static str;
8}
9
10impl JniJavaType for Primitive {
11    fn jni_java_type(&self) -> &'static str {
12        match self {
13            Primitive::Bool => {
14                "jni::signature::JavaType::Primitive(jni::signature::Primitive::Boolean)"
15            }
16            Primitive::U8 => OBJECT_TYPE,
17            Primitive::S8 => "jni::signature::JavaType::Primitive(jni::signature::Primitive::Byte)",
18            Primitive::U16 => OBJECT_TYPE,
19            Primitive::S16 => {
20                "jni::signature::JavaType::Primitive(jni::signature::Primitive::Short)"
21            }
22            Primitive::U32 => OBJECT_TYPE,
23            Primitive::S32 => "jni::signature::JavaType::Primitive(jni::signature::Primitive::Int)",
24            Primitive::U64 => OBJECT_TYPE,
25            Primitive::S64 => {
26                "jni::signature::JavaType::Primitive(jni::signature::Primitive::Long)"
27            }
28            Primitive::Float => {
29                "jni::signature::JavaType::Primitive(jni::signature::Primitive::Float)"
30            }
31            Primitive::Double => {
32                "jni::signature::JavaType::Primitive(jni::signature::Primitive::Double)"
33            }
34        }
35    }
36}
37
38impl JniJavaType for DurationType {
39    fn jni_java_type(&self) -> &'static str {
40        OBJECT_TYPE
41    }
42}
43
44impl JniJavaType for EnumHandle {
45    fn jni_java_type(&self) -> &'static str {
46        OBJECT_TYPE
47    }
48}
49
50impl JniJavaType for BasicType {
51    fn jni_java_type(&self) -> &'static str {
52        match self {
53            BasicType::Primitive(x) => x.jni_java_type(),
54            BasicType::Duration(x) => x.jni_java_type(),
55            BasicType::Enum(x) => x.jni_java_type(),
56        }
57    }
58}
59
60impl JniJavaType for StringType {
61    fn jni_java_type(&self) -> &'static str {
62        OBJECT_TYPE
63    }
64}
65
66impl JniJavaType for AsynchronousInterface {
67    fn jni_java_type(&self) -> &'static str {
68        OBJECT_TYPE
69    }
70}
71
72impl JniJavaType for UniversalOr<FunctionArgStructField> {
73    fn jni_java_type(&self) -> &'static str {
74        OBJECT_TYPE
75    }
76}
77
78impl JniJavaType for UniversalStructHandle {
79    fn jni_java_type(&self) -> &'static str {
80        OBJECT_TYPE
81    }
82}
83
84impl JniJavaType for FunctionArgStructField {
85    fn jni_java_type(&self) -> &'static str {
86        match self {
87            FunctionArgStructField::Basic(x) => x.jni_java_type(),
88            FunctionArgStructField::String(x) => x.jni_java_type(),
89            FunctionArgStructField::Interface(x) => x.jni_java_type(),
90            FunctionArgStructField::Struct(x) => x.jni_java_type(),
91        }
92    }
93}
94
95impl JniJavaType for UniversalStructField {
96    fn jni_java_type(&self) -> &'static str {
97        match self {
98            UniversalStructField::Basic(x) => x.jni_java_type(),
99            UniversalStructField::Struct(x) => x.jni_java_type(),
100            UniversalStructField::String(x) => x.jni_java_type(),
101        }
102    }
103}
104
105impl JniJavaType for CallbackReturnValue {
106    fn jni_java_type(&self) -> &'static str {
107        match self {
108            CallbackReturnValue::Basic(x) => x.jni_java_type(),
109            CallbackReturnValue::Struct(x) => x.jni_java_type(),
110        }
111    }
112}
113
114impl JniJavaType for OptionalReturnType<CallbackReturnValue, Validated> {
115    fn jni_java_type(&self) -> &'static str {
116        match self.get_value() {
117            None => "jni::signature::JavaType::Primitive(jni::signature::Primitive::Void)",
118            Some(x) => x.jni_java_type(),
119        }
120    }
121}