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

Method extract_inheritance

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

extractInheritance — delegation_specifier: user_type ?? its constructor_invocation's user_type → ONE `extends` ref named by the user_type's type_identifiers joined with `.` (`Outer.Inner`, type arguments left out), at the first one (interfaces ride extends too; `by`-delegation emits NOTHING).

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

Source from the content-addressed store, hash-verified

1375 /// arguments left out), at the first one (interfaces ride extends too;
1376 /// `by`-delegation emits NOTHING).
1377 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
1378 let extends_kind = edge_kind_index("extends").unwrap();
1379 for i in 0..node.named_child_count() {
1380 let Some(child) = node.named_child(i) else { continue };
1381 if child.kind() != "delegation_specifier" {
1382 continue;
1383 }
1384 let user_type = (0..child.named_child_count())
1385 .filter_map(|j| child.named_child(j))
1386 .find(|c| c.kind() == "user_type");
1387 let ctor_inv = (0..child.named_child_count())
1388 .filter_map(|j| child.named_child(j))
1389 .find(|c| c.kind() == "constructor_invocation");
1390 let target = user_type.or(ctor_inv);
1391 let Some(target) = target else { continue };
1392 let type_node: Option<Node> = if target.kind() == "user_type" {
1393 Some(target)
1394 } else {
1395 (0..target.named_child_count())
1396 .filter_map(|j| target.named_child(j))
1397 .find(|c| c.kind() == "user_type")
1398 };
1399 let ids: Vec<Node> = match type_node {
1400 Some(t) => (0..t.named_child_count())
1401 .filter_map(|j| t.named_child(j))
1402 .filter(|c| c.kind() == "type_identifier")
1403 .collect(),
1404 None => Vec::new(),
1405 };
1406 let type_id: Node = ids.first().copied().or(type_node).unwrap_or(target);
1407 let name = if ids.is_empty() {
1408 self.text(type_id).to_string()
1409 } else {
1410 ids.iter().map(|c| self.text(*c)).collect::<Vec<_>>().join(".")
1411 };
1412 self.push_ref_at(class_row, &name, extends_kind, type_id);
1413 }
1414 }
1415
1416 /// extractKotlinObjectLiteral — `object : Api.Listener { … }`: an anonymous
1417 /// class. Headers (each delegation_specifier) walked first by the CURRENT

Callers 3

extract_classMethod · 0.45
extract_interfaceMethod · 0.45
extract_enumMethod · 0.45

Calls 8

edge_kind_indexFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
collectMethod · 0.45
firstMethod · 0.45
joinMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected