MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / invocation_arg_jobject_from_java

Function invocation_arg_jobject_from_java

rust/src/jni_utils.rs:132–173  ·  view source on GitHub ↗
(
    ia: &InvocationArg,
    jni_env: *mut JNIEnv,
    create_global: bool,
)

Source from the content-addressed store, hash-verified

130}
131
132pub(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
175pub fn create_global_ref_from_local_ref(
176 local_ref: jobject,

Callers 2

Calls 9

debugFunction · 0.85
global_jobject_from_strFunction · 0.85
opt_to_resFunction · 0.85
get_jni_new_objectFunction · 0.85
get_invocation_arg_classFunction · 0.85
do_returnFunction · 0.85
delete_java_refFunction · 0.85

Tested by

no test coverage detected