Extract a package declaration.
(state: &mut ExtractionState, node: TsNode<'_>)
| 220 | |
| 221 | /// Extract a package declaration. |
| 222 | fn visit_package(state: &mut ExtractionState, node: TsNode<'_>) { |
| 223 | let text = state.node_text(node); |
| 224 | // Package text is like "package com.example.app;" |
| 225 | let pkg_name = text |
| 226 | .trim() |
| 227 | .strip_prefix("package ") |
| 228 | .unwrap_or(&text) |
| 229 | .trim_end_matches(';') |
| 230 | .trim() |
| 231 | .to_string(); |
| 232 | |
| 233 | let start_line = node.start_position().row as u32; |
| 234 | let end_line = node.end_position().row as u32; |
| 235 | let start_column = node.start_position().column as u32; |
| 236 | let end_column = node.end_position().column as u32; |
| 237 | let qualified_name = format!("{}::{}", state.qualified_prefix(), pkg_name); |
| 238 | let id = generate_node_id(&state.file_path, &NodeKind::Package, &pkg_name, start_line); |
| 239 | |
| 240 | let graph_node = Node { |
| 241 | id: id.clone(), |
| 242 | kind: NodeKind::Package, |
| 243 | name: pkg_name, |
| 244 | qualified_name, |
| 245 | file_path: state.file_path.clone(), |
| 246 | start_line, |
| 247 | attrs_start_line: start_line, |
| 248 | end_line, |
| 249 | start_column, |
| 250 | end_column, |
| 251 | signature: Some(text.trim().to_string()), |
| 252 | docstring: None, |
| 253 | visibility: Visibility::Pub, |
| 254 | is_async: false, |
| 255 | branches: 0, |
| 256 | loops: 0, |
| 257 | returns: 0, |
| 258 | max_nesting: 0, |
| 259 | unsafe_blocks: 0, |
| 260 | unchecked_calls: 0, |
| 261 | assertions: 0, |
| 262 | updated_at: state.timestamp, |
| 263 | parent_id: None, |
| 264 | }; |
| 265 | state.nodes.push(graph_node); |
| 266 | |
| 267 | // Contains edge from parent (the file). |
| 268 | if let Some(parent_id) = state.parent_node_id() { |
| 269 | state.edges.push(Edge { |
| 270 | source: parent_id.to_string(), |
| 271 | target: id, |
| 272 | kind: EdgeKind::Contains, |
| 273 | line: Some(start_line), |
| 274 | }); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /// Extract an import declaration as a Use node. |
| 279 | fn visit_import(state: &mut ExtractionState, node: TsNode<'_>) { |
nothing calls this directly
no test coverage detected