1#![doc = include_str!("readme.md")]
2use core::range::Range;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub struct JavaRoot {
11 pub items: Vec<Item>,
13}
14
15#[derive(Debug, Clone, PartialEq)]
17#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18pub struct Annotation {
19 pub name: String,
21 pub arguments: Vec<Expression>,
23 #[serde(with = "oak_core::serde_range")]
25 pub span: Range<usize>,
26}
27
28#[derive(Debug, Clone, PartialEq)]
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31pub enum Item {
32 Class(ClassDeclaration),
34 Interface(InterfaceDeclaration),
36 Struct(StructDeclaration),
38 Enum(EnumDeclaration),
40 Record(RecordDeclaration),
42 Package(PackageDeclaration),
44 Import(ImportDeclaration),
46}
47
48#[derive(Debug, Clone, PartialEq)]
50#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
51pub struct ClassDeclaration {
52 pub name: String,
54 pub modifiers: Vec<String>,
56 pub annotations: Vec<Annotation>,
58 pub extends: Option<String>,
60 pub implements: Vec<String>,
62 pub members: Vec<Member>,
64 #[serde(with = "oak_core::serde_range")]
66 pub span: Range<usize>,
67}
68
69#[derive(Debug, Clone, PartialEq)]
71#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
72pub enum Member {
73 Method(MethodDeclaration),
75 Field(FieldDeclaration),
77 Constructor(ConstructorDeclaration),
79}
80
81#[derive(Debug, Clone, PartialEq)]
83#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
84pub struct ConstructorDeclaration {
85 pub modifiers: Vec<String>,
87 pub annotations: Vec<Annotation>,
89 pub name: String,
91 pub parameters: Vec<Parameter>,
93 pub body: Vec<Statement>,
95 #[serde(with = "oak_core::serde_range")]
97 pub span: Range<usize>,
98}
99
100#[derive(Debug, Clone, PartialEq)]
102#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
103pub struct MethodDeclaration {
104 pub name: String,
106 pub modifiers: Vec<String>,
108 pub annotations: Vec<Annotation>,
110 pub return_type: String,
112 pub parameters: Vec<Parameter>,
114 pub body: Vec<Statement>,
116 pub throws: Vec<String>,
118 pub is_static: bool,
120 #[serde(with = "oak_core::serde_range")]
122 pub span: Range<usize>,
123}
124
125#[derive(Debug, Clone, PartialEq)]
127#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
128pub struct Parameter {
129 pub name: String,
131 pub r#type: String,
133}
134
135#[derive(Debug, Clone, PartialEq)]
137#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
138pub struct FieldDeclaration {
139 pub name: String,
141 pub r#type: String,
143 pub modifiers: Vec<String>,
145 pub annotations: Vec<Annotation>,
147 #[serde(with = "oak_core::serde_range")]
149 pub span: Range<usize>,
150}
151
152#[derive(Debug, Clone, PartialEq)]
154#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
155pub enum Statement {
156 Expression(Expression),
158 Return(Option<Expression>),
160 Block(Vec<Statement>),
162 Try(TryStatement),
164 Throw(Expression),
166 If {
168 condition: Expression,
170 then_branch: Box<Statement>,
172 else_branch: Option<Box<Statement>>,
174 },
175 While {
177 condition: Expression,
179 body: Box<Statement>,
181 },
182 DoWhile {
184 condition: Expression,
186 body: Box<Statement>,
188 },
189 For {
191 init: Option<Box<Statement>>,
193 condition: Option<Expression>,
195 update: Option<Expression>,
197 body: Box<Statement>,
199 },
200 ForEach {
202 item_type: String,
204 item_name: String,
206 iterable: Expression,
208 body: Box<Statement>,
210 },
211 Switch {
213 selector: Expression,
215 cases: Vec<SwitchCase>,
217 default: Option<Vec<Statement>>,
219 },
220 Break,
222 Continue,
224 LocalVariable {
226 r#type: String,
228 name: String,
230 initializer: Option<Expression>,
232 },
233}
234
235#[derive(Debug, Clone, PartialEq)]
237#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
238pub struct SwitchCase {
239 pub label: Expression,
241 pub body: Vec<Statement>,
243}
244
245#[derive(Debug, Clone, PartialEq)]
247#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
248pub struct TryStatement {
249 pub block: Vec<Statement>,
251 pub catches: Vec<CatchClause>,
253 pub finally: Option<Vec<Statement>>,
255}
256
257#[derive(Debug, Clone, PartialEq)]
259#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
260pub struct CatchClause {
261 pub parameter: Parameter,
263 pub block: Vec<Statement>,
265}
266
267#[derive(Debug, Clone, PartialEq)]
269#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
270pub enum Expression {
271 Literal(Literal),
273 Identifier(String),
275 MethodCall(MethodCall),
277 FieldAccess(FieldAccess),
279 ArrayAccess(ArrayAccess),
281 ArrayCreation(ArrayCreation),
283 New(NewExpression),
285 This,
287 Super,
289 Binary {
291 left: Box<Expression>,
293 op: String,
295 right: Box<Expression>,
297 },
298 Unary {
300 op: String,
302 expression: Box<Expression>,
304 },
305 Assignment {
307 left: Box<Expression>,
309 op: String,
311 right: Box<Expression>,
313 },
314 Update {
316 expression: Box<Expression>,
318 op: String,
320 is_prefix: bool,
322 },
323 Ternary {
325 condition: Box<Expression>,
327 then_branch: Box<Expression>,
329 else_branch: Box<Expression>,
331 },
332 Cast {
334 target_type: String,
336 expression: Box<Expression>,
338 },
339}
340
341#[derive(Debug, Clone, PartialEq)]
343#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
344pub struct NewExpression {
345 pub r#type: String,
347 pub arguments: Vec<Expression>,
349}
350
351#[derive(Debug, Clone, PartialEq)]
353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
354pub enum Literal {
355 Integer(i64),
357 Float(f64),
359 String(String),
361 Boolean(bool),
363}
364
365#[derive(Debug, Clone, PartialEq)]
367#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
368pub struct FieldAccess {
369 pub target: Box<Expression>,
371 pub name: String,
373}
374
375#[derive(Debug, Clone, PartialEq)]
377#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
378pub struct MethodCall {
379 pub target: Option<Box<Expression>>,
381 pub name: String,
383 pub arguments: Vec<Expression>,
385}
386
387#[derive(Debug, Clone, PartialEq)]
389#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
390pub struct ArrayAccess {
391 pub target: Box<Expression>,
393 pub index: Box<Expression>,
395}
396
397#[derive(Debug, Clone, PartialEq)]
399#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
400pub struct ArrayCreation {
401 pub element_type: String,
403 pub dimensions: Vec<Expression>,
405}
406
407#[derive(Debug, Clone, PartialEq)]
409#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
410pub struct InterfaceDeclaration {
411 pub name: String,
413 pub modifiers: Vec<String>,
415 pub annotations: Vec<Annotation>,
417 pub extends: Vec<String>,
419 pub members: Vec<Member>,
421 #[serde(with = "oak_core::serde_range")]
423 pub span: Range<usize>,
424}
425
426#[derive(Debug, Clone, PartialEq)]
428#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
429pub struct StructDeclaration {
430 pub name: String,
432 pub modifiers: Vec<String>,
434 pub annotations: Vec<Annotation>,
436 pub implements: Vec<String>,
438 pub members: Vec<Member>,
440 #[serde(with = "oak_core::serde_range")]
442 pub span: Range<usize>,
443}
444
445#[derive(Debug, Clone, PartialEq)]
447#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
448pub struct EnumDeclaration {
449 pub name: String,
451 pub modifiers: Vec<String>,
453 pub annotations: Vec<Annotation>,
455 pub implements: Vec<String>,
457 pub variants: Vec<String>,
459 pub members: Vec<Member>,
461 #[serde(with = "oak_core::serde_range")]
463 pub span: Range<usize>,
464}
465
466#[derive(Debug, Clone, PartialEq)]
468#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
469pub struct RecordDeclaration {
470 pub name: String,
472 pub modifiers: Vec<String>,
474 pub annotations: Vec<Annotation>,
476 pub parameters: Vec<Parameter>,
478 pub implements: Vec<String>,
480 pub members: Vec<Member>,
482 #[serde(with = "oak_core::serde_range")]
484 pub span: Range<usize>,
485}
486
487#[derive(Debug, Clone, PartialEq)]
489#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
490pub struct PackageDeclaration {
491 pub name: String,
493 #[serde(with = "oak_core::serde_range")]
495 pub span: Range<usize>,
496}
497
498#[derive(Debug, Clone, PartialEq)]
500#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
501pub struct ImportDeclaration {
502 pub path: String,
504 pub is_static: bool,
506 #[serde(with = "oak_core::serde_range")]
508 pub span: Range<usize>,
509}