#![doc = include_str!("readme.md")]
use core::range::Range;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct JavaRoot {
pub items: Vec<Item>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Annotation {
pub name: String,
pub arguments: Vec<Expression>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Item {
Class(ClassDeclaration),
Interface(InterfaceDeclaration),
Struct(StructDeclaration),
Enum(EnumDeclaration),
Record(RecordDeclaration),
AnnotationType(AnnotationTypeDeclaration),
Package(PackageDeclaration),
Import(ImportDeclaration),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClassDeclaration {
pub name: String,
pub type_parameters: Vec<TypeParameter>,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub extends: Option<String>,
pub implements: Vec<String>,
pub members: Vec<Member>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Member {
Method(MethodDeclaration),
Field(FieldDeclaration),
Constructor(ConstructorDeclaration),
InnerClass(ClassDeclaration),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConstructorDeclaration {
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub name: String,
pub parameters: Vec<Parameter>,
pub body: Vec<Statement>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodDeclaration {
pub name: String,
pub type_parameters: Vec<TypeParameter>,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub return_type: String,
pub parameters: Vec<Parameter>,
pub body: Vec<Statement>,
pub throws: Vec<String>,
pub is_static: bool,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Parameter {
pub name: String,
pub r#type: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeParameter {
pub name: String,
pub constraints: Vec<TypeParameterConstraint>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeParameterConstraint {
pub constraint_type: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GenericType {
pub base_type: String,
pub type_arguments: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldDeclaration {
pub name: String,
pub r#type: String,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Statement {
Expression(Expression),
Return(Option<Expression>),
Block(Vec<Statement>),
Try(TryStatement),
Throw(Expression),
If {
condition: Expression,
then_branch: Box<Statement>,
else_branch: Option<Box<Statement>>,
},
While {
condition: Expression,
body: Box<Statement>,
},
DoWhile {
condition: Expression,
body: Box<Statement>,
},
For {
init: Option<Box<Statement>>,
condition: Option<Expression>,
update: Option<Expression>,
body: Box<Statement>,
},
ForEach {
item_type: String,
item_name: String,
iterable: Expression,
body: Box<Statement>,
},
Switch {
selector: Expression,
cases: Vec<SwitchCase>,
default: Option<Vec<Statement>>,
},
Break,
Continue,
LocalVariable {
r#type: String,
name: String,
initializer: Option<Expression>,
},
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SwitchCase {
pub label: Expression,
pub body: Vec<Statement>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TryStatement {
pub block: Vec<Statement>,
pub catches: Vec<CatchClause>,
pub finally: Option<Vec<Statement>>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CatchClause {
pub parameter: Parameter,
pub block: Vec<Statement>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Expression {
Literal(Literal),
Identifier(String),
MethodCall(MethodCall),
FieldAccess(FieldAccess),
ArrayAccess(ArrayAccess),
ArrayCreation(ArrayCreation),
New(NewExpression),
AnonymousClass(AnonymousClassExpression),
This,
Super,
Binary {
left: Box<Expression>,
op: String,
right: Box<Expression>,
},
Unary {
op: String,
expression: Box<Expression>,
},
Assignment {
left: Box<Expression>,
op: String,
right: Box<Expression>,
},
Update {
expression: Box<Expression>,
op: String,
is_prefix: bool,
},
Ternary {
condition: Box<Expression>,
then_branch: Box<Expression>,
else_branch: Box<Expression>,
},
Cast {
target_type: String,
expression: Box<Expression>,
},
Lambda(LambdaExpression),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LambdaBody {
Expression(Box<Expression>),
Block(Vec<Statement>),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LambdaExpression {
pub parameters: Vec<Parameter>,
pub body: LambdaBody,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NewExpression {
pub r#type: String,
pub arguments: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnonymousClassExpression {
pub super_type: String,
pub arguments: Vec<Expression>,
pub members: Vec<Member>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Literal {
Integer(i64),
Float(f64),
String(String),
Boolean(bool),
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldAccess {
pub target: Box<Expression>,
pub name: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodCall {
pub target: Option<Box<Expression>>,
pub name: String,
pub arguments: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ArrayAccess {
pub target: Box<Expression>,
pub index: Box<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ArrayCreation {
pub element_type: String,
pub dimensions: Vec<Expression>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InterfaceDeclaration {
pub name: String,
pub type_parameters: Vec<TypeParameter>,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub extends: Vec<String>,
pub members: Vec<Member>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StructDeclaration {
pub name: String,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub implements: Vec<String>,
pub members: Vec<Member>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumDeclaration {
pub name: String,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub implements: Vec<String>,
pub constants: Vec<EnumConstant>,
pub members: Vec<Member>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EnumConstant {
pub name: String,
pub annotations: Vec<Annotation>,
pub arguments: Vec<Expression>,
pub body: Option<Vec<Member>>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RecordDeclaration {
pub name: String,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub parameters: Vec<Parameter>,
pub implements: Vec<String>,
pub members: Vec<Member>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnnotationTypeDeclaration {
pub name: String,
pub modifiers: Vec<String>,
pub annotations: Vec<Annotation>,
pub elements: Vec<AnnotationElement>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnnotationElement {
pub name: String,
pub r#type: String,
pub default_value: Option<Expression>,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PackageDeclaration {
pub name: String,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ImportDeclaration {
pub path: String,
pub is_static: bool,
#[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
pub span: Range<usize>,
}