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

Method extract_method

codegraph-kernel/src/ccpp/mod.rs:1308–1376  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1306 }
1307
1308 fn extract_method(&mut self, node: Node<'t>) {
1309 stack_guard!();
1310 let receiver_type = if self.variant == Variant::Cpp { self.receiver_type_of(node) } else { None };
1311
1312 if !self.inside_class_like() && receiver_type.is_none() {
1313 // (object-literal parents don't occur in c/cpp) — treat as function.
1314 self.extract_function(node);
1315 return;
1316 }
1317
1318 let name = self.extract_name(node);
1319 if self.is_misparsed_function(&name, node) {
1320 if let Some(body) = node.child_by_field_name("body") {
1321 self.visit_function_body(body);
1322 }
1323 return;
1324 }
1325
1326 let extra = Extra {
1327 docstring: preceding_docstring(node, self.src),
1328 signature: self.constructor_signature(node),
1329 visibility: if self.variant == Variant::Cpp { self.visibility_of(node) } else { None },
1330 is_abstract: if self.variant == Variant::Cpp && self.is_cpp_pure_virtual_method_decl(node) {
1331 Some(true)
1332 } else {
1333 None
1334 },
1335 return_type: self.return_type_of(node),
1336 qualified_name: receiver_type
1337 .as_ref()
1338 .map(|r| self.compose_receiver_qualified_name(r, &name)),
1339 ..Extra::default() // extractMethod passes no isExported
1340 };
1341 let Some(row) = self.create_node("method", &name, node, extra) else { return };
1342
1343 // Out-of-line def: contains edge from the FIRST earlier-in-file
1344 // struct/class/enum/trait node of the receiver's name.
1345 if let Some(receiver_type) = &receiver_type {
1346 if !self.inside_class_like() {
1347 let owner_row = self
1348 .nodes_meta
1349 .iter()
1350 .position(|m| {
1351 m.name == *receiver_type
1352 && matches!(m.kind, "struct" | "union" | "class" | "enum" | "trait")
1353 })
1354 .map(|i| i as u32);
1355 if let Some(owner_row) = owner_row {
1356 self.tables.push_edge(&EdgeRow {
1357 source_idx: owner_row,
1358 target_idx: row,
1359 kind: edge_kind_index("contains").unwrap(),
1360 provenance: 0,
1361 line: NONE,
1362 column: NONE,
1363 metadata_json: NONE_STR,
1364 source_id_str: NONE_STR,
1365 target_id_str: NONE_STR,

Callers 2

dispatch_nodeMethod · 0.45
extract_functionMethod · 0.45

Calls 15

preceding_docstringFunction · 0.85
edge_kind_indexFunction · 0.85
mapMethod · 0.80
positionMethod · 0.80
push_edgeMethod · 0.80
pushMethod · 0.80
unwrapMethod · 0.60
receiver_type_ofMethod · 0.45
inside_class_likeMethod · 0.45
extract_functionMethod · 0.45

Tested by

no test coverage detected