(
ia: &InvocationArg,
jni_env: *mut JNIEnv,
create_global: bool,
)
| 130 | } |
| 131 | |
| 132 | pub(crate) fn invocation_arg_jobject_from_java( |
| 133 | ia: &InvocationArg, |
| 134 | jni_env: *mut JNIEnv, |
| 135 | create_global: bool, |
| 136 | ) -> errors::Result<jobject> { |
| 137 | unsafe { |
| 138 | let (class_name, jinstance) = match ia { |
| 139 | _s @ &InvocationArg::Rust { .. } => panic!("Called invocation_arg_jobject_from_java for an InvocationArg that is created by Rust. Please consider opening a bug to the developers."), |
| 140 | &InvocationArg::Java { ref class_name, ref instance, .. } | &InvocationArg::RustBasic { ref class_name, ref instance, .. } => { |
| 141 | debug(&format!("Creating jobject from Java for class {}", class_name)); |
| 142 | (class_name.to_owned(), instance.jinstance) |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | debug(&format!( |
| 147 | "Calling the InvocationArg constructor for class '{}'", |
| 148 | class_name |
| 149 | )); |
| 150 | |
| 151 | let class_name_jstring = global_jobject_from_str(&class_name, jni_env)?; |
| 152 | |
| 153 | let inv_arg_instance = (opt_to_res(cache::get_jni_new_object())?)( |
| 154 | jni_env, |
| 155 | cache::get_invocation_arg_class()?, |
| 156 | cache::get_inv_arg_java_constructor_method()?, |
| 157 | // First argument: class_name |
| 158 | class_name_jstring, |
| 159 | // Second argument: Instance instance |
| 160 | jinstance, |
| 161 | ); |
| 162 | |
| 163 | // Check for exceptions |
| 164 | Jvm::do_return(jni_env, ())?; |
| 165 | delete_java_ref(jni_env, class_name_jstring); |
| 166 | |
| 167 | if create_global { |
| 168 | Ok(create_global_ref_from_local_ref(inv_arg_instance, jni_env)?) |
| 169 | } else { |
| 170 | Ok(inv_arg_instance) |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | pub fn create_global_ref_from_local_ref( |
| 176 | local_ref: jobject, |
no test coverage detected