1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
use super::_type::ClassType; use super::annotation_spec::AnnotationSpec; use super::element::*; use super::elements::Elements; use super::modifier::Modifiers; use super::statement::Statement; #[derive(Debug, Clone)] pub struct InterfaceSpec { pub modifiers: Modifiers, pub name: String, pub annotations: Vec<AnnotationSpec>, pub elements: Elements, pub extends: Vec<ClassType>, } impl InterfaceSpec { pub fn new(modifiers: Modifiers, name: &str) -> InterfaceSpec { InterfaceSpec { modifiers: modifiers, name: name.to_owned(), annotations: Vec::new(), elements: Elements::new(), extends: Vec::new(), } } pub fn push_annotation(&mut self, annotation: &AnnotationSpec) { self.annotations.push(annotation.clone()); } pub fn extends<T>(&mut self, ty: T) where T: Into<ClassType> { self.extends.push(ty.into()); } } impl From<InterfaceSpec> for Element { fn from(value: InterfaceSpec) -> Element { let mut elements = Elements::new(); let mut open = Statement::new(); for a in &value.annotations { elements.push(a); } if !value.modifiers.is_empty() { open.push(value.modifiers); open.push(" "); } open.push("interface "); open.push(value.name); if !value.extends.is_empty() { let mut arguments = Statement::new(); for extends in &value.extends { arguments.push(extends); } open.push(" extends "); open.push(arguments.join(",")); } open.push(" {"); elements.push(open); elements.push_nested(value.elements.join(Spacing)); elements.push("}"); elements.into() } }