1#![doc = include_str!("readme.md")]
2
3use core::range::Range;
4
5#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct JavaRoot {
9 pub items: Vec<Item>,
11}
12
13#[derive(Debug, Clone, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct Annotation {
17 pub name: String,
19 pub arguments: Vec<Expression>,
21 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
23 pub span: Range<usize>,
24}
25
26#[derive(Debug, Clone, PartialEq)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29pub enum Item {
30 Class(ClassDeclaration),
32 Interface(InterfaceDeclaration),
34 Struct(StructDeclaration),
36 Enum(EnumDeclaration),
38 Record(RecordDeclaration),
40 AnnotationType(AnnotationTypeDeclaration),
42 Package(PackageDeclaration),
44 Import(ImportDeclaration),
46}
47
48#[derive(Debug, Clone, PartialEq)]
50#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
51pub struct ClassDeclaration {
52 pub name: String,
54 pub type_parameters: Vec<TypeParameter>,
56 pub modifiers: Vec<String>,
58 pub annotations: Vec<Annotation>,
60 pub extends: Option<String>,
62 pub implements: Vec<String>,
64 pub members: Vec<Member>,
66 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
68 pub span: Range<usize>,
69}
70
71#[derive(Debug, Clone, PartialEq)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
74pub enum Member {
75 Method(MethodDeclaration),
77 Field(FieldDeclaration),
79 Constructor(ConstructorDeclaration),
81 InnerClass(ClassDeclaration),
83}
84
85#[derive(Debug, Clone, PartialEq)]
87#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
88pub struct ConstructorDeclaration {
89 pub modifiers: Vec<String>,
91 pub annotations: Vec<Annotation>,
93 pub name: String,
95 pub parameters: Vec<Parameter>,
97 pub body: Vec<Statement>,
99 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
101 pub span: Range<usize>,
102}
103
104#[derive(Debug, Clone, PartialEq)]
106#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
107pub struct MethodDeclaration {
108 pub name: String,
110 pub type_parameters: Vec<TypeParameter>,
112 pub modifiers: Vec<String>,
114 pub annotations: Vec<Annotation>,
116 pub return_type: String,
118 pub parameters: Vec<Parameter>,
120 pub body: Vec<Statement>,
122 pub throws: Vec<String>,
124 pub is_static: bool,
126 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
128 pub span: Range<usize>,
129}
130
131#[derive(Debug, Clone, PartialEq)]
133#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
134pub struct Parameter {
135 pub name: String,
137 pub r#type: String,
139}
140
141#[derive(Debug, Clone, PartialEq)]
143#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
144pub struct TypeParameter {
145 pub name: String,
147 pub constraints: Vec<TypeParameterConstraint>,
149}
150
151#[derive(Debug, Clone, PartialEq)]
153#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
154pub struct TypeParameterConstraint {
155 pub constraint_type: String,
157}
158
159#[derive(Debug, Clone, PartialEq)]
161#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
162pub struct GenericType {
163 pub base_type: String,
165 pub type_arguments: Vec<String>,
167}
168
169#[derive(Debug, Clone, PartialEq)]
171#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
172pub struct FieldDeclaration {
173 pub name: String,
175 pub r#type: String,
177 pub modifiers: Vec<String>,
179 pub annotations: Vec<Annotation>,
181 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
183 pub span: Range<usize>,
184}
185
186#[derive(Debug, Clone, PartialEq)]
188#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
189pub enum Statement {
190 Expression(Expression),
192 Return(Option<Expression>),
194 Block(Vec<Statement>),
196 Try(TryStatement),
198 Throw(Expression),
200 If {
202 condition: Expression,
204 then_branch: Box<Statement>,
206 else_branch: Option<Box<Statement>>,
208 },
209 While {
211 condition: Expression,
213 body: Box<Statement>,
215 },
216 DoWhile {
218 condition: Expression,
220 body: Box<Statement>,
222 },
223 For {
225 init: Option<Box<Statement>>,
227 condition: Option<Expression>,
229 update: Option<Expression>,
231 body: Box<Statement>,
233 },
234 ForEach {
236 item_type: String,
238 item_name: String,
240 iterable: Expression,
242 body: Box<Statement>,
244 },
245 Switch {
247 selector: Expression,
249 cases: Vec<SwitchCase>,
251 default: Option<Vec<Statement>>,
253 },
254 Break,
256 Continue,
258 LocalVariable {
260 r#type: String,
262 name: String,
264 initializer: Option<Expression>,
266 },
267}
268
269#[derive(Debug, Clone, PartialEq)]
271#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
272pub struct SwitchCase {
273 pub label: Expression,
275 pub body: Vec<Statement>,
277}
278
279#[derive(Debug, Clone, PartialEq)]
281#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
282pub struct TryStatement {
283 pub block: Vec<Statement>,
285 pub catches: Vec<CatchClause>,
287 pub finally: Option<Vec<Statement>>,
289}
290
291#[derive(Debug, Clone, PartialEq)]
293#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
294pub struct CatchClause {
295 pub parameter: Parameter,
297 pub block: Vec<Statement>,
299}
300
301#[derive(Debug, Clone, PartialEq)]
303#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
304pub enum Expression {
305 Literal(Literal),
307 Identifier(String),
309 MethodCall(MethodCall),
311 FieldAccess(FieldAccess),
313 ArrayAccess(ArrayAccess),
315 ArrayCreation(ArrayCreation),
317 New(NewExpression),
319 AnonymousClass(AnonymousClassExpression),
321 This,
323 Super,
325 Binary {
327 left: Box<Expression>,
329 op: String,
331 right: Box<Expression>,
333 },
334 Unary {
336 op: String,
338 expression: Box<Expression>,
340 },
341 Assignment {
343 left: Box<Expression>,
345 op: String,
347 right: Box<Expression>,
349 },
350 Update {
352 expression: Box<Expression>,
354 op: String,
356 is_prefix: bool,
358 },
359 Ternary {
361 condition: Box<Expression>,
363 then_branch: Box<Expression>,
365 else_branch: Box<Expression>,
367 },
368 Cast {
370 target_type: String,
372 expression: Box<Expression>,
374 },
375 Lambda(LambdaExpression),
377}
378
379#[derive(Debug, Clone, PartialEq)]
381#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
382pub enum LambdaBody {
383 Expression(Box<Expression>),
385 Block(Vec<Statement>),
387}
388
389#[derive(Debug, Clone, PartialEq)]
391#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
392pub struct LambdaExpression {
393 pub parameters: Vec<Parameter>,
395 pub body: LambdaBody,
397}
398
399#[derive(Debug, Clone, PartialEq)]
401#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
402pub struct NewExpression {
403 pub r#type: String,
405 pub arguments: Vec<Expression>,
407}
408
409#[derive(Debug, Clone, PartialEq)]
411#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
412pub struct AnonymousClassExpression {
413 pub super_type: String,
415 pub arguments: Vec<Expression>,
417 pub members: Vec<Member>,
419}
420
421#[derive(Debug, Clone, PartialEq)]
423#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
424pub enum Literal {
425 Integer(i64),
427 Float(f64),
429 String(String),
431 Boolean(bool),
433}
434
435#[derive(Debug, Clone, PartialEq)]
437#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
438pub struct FieldAccess {
439 pub target: Box<Expression>,
441 pub name: String,
443}
444
445#[derive(Debug, Clone, PartialEq)]
447#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
448pub struct MethodCall {
449 pub target: Option<Box<Expression>>,
451 pub name: String,
453 pub arguments: Vec<Expression>,
455}
456
457#[derive(Debug, Clone, PartialEq)]
459#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
460pub struct ArrayAccess {
461 pub target: Box<Expression>,
463 pub index: Box<Expression>,
465}
466
467#[derive(Debug, Clone, PartialEq)]
469#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
470pub struct ArrayCreation {
471 pub element_type: String,
473 pub dimensions: Vec<Expression>,
475}
476
477#[derive(Debug, Clone, PartialEq)]
479#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
480pub struct InterfaceDeclaration {
481 pub name: String,
483 pub type_parameters: Vec<TypeParameter>,
485 pub modifiers: Vec<String>,
487 pub annotations: Vec<Annotation>,
489 pub extends: Vec<String>,
491 pub members: Vec<Member>,
493 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
495 pub span: Range<usize>,
496}
497
498#[derive(Debug, Clone, PartialEq)]
500#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
501pub struct StructDeclaration {
502 pub name: String,
504 pub modifiers: Vec<String>,
506 pub annotations: Vec<Annotation>,
508 pub implements: Vec<String>,
510 pub members: Vec<Member>,
512 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
514 pub span: Range<usize>,
515}
516
517#[derive(Debug, Clone, PartialEq)]
519#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
520pub struct EnumDeclaration {
521 pub name: String,
523 pub modifiers: Vec<String>,
525 pub annotations: Vec<Annotation>,
527 pub implements: Vec<String>,
529 pub constants: Vec<EnumConstant>,
531 pub members: Vec<Member>,
533 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
535 pub span: Range<usize>,
536}
537
538#[derive(Debug, Clone, PartialEq)]
540#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
541pub struct EnumConstant {
542 pub name: String,
544 pub annotations: Vec<Annotation>,
546 pub arguments: Vec<Expression>,
548 pub body: Option<Vec<Member>>,
550 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
552 pub span: Range<usize>,
553}
554
555#[derive(Debug, Clone, PartialEq)]
557#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
558pub struct RecordDeclaration {
559 pub name: String,
561 pub modifiers: Vec<String>,
563 pub annotations: Vec<Annotation>,
565 pub parameters: Vec<Parameter>,
567 pub implements: Vec<String>,
569 pub members: Vec<Member>,
571 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
573 pub span: Range<usize>,
574}
575
576#[derive(Debug, Clone, PartialEq)]
578#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
579pub struct AnnotationTypeDeclaration {
580 pub name: String,
582 pub modifiers: Vec<String>,
584 pub annotations: Vec<Annotation>,
586 pub elements: Vec<AnnotationElement>,
588 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
590 pub span: Range<usize>,
591}
592
593#[derive(Debug, Clone, PartialEq)]
595#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
596pub struct AnnotationElement {
597 pub name: String,
599 pub r#type: String,
601 pub default_value: Option<Expression>,
603 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
605 pub span: Range<usize>,
606}
607
608#[derive(Debug, Clone, PartialEq)]
610#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
611pub struct PackageDeclaration {
612 pub name: String,
614 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
616 pub span: Range<usize>,
617}
618
619#[derive(Debug, Clone, PartialEq)]
621#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
622pub struct ImportDeclaration {
623 pub path: String,
625 pub is_static: bool,
627 #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
629 pub span: Range<usize>,
630}