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

Method extract_inheritance

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

Source from the content-addressed store, hash-verified

1990 // --- extractInheritance (TS/JS clauses) ---------------------------------------------------
1991
1992 pub(super) fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
1993 stack_guard!();
1994 let extends_kind = edge_kind_index("extends").unwrap();
1995 let implements_kind = edge_kind_index("implements").unwrap();
1996 for i in 0..node.named_child_count() {
1997 let Some(child) = node.named_child(i) else { continue };
1998 match child.kind() {
1999 // TS `extends_clause` (the other spellings are other grammars').
2000 "extends_clause" | "superclass" | "base_clause" | "extends_interfaces" => {
2001 if let Some(target) = child.named_child(0) {
2002 let name = self.supertype_name(target);
2003 self.push_ref(class_row, &name, extends_kind, target);
2004 }
2005 }
2006 "implements_clause" | "class_interface_clause" | "super_interfaces" | "interfaces" => {
2007 for j in 0..child.named_child_count() {
2008 if let Some(iface) = child.named_child(j) {
2009 let name = self.supertype_name(iface);
2010 self.push_ref(class_row, &name, implements_kind, iface);
2011 }
2012 }
2013 }
2014 // TS `interface Repo<T> extends Base, ns.Shape, Store<T>` — each
2015 // supertype is a `type` of the clause; a `generic_type` is named
2016 // by its `name` field (`Store`, never `Store<T>`).
2017 "extends_type_clause" => {
2018 let mut cursor = child.walk();
2019 let targets: Vec<Node<'t>> = child.children_by_field_name("type", &mut cursor).collect();
2020 for target in targets {
2021 let named = if target.kind() == "generic_type" {
2022 target.child_by_field_name("name").unwrap_or(target)
2023 } else {
2024 target
2025 };
2026 let name = self.text(named).to_string();
2027 self.push_ref(class_row, &name, extends_kind, target);
2028 }
2029 }
2030 // JS `class Foo extends Bar` — class_heritage holds a bare
2031 // identifier without an extends_clause wrapper.
2032 "identifier" | "type_identifier" if node.kind() == "class_heritage" => {
2033 let name = self.text(child).to_string();
2034 self.push_ref(class_row, &name, extends_kind, child);
2035 }
2036 // TS class_heritage wraps extends/implements — recurse.
2037 "field_declaration_list" | "class_heritage" => {
2038 self.extract_inheritance(child, class_row);
2039 }
2040 _ => {}
2041 }
2042 }
2043 }
2044
2045 /// supertypeName — a parameterized supertype (`generic_type`) by the name
2046 /// 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
walkMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
supertype_nameMethod · 0.45
push_refMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected