java_lang/tree/node/
import.rs

1use std::{
2    borrow::Cow,
3    fmt::{Display, Formatter, Result as FmtResult},
4};
5
6/// ImportDeclaration 枚举表示Java中的导入声明。
7#[derive(Debug)]
8pub enum ImportDeclaration<'a> {
9    /// 单类型导入声明,参数是导入的类或接口的名称。
10    SimpleType(Cow<'a, str>),
11    /// 需求类型导入声明,参数是导入的包、类或接口的名称(路径)。
12    TypeOnDemand(Cow<'a, str>),
13    /// 单静态导入声明,参数是导入的类或接口的名称 + 导入的静态成员的名称。
14    SingleStatic(Cow<'a, str>),
15    /// 静态需求导入声明,参数是导入的类或接口的名称。
16    StaticOnDemand(Cow<'a, str>),
17}
18
19impl<'a> Display for ImportDeclaration<'a> {
20    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
21        match self {
22            Self::SimpleType(r) | Self::SingleStatic(r) => write!(f, "import {};", r),
23            Self::TypeOnDemand(r) | Self::StaticOnDemand(r) => write!(f, "import {}.*;", r),
24        }
25    }
26}