use std::cell::RefCell; use crate::name_analysis::symbol::class_symbol::ClassSymbol; use crate::name_analysis::symbol::function_symbol::FunctionSymbol; use crate::name_analysis::symbol::interface_symbol::InterfaceSymbol; use std::collections::HashMap; use std::rc::Rc; pub struct SymbolTree { children: Box>, classes: Box>>>, interfaces: Box>>>, functions: Box>>>, } impl SymbolTree { pub fn new() -> Self { Self { children: Box::new(HashMap::new()), classes: Box::new(HashMap::new()), interfaces: Box::new(HashMap::new()), functions: Box::new(HashMap::new()), } } pub fn find_class(&self, fqn_parts: &[&str]) -> Option>> { match fqn_parts.len() { 0 => None, 1 => self.classes.get(fqn_parts[0]).cloned(), _ => self .children .get(fqn_parts[0]) .and_then(|child_tree| child_tree.find_class(&fqn_parts[1..])), } } pub fn find_interface(&self, fqn_parts: &[&str]) -> Option>> { match fqn_parts.len() { 0 => None, 1 => self.interfaces.get(fqn_parts[0]).cloned(), _ => self .children .get(fqn_parts[0]) .and_then(|child_tree| child_tree.find_interface(&fqn_parts[1..])), } } pub fn find_function(&self, fqn_parts: &[&str]) -> Option>> { match fqn_parts.len() { 0 => None, 1 => self.functions.get(fqn_parts[0]).cloned(), _ => self .children .get(fqn_parts[0]) .and_then(|child_tree| child_tree.find_function(&fqn_parts[1..])), } } }