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

Method extract_inheritance

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

Source from the content-addressed store, hash-verified

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