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

Method extract_method

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

Source from the content-addressed store, hash-verified

1049 }
1050
1051 fn extract_method(&mut self, node: Node<'t>) {
1052 stack_guard!();
1053 let receiver_type = if self.variant == Variant::Cpp { self.receiver_type_of(node) } else { None };
1054
1055 if !self.inside_class_like() && receiver_type.is_none() {
1056 // (object-literal parents don't occur in c/cpp) — treat as function.
1057 self.extract_function(node);
1058 return;
1059 }
1060
1061 let name = self.extract_name(node);
1062 if self.is_misparsed_function(&name, node) {
1063 if let Some(body) = node.child_by_field_name("body") {
1064 self.visit_function_body(body);
1065 }
1066 return;
1067 }
1068
1069 let extra = Extra {
1070 docstring: preceding_docstring(node, self.src),
1071 signature: self.constructor_signature(node),
1072 visibility: if self.variant == Variant::Cpp { self.visibility_of(node) } else { None },
1073 is_abstract: if self.variant == Variant::Cpp && self.is_cpp_pure_virtual_method_decl(node) {
1074 Some(true)
1075 } else {
1076 None
1077 },
1078 return_type: self.return_type_of(node),
1079 qualified_name: receiver_type
1080 .as_ref()
1081 .map(|r| self.compose_receiver_qualified_name(r, &name)),
1082 ..Extra::default() // extractMethod passes no isExported
1083 };
1084 let Some(row) = self.create_node("method", &name, node, extra) else { return };
1085
1086 // Out-of-line def: contains edge from the FIRST earlier-in-file
1087 // struct/class/enum/trait node of the receiver's name.
1088 if let Some(receiver_type) = &receiver_type {
1089 if !self.inside_class_like() {
1090 let owner_row = self
1091 .nodes_meta
1092 .iter()
1093 .position(|m| {
1094 m.name == *receiver_type
1095 && matches!(m.kind, "struct" | "union" | "class" | "enum" | "trait")
1096 })
1097 .map(|i| i as u32);
1098 if let Some(owner_row) = owner_row {
1099 self.tables.push_edge(&EdgeRow {
1100 source_idx: owner_row,
1101 target_idx: row,
1102 kind: edge_kind_index("contains").unwrap(),
1103 provenance: 0,
1104 line: NONE,
1105 column: NONE,
1106 metadata_json: NONE_STR,
1107 source_id_str: NONE_STR,
1108 target_id_str: NONE_STR,

Callers 2

visit_nodeMethod · 0.45
extract_functionMethod · 0.45

Calls 15

preceding_docstringFunction · 0.85
edge_kind_indexFunction · 0.85
is_misparsed_functionMethod · 0.80
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

Tested by

no test coverage detected