use crate::checkstyle::api::ast::DetailAst;
use std::sync::Arc;
pub struct FullIdent {
pub text: String,
pub detail_ast: Option<Arc<dyn DetailAst>>,
}
impl FullIdent {
pub fn create_full_ident(ast: &Arc<dyn DetailAst>) -> Self {
let mut text_parts = Vec::new();
let mut current: Option<Arc<dyn DetailAst>> = Some(ast.clone());
let mut first_ast: Option<Arc<dyn DetailAst>> = None;
while let Some(node) = current {
let node_type = node.get_type();
if node_type == crate::checkstyle::api::ast::token_types::IDENT {
if first_ast.is_none() {
first_ast = Some(node.clone());
}
text_parts.push(node.get_text().to_string());
current = node.get_next_sibling_arc();
} else if node_type == crate::checkstyle::api::ast::token_types::DOT {
text_parts.push(".".to_string());
current = node.get_next_sibling_arc();
} else {
if let Some(child) = node.get_first_child_arc() {
current = Some(child);
} else {
break;
}
}
}
let text = text_parts.join("");
Self {
text,
detail_ast: first_ast,
}
}
pub fn get_text(&self) -> &str {
&self.text
}
pub fn get_detail_ast(&self) -> Option<&Arc<dyn DetailAst>> {
self.detail_ast.as_ref()
}
pub fn create_full_ident_below(ast: &Arc<dyn DetailAst>) -> Self {
if let Some(first_child) = ast.get_first_child_arc() {
Self::create_full_ident(&first_child)
} else {
Self {
text: String::new(),
detail_ast: None,
}
}
}
}