rujag/java/
jvariable.rs

1use crate::java::*;
2
3pub struct JVariable {
4    name: String,
5    jtype: JType,
6    access: JAccessModifier,
7    jfinal: bool,
8    jstatic: bool,
9}
10
11
12impl JVariable {
13    pub fn new(
14        name: &str,
15        jtype: JType,
16        access: JAccessModifier,
17        jfinal: bool,
18        jstatic: bool,
19    ) -> Self {
20        assert_ne!(0, name.len(), "Variable name cannot be empty");
21        assert_ne!(JType::Void, jtype, "Variables cannot be of type `void`");
22        JVariable {
23            name: name.to_string(),
24            jtype,
25            access,
26            jfinal,
27            jstatic,
28        }
29    }
30    pub fn private(name: &str, jtype: JType) -> Self {
31        Self::new(
32            name,
33            jtype,
34            JAccessModifier::Private,
35            false,
36            false,
37        )
38    }
39
40    pub fn name(&self) -> &String {
41        &self.name
42    }
43
44    pub fn jtype(&self) -> &JType {
45        &self.jtype
46    }
47
48    pub fn access(&self) -> &JAccessModifier {
49        &self.access
50    }
51
52    pub fn is_final(&self) -> bool {
53        self.jfinal
54    }
55
56    pub fn is_static(&self) -> bool {
57        self.jstatic
58    }
59}