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,
}