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

Function invocation_arg_jobject_from_rust_basic

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

Source from the content-addressed store, hash-verified

79}
80
81pub(crate) fn invocation_arg_jobject_from_rust_basic(
82 ia: &InvocationArg,
83 jni_env: *mut JNIEnv,
84 create_global: bool,
85) -> errors::Result<jobject> {
86 unsafe {
87 let (class_name, jinstance) = match ia {
88 _s @ &InvocationArg::Java { .. } => {
89 panic!("Called invocation_arg_jobject_from_rust_basic for an InvocationArg that contains an object from Java. Please consider opening a bug to the developers.")
90 }
91 _s @ &InvocationArg::Rust { .. } => {
92 panic!("Called invocation_arg_jobject_from_rust_basic for an InvocationArg that contains a serialized object. Please consider opening a bug to the developers.")
93 }
94 InvocationArg::RustBasic {
95 class_name,
96 instance,
97 ..
98 } => {
99 debug(&format!(
100 "Creating jobject from Rust basic for class {}",
101 class_name
102 ));
103 (class_name.to_owned(), instance.jinstance)
104 }
105 };
106 debug(&format!(
107 "Calling the InvocationArg constructor with '{}'",
108 class_name
109 ));
110 let class_name_jstring = global_jobject_from_str(&class_name, jni_env)?;
111
112 let inv_arg_instance = (opt_to_res(cache::get_jni_new_object())?)(
113 jni_env,
114 cache::get_invocation_arg_class()?,
115 cache::get_inv_arg_basic_rust_constructor_method()?,
116 // First argument: class_name
117 class_name_jstring,
118 // Second argument: Instance instance
119 jinstance,
120 );
121
122 delete_java_ref(jni_env, class_name_jstring);
123
124 if create_global {
125 Ok(create_global_ref_from_local_ref(inv_arg_instance, jni_env)?)
126 } else {
127 Ok(inv_arg_instance)
128 }
129 }
130}
131
132pub(crate) fn invocation_arg_jobject_from_java(
133 ia: &InvocationArg,

Callers 2

Calls 8

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
delete_java_refFunction · 0.85

Tested by

no test coverage detected