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

Method field

rust/src/api/mod.rs:911–947  ·  view source on GitHub ↗

Retrieves the field `field_name` of a created `Instance`.

(&self, instance: &Instance, field_name: &str)

Source from the content-addressed store, hash-verified

909
910 /// Retrieves the field `field_name` of a created `Instance`.
911 pub fn field(&self, instance: &Instance, field_name: &str) -> errors::Result<Instance> {
912 debug(&format!(
913 "Retrieving field {} of class {}",
914 field_name, instance.class_name
915 ));
916 unsafe {
917 // First argument: create a jstring to pass as argument for the field_name
918 let field_name_jstring: jstring =
919 jni_utils::global_jobject_from_str(field_name, self.jni_env)?;
920
921 // Call the method of the instance
922 let java_instance = (opt_to_res(cache::get_jni_call_object_method())?)(
923 self.jni_env,
924 instance.jinstance,
925 cache::get_field_method()?,
926 field_name_jstring,
927 );
928
929 // Check for exceptions before creating the globalref
930 Self::do_return(self.jni_env, ())?;
931
932 let java_instance_global_instance =
933 jni_utils::create_global_ref_from_local_ref(java_instance, self.jni_env)?;
934 // Prevent memory leaks from the created local references
935 jni_utils::delete_java_ref(self.jni_env, field_name_jstring);
936
937 // Create and return the Instance
938 Self::do_return(
939 self.jni_env,
940 Instance {
941 jinstance: java_instance_global_instance,
942 class_name: cache::UNKNOWN_FOR_RUST.to_string(),
943 skip_deleting_jobject: false,
944 },
945 )
946 }
947 }
948
949 /// Retrieves the field `field_name` of a static class.
950 pub fn static_class_field(

Callers

nothing calls this directly

Calls 9

debugFunction · 0.85
global_jobject_from_strFunction · 0.85
opt_to_resFunction · 0.85
get_field_methodFunction · 0.85
do_returnFunction · 0.85
delete_java_refFunction · 0.85
to_stringMethod · 0.80

Tested by

no test coverage detected