MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_inheritance

Method extract_inheritance

codegraph-kernel/src/tsjs/extractors.rs:2514–2562  ·  view source on GitHub ↗
(&mut self, node: Node<'t>, class_row: u32)

Source from the content-addressed store, hash-verified

2512 // --- extractInheritance (TS/JS clauses) ---------------------------------------------------
2513
2514 pub(super) fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
2515 stack_guard!();
2516 let extends_kind = edge_kind_index("extends").unwrap();
2517 let implements_kind = edge_kind_index("implements").unwrap();
2518 for child in node.named_children(&mut node.walk()) {
2519 match child.kind() {
2520 // TS `extends_clause` (the other spellings are other grammars').
2521 "extends_clause" | "superclass" | "base_clause" | "extends_interfaces" => {
2522 if let Some(target) = child.named_child(0) {
2523 let name = self.supertype_name(target);
2524 self.push_ref(class_row, &name, extends_kind, target);
2525 }
2526 }
2527 "implements_clause" | "class_interface_clause" | "super_interfaces" | "interfaces" => {
2528 for iface in child.named_children(&mut child.walk()) {
2529 let name = self.supertype_name(iface);
2530 self.push_ref(class_row, &name, implements_kind, iface);
2531 }
2532 }
2533 // TS `interface Repo<T> extends Base, ns.Shape, Store<T>` — each
2534 // supertype is a `type` of the clause; a `generic_type` is named
2535 // by its `name` field (`Store`, never `Store<T>`).
2536 "extends_type_clause" => {
2537 let mut cursor = child.walk();
2538 let targets: Vec<Node<'t>> = child.children_by_field_name("type", &mut cursor).collect();
2539 for target in targets {
2540 let named = if target.kind() == "generic_type" {
2541 target.child_by_field_name("name").unwrap_or(target)
2542 } else {
2543 target
2544 };
2545 let name = self.text(named).to_string();
2546 self.push_ref(class_row, &name, extends_kind, target);
2547 }
2548 }
2549 // JS `class Foo extends Bar` — class_heritage holds a bare
2550 // identifier without an extends_clause wrapper.
2551 "identifier" | "type_identifier" if node.kind() == "class_heritage" => {
2552 let name = self.text(child).to_string();
2553 self.push_ref(class_row, &name, extends_kind, child);
2554 }
2555 // TS class_heritage wraps extends/implements — recurse.
2556 "field_declaration_list" | "class_heritage" => {
2557 self.extract_inheritance(child, class_row);
2558 }
2559 _ => {}
2560 }
2561 }
2562 }
2563
2564 /// supertypeName — a parameterized supertype (`generic_type`) by the name
2565 /// before its type arguments: `Store` for `implements Store<string>`.

Callers 3

extract_classMethod · 0.45
extract_interfaceMethod · 0.45
extract_enumMethod · 0.45

Calls 7

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
walkMethod · 0.45
supertype_nameMethod · 0.45
push_refMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected