Extract an enum declaration.
(state: &mut ExtractionState, node: TsNode<'_>)
| 484 | |
| 485 | /// Extract an enum declaration. |
| 486 | fn visit_enum(state: &mut ExtractionState, node: TsNode<'_>) { |
| 487 | let name = find_direct_child_by_kind(node, "name") |
| 488 | .map_or_else(|| "<anonymous>".to_string(), |n| state.node_text(n)); |
| 489 | |
| 490 | let visibility = Visibility::Pub; |
| 491 | let docstring = Self::extract_docstring(state, node); |
| 492 | let start_line = node.start_position().row as u32; |
| 493 | let end_line = node.end_position().row as u32; |
| 494 | let start_column = node.start_position().column as u32; |
| 495 | let end_column = node.end_position().column as u32; |
| 496 | let qualified_name = format!("{}::{}", state.qualified_prefix(), name); |
| 497 | let id = generate_node_id(&state.file_path, &NodeKind::Enum, &name, start_line); |
| 498 | |
| 499 | let graph_node = Node { |
| 500 | id: id.clone(), |
| 501 | kind: NodeKind::Enum, |
| 502 | name: name.clone(), |
| 503 | qualified_name, |
| 504 | file_path: state.file_path.clone(), |
| 505 | start_line, |
| 506 | attrs_start_line: start_line, |
| 507 | end_line, |
| 508 | start_column, |
| 509 | end_column, |
| 510 | signature: Some(format!("enum {name}")), |
| 511 | docstring, |
| 512 | visibility, |
| 513 | is_async: false, |
| 514 | branches: 0, |
| 515 | loops: 0, |
| 516 | returns: 0, |
| 517 | max_nesting: 0, |
| 518 | unsafe_blocks: 0, |
| 519 | unchecked_calls: 0, |
| 520 | assertions: 0, |
| 521 | updated_at: state.timestamp, |
| 522 | parent_id: None, |
| 523 | }; |
| 524 | state.nodes.push(graph_node); |
| 525 | |
| 526 | // Contains edge from parent. |
| 527 | if let Some(parent_id) = state.parent_node_id() { |
| 528 | state.edges.push(Edge { |
| 529 | source: parent_id.to_string(), |
| 530 | target: id.clone(), |
| 531 | kind: EdgeKind::Contains, |
| 532 | line: Some(start_line), |
| 533 | }); |
| 534 | } |
| 535 | |
| 536 | // Visit enum body for cases. |
| 537 | state.node_stack.push((name.clone(), id)); |
| 538 | state.class_depth += 1; |
| 539 | if let Some(body) = find_direct_child_by_kind(node, "enum_declaration_list") { |
| 540 | Self::visit_enum_body(state, body); |
| 541 | } |
| 542 | state.class_depth -= 1; |
| 543 | state.node_stack.pop(); |
nothing calls this directly
no test coverage detected