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

Method visit_trait

src/extraction/php_extractor.rs:425–483  ·  view source on GitHub ↗

Extract a trait declaration.

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

Source from the content-addressed store, hash-verified

423
424 /// Extract a trait declaration.
425 fn visit_trait(state: &mut ExtractionState, node: TsNode<'_>) {
426 let name = find_direct_child_by_kind(node, "name")
427 .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n));
428
429 let visibility = Visibility::Pub;
430 let docstring = Self::extract_docstring(state, node);
431 let start_line = node.start_position().row as u32;
432 let end_line = node.end_position().row as u32;
433 let start_column = node.start_position().column as u32;
434 let end_column = node.end_position().column as u32;
435 let qualified_name = format!("{}::{}", state.qualified_prefix(), name);
436 let id = generate_node_id(&state.file_path, &NodeKind::Trait, &name, start_line);
437
438 let graph_node = Node {
439 id: id.clone(),
440 kind: NodeKind::Trait,
441 name: name.clone(),
442 qualified_name,
443 file_path: state.file_path.clone(),
444 start_line,
445 attrs_start_line: start_line,
446 end_line,
447 start_column,
448 end_column,
449 signature: Some(format!("trait {name}")),
450 docstring,
451 visibility,
452 is_async: false,
453 branches: 0,
454 loops: 0,
455 returns: 0,
456 max_nesting: 0,
457 unsafe_blocks: 0,
458 unchecked_calls: 0,
459 assertions: 0,
460 updated_at: state.timestamp,
461 parent_id: None,
462 };
463 state.nodes.push(graph_node);
464
465 // Contains edge from parent.
466 if let Some(parent_id) = state.parent_node_id() {
467 state.edges.push(Edge {
468 source: parent_id.to_string(),
469 target: id.clone(),
470 kind: EdgeKind::Contains,
471 line: Some(start_line),
472 });
473 }
474
475 // Visit trait body.
476 state.node_stack.push((name.clone(), id));
477 state.class_depth += 1;
478 if let Some(body) = find_direct_child_by_kind(node, "declaration_list") {
479 Self::visit_class_body(state, body);
480 }
481 state.class_depth -= 1;
482 state.node_stack.pop();

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected