use super::modifier::Modifier;
use cons::Cons;
use into_tokens::IntoTokens;
use java::Java;
use tokens::Tokens;
#[derive(Debug, Clone)]
pub struct Argument<'el> {
pub modifiers: Vec<Modifier>,
annotations: Tokens<'el, Java<'el>>,
ty: Java<'el>,
name: Cons<'el>,
}
impl<'el> Argument<'el> {
pub fn new<T, N>(ty: T, name: N) -> Argument<'el>
where
T: Into<Java<'el>>,
N: Into<Cons<'el>>,
{
Argument {
annotations: Tokens::new(),
modifiers: vec![Modifier::Final],
ty: ty.into(),
name: name.into(),
}
}
pub fn annotation<A>(&mut self, annotation: A)
where
A: IntoTokens<'el, Java<'el>>,
{
self.annotations.push(annotation.into_tokens());
}
pub fn var(&self) -> Cons<'el> {
self.name.clone()
}
pub fn ty(&self) -> Java<'el> {
self.ty.clone()
}
}
into_tokens_impl_from!(Argument<'el>, Java<'el>);
impl<'el> IntoTokens<'el, Java<'el>> for Argument<'el> {
fn into_tokens(self) -> Tokens<'el, Java<'el>> {
let mut s = Tokens::new();
s.extend(self.annotations.into_iter());
s.extend(self.modifiers.into_tokens());
s.append(self.ty);
s.append(self.name);
s.join_spacing()
}
}