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

Method extract_method

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

Source from the content-addressed store, hash-verified

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