1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use core::ops::Deref;
use swim_jvm_sys::{jsize, jarray, jvalue};
use crate::error::Result;
use crate::object::JObject;
use crate::env::JEnv;
use crate::convert::{FromJava, IntoJava, TryFromJava, TryIntoJava};

#[derive(Clone, Copy)]
pub struct JArray {
    object: JObject,
}

unsafe impl Send for JArray {}
unsafe impl Sync for JArray {}

impl JArray {
    #[inline]
    pub fn get_env(&self) -> &JEnv {
        self.object.get_env()
    }

    #[inline]
    pub fn len(&self) -> jsize {
        self.get_env().get_array_length(self)
    }
}

impl Deref for JArray {
    type Target = JObject;

    #[inline]
    fn deref(&self) -> &JObject {
        &self.object
    }
}

impl FromJava<jarray> for JArray {
    #[inline]
    fn from_java(env: &JEnv, string: jarray) -> Self {
        Self { object: JObject::from_java(env, string) }
    }
}

impl TryFromJava<jarray> for JArray {
    #[inline]
    fn try_from_java(env: &JEnv, string: jarray) -> Result<Self> {
        Ok(Self::from_java(env, string))
    }
}

impl IntoJava<jarray> for JArray {
    #[inline]
    fn into_java(self, _env: &JEnv) -> jarray {
        self.object.into()
    }
}

impl<'a> IntoJava<jarray> for &'a JArray {
    #[inline]
    fn into_java(self, _env: &JEnv) -> jarray {
        self.object.into()
    }
}

impl TryIntoJava<jarray> for JArray {
    #[inline]
    fn try_into_java(self, _env: &JEnv) -> Result<jarray> {
        Ok(self.object.into())
    }
}

impl<'a> TryIntoJava<jarray> for &'a JArray {
    #[inline]
    fn try_into_java(self, _env: &JEnv) -> Result<jarray> {
        Ok(self.object.into())
    }
}

impl From<JObject> for JArray {
    #[inline]
    fn from(object: JObject) -> JArray {
        JArray { object: object }
    }
}

impl Into<JObject> for JArray {
    #[inline]
    fn into(self) -> JObject {
        self.object
    }
}

impl<'a> Into<JObject> for &'a JArray {
    #[inline]
    fn into(self) -> JObject {
        self.object
    }
}

impl Into<jarray> for JArray {
    #[inline]
    fn into(self) -> jarray {
        self.object.into()
    }
}

impl<'a> Into<jarray> for &'a JArray {
    #[inline]
    fn into(self) -> jarray {
        self.object.into()
    }
}

impl Into<jvalue> for JArray {
    #[inline]
    fn into(self) -> jvalue {
        jvalue { l: self.object.into() }
    }
}

impl<'a> Into<jvalue> for &'a JArray {
    #[inline]
    fn into(self) -> jvalue {
        jvalue { l: self.object.into() }
    }
}