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
use super::*; #[derive(Debug, Clone)] pub struct AnnotationSpec { pub ty: Type, pub arguments: Vec<Statement>, } impl AnnotationSpec { pub fn new<I>(ty: I) -> AnnotationSpec where I: Into<Type> { AnnotationSpec { ty: ty.into(), arguments: Vec::new(), } } pub fn push_argument<S>(&mut self, statement: S) where S: Into<Statement> { self.arguments.push(statement.into()); } } impl<'a, T> From<&'a T> for AnnotationSpec where T: Into<AnnotationSpec> + Clone { fn from(value: &'a T) -> AnnotationSpec { value.clone().into() } } impl From<ClassType> for AnnotationSpec { fn from(value: ClassType) -> AnnotationSpec { AnnotationSpec::new(value) } } impl From<AnnotationSpec> for Element { fn from(value: AnnotationSpec) -> Element { let mut elements = Elements::new(); let mut annotation = Statement::new(); annotation.push("@"); annotation.push(value.ty); if !value.arguments.is_empty() { let mut open = Statement::new(); let arguments: Statement = value.arguments.into(); open.push(annotation); open.push("("); open.push(arguments.join(", ")); open.push(")"); elements.push(open); } else { elements.push(annotation); } elements.into() } } impl From<AnnotationSpec> for Statement { fn from(value: AnnotationSpec) -> Statement { Statement { parts: vec![Variable::Element(value.into())] } } }