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

Method extract_inheritance

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

Source from the content-addressed store, hash-verified

2024 // --- extractInheritance — the dart rows (:5368-5393, :5437-5459) ------
2025
2026 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
2027 // The type an extension is `on` — a `references` edge (#2327).
2028 if node.kind() == "extension_declaration" {
2029 let mut oc = node.walk();
2030 let on_types: Vec<Node<'t>> = node.children_by_field_name("class", &mut oc).collect();
2031 for on_type in on_types {
2032 self.type_refs_dart(on_type, class_row);
2033 }
2034 }
2035 let mut cursor = node.walk();
2036 let kids: Vec<Node<'t>> = node.named_children(&mut cursor).collect();
2037 for child in kids {
2038 if child.kind() == "mixin_application_class" {
2039 // `class A = B with M implements I;` — extends B, implements
2040 // each mixin and interface, in source order.
2041 let mut cc = child.walk();
2042 let application = child.named_children(&mut cc).find(|c| c.kind() == "mixin_application");
2043 let Some(application) = application else { continue };
2044 let mut ac = application.walk();
2045 let parts: Vec<Node<'t>> = application.named_children(&mut ac).collect();
2046 for t in parts {
2047 match t.kind() {
2048 "type_identifier" => {
2049 let name = self.text(t).to_string();
2050 self.push_ref_at(class_row, &name, "extends", t);
2051 }
2052 "mixins" | "interfaces" => {
2053 let mut mc = t.walk();
2054 let targets: Vec<Node<'t>> = t.named_children(&mut mc).collect();
2055 for m in targets {
2056 if t.kind() == "interfaces" || m.kind() == "type_identifier" {
2057 let name = self.text(m).to_string();
2058 self.push_ref_at(class_row, &name, "implements", m);
2059 }
2060 }
2061 }
2062 _ => {}
2063 }
2064 }
2065 } else if child.kind() == "superclass" {
2066 // extends type + `with` mixins (implements) — dart branch.
2067 let mut cc = child.walk();
2068 let targets: Vec<Node<'t>> = child.named_children(&mut cc).collect();
2069 for t in targets {
2070 if t.kind() == "mixins" {
2071 let mut mc = t.walk();
2072 let mixins: Vec<Node<'t>> = t.named_children(&mut mc).collect();
2073 for m in mixins {
2074 if m.kind() == "type_identifier" {
2075 let name = self.text(m).to_string();
2076 self.push_ref_at(class_row, &name, "implements", m);
2077 }
2078 }
2079 } else if t.kind() == "type_identifier" {
2080 let name = self.text(t).to_string();
2081 self.push_ref_at(class_row, &name, "extends", t);
2082 }
2083 }

Callers 2

extract_classMethod · 0.45
extract_enumMethod · 0.45

Calls 5

type_refs_dartMethod · 0.80
textMethod · 0.65
walkMethod · 0.45
collectMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected