Walk the AST and extract entities.
(
&self,
node: &Node,
source: &str,
file_path: &str,
entities: &mut Vec<Entity>,
in_class: Option<&str>,
)
| 38 | |
| 39 | /// Walk the AST and extract entities. |
| 40 | fn walk_tree( |
| 41 | &self, |
| 42 | node: &Node, |
| 43 | source: &str, |
| 44 | file_path: &str, |
| 45 | entities: &mut Vec<Entity>, |
| 46 | in_class: Option<&str>, |
| 47 | ) { |
| 48 | match node.kind() { |
| 49 | "class_declaration" => { |
| 50 | if let Some(entity) = self.extract_class(node, source, file_path) { |
| 51 | let class_name = entity.name.clone(); |
| 52 | entities.push(entity); |
| 53 | |
| 54 | // Walk class body for methods, fields, inner classes |
| 55 | if let Some(body) = node.child_by_field_name("body") { |
| 56 | let mut cursor = body.walk(); |
| 57 | for child in body.children(&mut cursor) { |
| 58 | self.walk_tree(&child, source, file_path, entities, Some(&class_name)); |
| 59 | } |
| 60 | } |
| 61 | return; // Don't recurse into class again below |
| 62 | } |
| 63 | } |
| 64 | "interface_declaration" => { |
| 65 | if let Some(entity) = self.extract_interface(node, source, file_path) { |
| 66 | let iface_name = entity.name.clone(); |
| 67 | entities.push(entity); |
| 68 | |
| 69 | // Walk interface body for method signatures |
| 70 | if let Some(body) = node.child_by_field_name("body") { |
| 71 | let mut cursor = body.walk(); |
| 72 | for child in body.children(&mut cursor) { |
| 73 | self.walk_tree(&child, source, file_path, entities, Some(&iface_name)); |
| 74 | } |
| 75 | } |
| 76 | return; |
| 77 | } |
| 78 | } |
| 79 | "enum_declaration" => { |
| 80 | if let Some(entity) = self.extract_enum(node, source, file_path) { |
| 81 | let enum_name = entity.name.clone(); |
| 82 | entities.push(entity); |
| 83 | |
| 84 | // Walk enum body for methods |
| 85 | if let Some(body) = node.child_by_field_name("body") { |
| 86 | let mut cursor = body.walk(); |
| 87 | for child in body.children(&mut cursor) { |
| 88 | self.walk_tree(&child, source, file_path, entities, Some(&enum_name)); |
| 89 | } |
| 90 | } |
| 91 | return; |
| 92 | } |
| 93 | } |
| 94 | "record_declaration" => { |
| 95 | if let Some(entity) = self.extract_record(node, source, file_path) { |
| 96 | let record_name = entity.name.clone(); |
| 97 | entities.push(entity); |
no test coverage detected