MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / visit_namespace

Method visit_namespace

src/extraction/php_extractor.rs:615–670  ·  view source on GitHub ↗

Extract a namespace definition.

(state: &mut ExtractionState, node: TsNode<'_>)

Source from the content-addressed store, hash-verified

613
614 /// Extract a namespace definition.
615 fn visit_namespace(state: &mut ExtractionState, node: TsNode<'_>) {
616 let name = find_direct_child_by_kind(node, "namespace_name")
617 .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n));
618
619 let visibility = Visibility::Pub;
620 let start_line = node.start_position().row as u32;
621 let end_line = node.end_position().row as u32;
622 let start_column = node.start_position().column as u32;
623 let end_column = node.end_position().column as u32;
624 let qualified_name = format!("{}::{}", state.qualified_prefix(), name);
625 let id = generate_node_id(&state.file_path, &NodeKind::Module, &name, start_line);
626
627 let graph_node = Node {
628 id: id.clone(),
629 kind: NodeKind::Module,
630 name: name.clone(),
631 qualified_name,
632 file_path: state.file_path.clone(),
633 start_line,
634 attrs_start_line: start_line,
635 end_line,
636 start_column,
637 end_column,
638 signature: Some(format!("namespace {name}")),
639 docstring: None,
640 visibility,
641 is_async: false,
642 branches: 0,
643 loops: 0,
644 returns: 0,
645 max_nesting: 0,
646 unsafe_blocks: 0,
647 unchecked_calls: 0,
648 assertions: 0,
649 updated_at: state.timestamp,
650 parent_id: None,
651 };
652 state.nodes.push(graph_node);
653
654 // Contains edge from parent.
655 if let Some(parent_id) = state.parent_node_id() {
656 state.edges.push(Edge {
657 source: parent_id.to_string(),
658 target: id.clone(),
659 kind: EdgeKind::Contains,
660 line: Some(start_line),
661 });
662 }
663
664 // Visit namespace body (braced namespace) or siblings (unbraced).
665 state.node_stack.push((name.clone(), id));
666 if let Some(body) = find_direct_child_by_kind(node, "compound_statement") {
667 Self::visit_children(state, body);
668 }
669 state.node_stack.pop();
670 }
671
672 /// Extract a use declaration (import statement).

Callers

nothing calls this directly

Calls 6

generate_node_idFunction · 0.85
visit_childrenFunction · 0.85
pushMethod · 0.80
node_textMethod · 0.45
parent_node_idMethod · 0.45

Tested by

no test coverage detected