java_lang/tree/node/
module.rs

1use std::{
2    borrow::Cow,
3    fmt::{Display, Formatter,Result as FmtResult}
4};
5use crate::{Annotation, DocumentationComment};
6
7/// ModuleDeclaration表示Java程序中的模块声明。
8/// 它包括模块的名称、注解、指令以及是否为开放模块。
9#[derive(Debug)]
10pub struct ModuleDeclaration<'a> {
11    /// 模块的名称。
12    pub name: Cow<'a, str>,
13    /// 应用到模块声明的注解。
14    pub annotations: Vec<Annotation<'a>>,
15    /// 指定模块的依赖、导出、打开、使用和提供等指令。
16    pub directives: Vec<ModuleDirective>,
17    /// 是否为开放模块。
18    pub open: bool,
19    /// 文档注释
20    pub documentation: Option<DocumentationComment<'a>>,
21}
22
23impl<'a> Display for ModuleDeclaration<'a> {
24    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
25        if let Some(ref d) = self.documentation {
26            Display::fmt(d, f)?;
27        }
28        for i in &self.annotations {
29            write!(f, "{}\n", i)?;
30        }
31        if self.open {
32            write!(f, "open")?;
33        }
34        write!(f, "module {} {{}}", self.name)?;
35        Ok(())
36    }
37}
38
39#[derive(Debug)]
40pub struct ModuleDirective;