• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::{
2     descriptors::Desc,
3     errors::*,
4     objects::{JClass, JObject, JThrowable, JValue},
5     strings::JNIString,
6     JNIEnv,
7 };
8 
9 const DEFAULT_EXCEPTION_CLASS: &str = "java/lang/RuntimeException";
10 
11 impl<'a, 'c, C, M> Desc<'a, JThrowable<'a>> for (C, M)
12 where
13     C: Desc<'a, JClass<'c>>,
14     M: Into<JNIString>,
15 {
lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>>16     fn lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>> {
17         let jmsg: JObject = env.new_string(self.1)?.into();
18         let obj: JThrowable = env
19             .new_object(self.0, "(Ljava/lang/String;)V", &[JValue::from(jmsg)])?
20             .into();
21         Ok(obj)
22     }
23 }
24 
25 impl<'a> Desc<'a, JThrowable<'a>> for Exception {
lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>>26     fn lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>> {
27         (self.class, self.msg).lookup(env)
28     }
29 }
30 
31 impl<'a, 'b> Desc<'a, JThrowable<'a>> for &'b str {
lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>>32     fn lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>> {
33         (DEFAULT_EXCEPTION_CLASS, self).lookup(env)
34     }
35 }
36 
37 impl<'a> Desc<'a, JThrowable<'a>> for String {
lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>>38     fn lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>> {
39         (DEFAULT_EXCEPTION_CLASS, self).lookup(env)
40     }
41 }
42 
43 impl<'a> Desc<'a, JThrowable<'a>> for JNIString {
lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>>44     fn lookup(self, env: &JNIEnv<'a>) -> Result<JThrowable<'a>> {
45         (DEFAULT_EXCEPTION_CLASS, self).lookup(env)
46     }
47 }
48