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

Method extract_inheritance

codegraph-kernel/src/go.rs:844–878  ·  view source on GitHub ↗

extractInheritance — the Go branches: interface embedding (constraint_elem) and struct embedding (field_declaration without a field_identifier), plus the field_declaration_list recursion.

(&mut self, node: Node<'t>, class_row: u32)

Source from the content-addressed store, hash-verified

842 /// (constraint_elem) and struct embedding (field_declaration without a
843 /// field_identifier), plus the field_declaration_list recursion.
844 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
845 let extends_kind = edge_kind_index("extends").unwrap();
846 for i in 0..node.named_child_count() {
847 let Some(child) = node.named_child(i) else { continue };
848 match child.kind() {
849 "constraint_elem" => {
850 let type_id = (0..child.named_child_count())
851 .filter_map(|j| child.named_child(j))
852 .find(|c| c.kind() == "type_identifier");
853 if let Some(type_id) = type_id {
854 let name = self.text(type_id).to_string();
855 self.push_ref_at(class_row, &name, extends_kind, type_id);
856 }
857 }
858 "field_declaration" => {
859 let has_field_identifier = (0..child.named_child_count())
860 .filter_map(|j| child.named_child(j))
861 .any(|c| c.kind() == "field_identifier");
862 if !has_field_identifier {
863 let type_id = (0..child.named_child_count())
864 .filter_map(|j| child.named_child(j))
865 .find(|c| c.kind() == "type_identifier");
866 if let Some(type_id) = type_id {
867 let name = self.text(type_id).to_string();
868 self.push_ref_at(class_row, &name, extends_kind, type_id);
869 }
870 }
871 }
872 "field_declaration_list" | "class_heritage" => {
873 self.extract_inheritance(child, class_row);
874 }
875 _ => {}
876 }
877 }
878 }
879
880 /// extractTypeAnnotations — Go's returnField is `result`.
881 fn extract_type_annotations(&mut self, node: Node<'t>, from_row: u32) {

Callers 1

extract_type_aliasMethod · 0.45

Calls 4

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
textMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected