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
use crate::{FormatTokens, ItemStr, Java, Tokens};

/// Format a block comment, starting with `/**`, and ending in `*/`.
///
/// This struct is created by the [block_comment][super::block_comment()] function.
pub struct BlockComment<T>(pub(super) T);

impl<T> FormatTokens<Java> for BlockComment<T>
where
    T: IntoIterator,
    T::Item: Into<ItemStr>,
{
    fn format_tokens(self, tokens: &mut Tokens<Java>) {
        let mut it = self.0.into_iter().peekable();

        if it.peek().is_none() {
            return;
        }

        tokens.push();
        tokens.append(ItemStr::Static("/**"));
        tokens.push();

        for line in it {
            tokens.space();
            tokens.append(ItemStr::Static("*"));
            tokens.space();
            tokens.append(line.into());
            tokens.push();
        }

        tokens.space();
        tokens.append("*/");
    }
}