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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
pub use super::{
Visibility,
Ident,
Path,
Import,
Type,
Block,
};
pub trait ItemExt {
fn ident(&self) -> Option<&Ident> { None }
fn vis(&self) -> Visibility;
fn static_(&self) -> Option<bool> { None }
}
#[derive(Debug, Clone)]
pub enum TypeDef {
NormalClass(Class),
NormalInterface(Interface),
}
impl ItemExt for TypeDef {
fn ident(&self) -> Option<&Ident> {
match *self {
TypeDef::NormalClass(ref c) => c.ident(),
TypeDef::NormalInterface(ref i) => i.ident(),
}
}
fn vis(&self) -> Visibility {
match *self {
TypeDef::NormalClass(ref c) => c.vis(),
TypeDef::NormalInterface(ref i) => i.vis(),
}
}
fn static_(&self) -> Option<bool> {
match *self {
TypeDef::NormalClass(ref c) => c.static_(),
TypeDef::NormalInterface(ref i) => i.static_(),
}
}
}
#[derive(Debug, Clone)]
pub enum Item {
Import(Import),
Class(Box<Class>),
Method(Box<Method>),
Constant(()),
}
pub enum TypeItem {
Type(TypeDef),
Constant(Field),
Method(Method),
}
#[derive(Debug, Clone)]
pub struct Interface {
pub name: Ident,
pub vis: Visibility,
pub static_: bool,
pub strictfp: bool,
pub extends: Vec<Type>,
pub types: Vec<TypeDef>,
pub constants: Vec<Field>,
pub methods: Vec<Method>,
}
impl ItemExt for Interface {
fn ident(&self) -> Option<&Ident> { Some(&self.name) }
fn vis(&self) -> Visibility { self.vis }
fn static_(&self) -> Option<bool> { Some(self.static_) }
}
#[derive(Debug, Clone)]
pub struct Class {
pub name: Ident,
pub vis: Visibility,
pub members: Vec<ClassMember>,
}
impl ItemExt for Class {
fn ident(&self) -> Option<&Ident> { Some(&self.name) }
fn vis(&self) -> Visibility { self.vis }
fn static_(&self) -> Option<bool> { Some(unimplemented!()) }
}
#[derive(Clone, Debug)]
pub enum ClassMember {
Method(Method),
Field(Field),
}
#[derive(Debug, Clone)]
pub struct Field {
pub vis: Visibility,
pub static_: bool,
pub final_: bool,
pub ty: Type,
pub name: Ident,
}
#[derive(Debug, Clone)]
pub struct Method {
pub vis: Visibility,
pub name: Ident,
pub ret_ty: Type,
pub static_: bool,
pub final_: bool,
pub strictfp: bool,
pub abstract_: bool,
pub native: bool,
pub synchronized: bool,
pub default: bool,
pub params: Vec<FormalParameter>,
pub throws: Vec<Type>,
pub block: Option<Block>,
}
#[derive(Debug, Clone)]
pub struct FormalParameter {
pub ty: Type,
pub name: Ident,
pub final_: bool,
}