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