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

Method extract_inheritance

codegraph-kernel/src/kotlin.rs:1116–1152  ·  view source on GitHub ↗

extractInheritance — delegation_specifier: user_type ?? its constructor_invocation's user_type → FIRST type_identifier → ONE `extends` ref at the typeId (interfaces ride extends too; qualified supertypes take the FIRST segment — `com`; `by`-delegation emits NOTHING).

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

Source from the content-addressed store, hash-verified

1114 /// supertypes take the FIRST segment — `com`; `by`-delegation emits
1115 /// NOTHING).
1116 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
1117 let extends_kind = edge_kind_index("extends").unwrap();
1118 for i in 0..node.named_child_count() {
1119 let Some(child) = node.named_child(i) else { continue };
1120 if child.kind() != "delegation_specifier" {
1121 continue;
1122 }
1123 let user_type = (0..child.named_child_count())
1124 .filter_map(|j| child.named_child(j))
1125 .find(|c| c.kind() == "user_type");
1126 let ctor_inv = (0..child.named_child_count())
1127 .filter_map(|j| child.named_child(j))
1128 .find(|c| c.kind() == "constructor_invocation");
1129 let target = user_type.or(ctor_inv);
1130 let Some(target) = target else { continue };
1131 let type_id: Node = if target.kind() == "user_type" {
1132 (0..target.named_child_count())
1133 .filter_map(|j| target.named_child(j))
1134 .find(|c| c.kind() == "type_identifier")
1135 .unwrap_or(target)
1136 } else {
1137 // constructor_invocation → its user_type → first type_identifier
1138 let ut = (0..target.named_child_count())
1139 .filter_map(|j| target.named_child(j))
1140 .find(|c| c.kind() == "user_type");
1141 match ut {
1142 Some(ut) => (0..ut.named_child_count())
1143 .filter_map(|j| ut.named_child(j))
1144 .find(|c| c.kind() == "type_identifier")
1145 .unwrap_or(ut),
1146 None => target,
1147 }
1148 };
1149 let name = self.text(type_id).to_string();
1150 self.push_ref_at(class_row, &name, extends_kind, type_id);
1151 }
1152 }
1153
1154 /// extractDecoratorsFor — kotlin annotations inside `modifiers`:
1155 /// `@Marker` (user_type child) → decorates ref; `@Anno(args)`

Callers 3

extract_classMethod · 0.45
extract_interfaceMethod · 0.45
extract_enumMethod · 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