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

Method extract_method

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

Source from the content-addressed store, hash-verified

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