1#![doc = include_str!("readme.md")]
2use core::range::Range;
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub struct JavaRoot {
12 pub items: Vec<Item>,
14}
15
16#[derive(Debug, Clone, PartialEq)]
18#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19pub enum Item {
20 Class(ClassDeclaration),
22 Interface(InterfaceDeclaration),
24 Struct(StructDeclaration),
26 Enum(EnumDeclaration),
28 Record(RecordDeclaration),
30 Package(PackageDeclaration),
32 Import(ImportDeclaration),
34}
35
36#[derive(Debug, Clone, PartialEq)]
38#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
39pub struct ClassDeclaration {
40 pub name: String,
42 pub modifiers: Vec<String>,
44 pub extends: Option<String>,
46 pub implements: Vec<String>,
48 pub members: Vec<Member>,
50 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
52 pub span: Range<usize>,
53}
54
55#[derive(Debug, Clone, PartialEq)]
57#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
58pub enum Member {
59 Method(MethodDeclaration),
61 Field(FieldDeclaration),
63 Constructor(ConstructorDeclaration),
65}
66
67#[derive(Debug, Clone, PartialEq)]
69#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
70pub struct ConstructorDeclaration {
71 pub modifiers: Vec<String>,
73 pub name: String,
75 pub parameters: Vec<Parameter>,
77 pub body: Vec<Statement>,
79 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
81 pub span: Range<usize>,
82}
83
84#[derive(Debug, Clone, PartialEq)]
86#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
87pub struct MethodDeclaration {
88 pub name: String,
90 pub modifiers: Vec<String>,
92 pub return_type: String,
94 pub parameters: Vec<Parameter>,
96 pub body: Vec<Statement>,
98 pub throws: Vec<String>,
100 pub is_static: bool,
102 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
104 pub span: Range<usize>,
105}
106
107#[derive(Debug, Clone, PartialEq)]
109#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
110pub struct Parameter {
111 pub name: String,
113 pub r#type: String,
115}
116
117#[derive(Debug, Clone, PartialEq)]
119#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
120pub struct FieldDeclaration {
121 pub name: String,
122 pub r#type: String,
123 pub modifiers: Vec<String>,
124 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
125 pub span: Range<usize>,
126}
127
128#[derive(Debug, Clone, PartialEq)]
130#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
131pub enum Statement {
132 Expression(Expression),
134 Return(Option<Expression>),
136 Block(Vec<Statement>),
138 Try(TryStatement),
140 Throw(Expression),
142 If { condition: Expression, then_branch: Box<Statement>, else_branch: Option<Box<Statement>> },
144 While { condition: Expression, body: Box<Statement> },
146 DoWhile { condition: Expression, body: Box<Statement> },
148 For { init: Option<Box<Statement>>, condition: Option<Expression>, update: Option<Expression>, body: Box<Statement> },
150 ForEach { item_type: String, item_name: String, iterable: Expression, body: Box<Statement> },
152 Switch { selector: Expression, cases: Vec<SwitchCase>, default: Option<Vec<Statement>> },
154 Break,
156 Continue,
158 LocalVariable { r#type: String, name: String, initializer: Option<Expression> },
160}
161
162#[derive(Debug, Clone, PartialEq)]
164#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
165pub struct SwitchCase {
166 pub label: Expression,
167 pub body: Vec<Statement>,
168}
169
170#[derive(Debug, Clone, PartialEq)]
172#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
173pub struct TryStatement {
174 pub block: Vec<Statement>,
175 pub catches: Vec<CatchClause>,
176 pub finally: Option<Vec<Statement>>,
177}
178
179#[derive(Debug, Clone, PartialEq)]
181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
182pub struct CatchClause {
183 pub parameter: Parameter,
184 pub block: Vec<Statement>,
185}
186
187#[derive(Debug, Clone, PartialEq)]
189#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
190pub enum Expression {
191 Literal(Literal),
193 Identifier(String),
195 MethodCall(MethodCall),
197 FieldAccess(FieldAccess),
199 ArrayAccess(ArrayAccess),
201 ArrayCreation(ArrayCreation),
203 New(NewExpression),
205 This,
207 Super,
209 Binary { left: Box<Expression>, op: String, right: Box<Expression> },
211 Unary { op: String, expression: Box<Expression> },
213 Assignment { left: Box<Expression>, op: String, right: Box<Expression> },
215 Update { expression: Box<Expression>, op: String, is_prefix: bool },
217 Ternary { condition: Box<Expression>, then_branch: Box<Expression>, else_branch: Box<Expression> },
219 Cast { target_type: String, expression: Box<Expression> },
221}
222
223#[derive(Debug, Clone, PartialEq)]
225#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
226pub struct NewExpression {
227 pub r#type: String,
228 pub arguments: Vec<Expression>,
229}
230
231#[derive(Debug, Clone, PartialEq)]
233#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
234pub enum Literal {
235 Integer(i64),
236 Float(f64),
237 String(String),
238 Boolean(bool),
239}
240
241#[derive(Debug, Clone, PartialEq)]
243#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
244pub struct FieldAccess {
245 pub target: Box<Expression>,
247 pub name: String,
249}
250
251#[derive(Debug, Clone, PartialEq)]
253#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
254pub struct MethodCall {
255 pub target: Option<Box<Expression>>,
257 pub name: String,
259 pub arguments: Vec<Expression>,
261}
262
263#[derive(Debug, Clone, PartialEq)]
265#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
266pub struct ArrayAccess {
267 pub target: Box<Expression>,
268 pub index: Box<Expression>,
269}
270
271#[derive(Debug, Clone, PartialEq)]
273#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
274pub struct ArrayCreation {
275 pub element_type: String,
276 pub dimensions: Vec<Expression>,
277}
278
279#[derive(Debug, Clone, PartialEq)]
281#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
282pub struct InterfaceDeclaration {
283 pub name: String,
285 pub modifiers: Vec<String>,
287 pub extends: Vec<String>,
289 pub members: Vec<Member>,
291 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
293 pub span: Range<usize>,
294}
295
296#[derive(Debug, Clone, PartialEq)]
298#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
299pub struct StructDeclaration {
300 pub name: String,
302 pub modifiers: Vec<String>,
304 pub implements: Vec<String>,
306 pub members: Vec<Member>,
308 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
310 pub span: Range<usize>,
311}
312
313#[derive(Debug, Clone, PartialEq)]
315#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
316pub struct EnumDeclaration {
317 pub name: String,
319 pub modifiers: Vec<String>,
321 pub variants: Vec<String>,
323 pub members: Vec<Member>,
325 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
327 pub span: Range<usize>,
328}
329
330#[derive(Debug, Clone, PartialEq)]
332#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
333pub struct RecordDeclaration {
334 pub name: String,
336 pub modifiers: Vec<String>,
338 pub parameters: Vec<Parameter>,
340 pub implements: Vec<String>,
342 pub members: Vec<Member>,
344 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
346 pub span: Range<usize>,
347}
348
349#[derive(Debug, Clone, PartialEq)]
351#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
352pub struct PackageDeclaration {
353 pub name: String,
355 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
357 pub span: Range<usize>,
358}
359
360#[derive(Debug, Clone, PartialEq)]
362#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
363pub struct ImportDeclaration {
364 pub path: String,
366 pub is_static: bool,
368 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
370 pub span: Range<usize>,
371}