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

Method extract_inheritance

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

Source from the content-addressed store, hash-verified

2128 // --- extractInheritance (TS/JS clauses) ---------------------------------------------------
2129
2130 pub(super) fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
2131 stack_guard!();
2132 let extends_kind = edge_kind_index("extends").unwrap();
2133 let implements_kind = edge_kind_index("implements").unwrap();
2134 for i in 0..node.named_child_count() {
2135 let Some(child) = node.named_child(i) else { continue };
2136 match child.kind() {
2137 // TS `extends_clause` (the other spellings are other grammars').
2138 "extends_clause" | "superclass" | "base_clause" | "extends_interfaces" => {
2139 if let Some(target) = child.named_child(0) {
2140 let name = self.supertype_name(target);
2141 self.push_ref(class_row, &name, extends_kind, target);
2142 }
2143 }
2144 "implements_clause" | "class_interface_clause" | "super_interfaces" | "interfaces" => {
2145 for j in 0..child.named_child_count() {
2146 if let Some(iface) = child.named_child(j) {
2147 let name = self.supertype_name(iface);
2148 self.push_ref(class_row, &name, implements_kind, iface);
2149 }
2150 }
2151 }
2152 // TS `interface Repo<T> extends Base, ns.Shape, Store<T>` — each
2153 // supertype is a `type` of the clause; a `generic_type` is named
2154 // by its `name` field (`Store`, never `Store<T>`).
2155 "extends_type_clause" => {
2156 let mut cursor = child.walk();
2157 let targets: Vec<Node<'t>> = child.children_by_field_name("type", &mut cursor).collect();
2158 for target in targets {
2159 let named = if target.kind() == "generic_type" {
2160 target.child_by_field_name("name").unwrap_or(target)
2161 } else {
2162 target
2163 };
2164 let name = self.text(named).to_string();
2165 self.push_ref(class_row, &name, extends_kind, target);
2166 }
2167 }
2168 // JS `class Foo extends Bar` — class_heritage holds a bare
2169 // identifier without an extends_clause wrapper.
2170 "identifier" | "type_identifier" if node.kind() == "class_heritage" => {
2171 let name = self.text(child).to_string();
2172 self.push_ref(class_row, &name, extends_kind, child);
2173 }
2174 // TS class_heritage wraps extends/implements — recurse.
2175 "field_declaration_list" | "class_heritage" => {
2176 self.extract_inheritance(child, class_row);
2177 }
2178 _ => {}
2179 }
2180 }
2181 }
2182
2183 /// supertypeName — a parameterized supertype (`generic_type`) by the name
2184 /// 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