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

Method extract_method

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

Source from the content-addressed store, hash-verified

889 }
890
891 fn extract_method(&mut self, node: Node<'t>) {
892 let receiver_type = if self.variant == Variant::Cpp { self.receiver_type_of(node) } else { None };
893
894 if !self.inside_class_like() && receiver_type.is_none() {
895 // (object-literal parents don't occur in c/cpp) — treat as function.
896 self.extract_function(node);
897 return;
898 }
899
900 let name = self.extract_name(node);
901 if self.is_misparsed_function(&name, node) {
902 if let Some(body) = node.child_by_field_name("body") {
903 self.visit_function_body(body);
904 }
905 return;
906 }
907
908 let extra = Extra {
909 docstring: preceding_docstring(node, self.src),
910 visibility: if self.variant == Variant::Cpp { self.visibility_of(node) } else { None },
911 return_type: self.return_type_of(node),
912 qualified_name: receiver_type
913 .as_ref()
914 .map(|r| self.compose_receiver_qualified_name(r, &name)),
915 ..Extra::default() // extractMethod passes no isExported
916 };
917 let Some(row) = self.create_node("method", &name, node, extra) else { return };
918
919 // Out-of-line def: contains edge from the FIRST earlier-in-file
920 // struct/class/enum/trait node of the receiver's name.
921 if let Some(receiver_type) = &receiver_type {
922 if !self.inside_class_like() {
923 let owner_row = self
924 .nodes_meta
925 .iter()
926 .position(|m| {
927 m.name == *receiver_type
928 && matches!(m.kind, "struct" | "class" | "enum" | "trait")
929 })
930 .map(|i| i as u32);
931 if let Some(owner_row) = owner_row {
932 self.tables.push_edge(&EdgeRow {
933 source_idx: owner_row,
934 target_idx: row,
935 kind: edge_kind_index("contains").unwrap(),
936 provenance: 0,
937 line: NONE,
938 column: NONE,
939 metadata_json: NONE_STR,
940 source_id_str: NONE_STR,
941 target_id_str: NONE_STR,
942 });
943 }
944 }
945 }
946
947 self.stack.push(Scope { row, kind: "method", name });
948 if let Some(body) = node.child_by_field_name("body") {

Callers 2

visit_nodeMethod · 0.45
extract_functionMethod · 0.45

Calls 14

preceding_docstringFunction · 0.85
edge_kind_indexFunction · 0.85
is_misparsed_functionMethod · 0.80
push_edgeMethod · 0.80
unwrapMethod · 0.60
receiver_type_ofMethod · 0.45
inside_class_likeMethod · 0.45
extract_functionMethod · 0.45
extract_nameMethod · 0.45
visit_function_bodyMethod · 0.45
visibility_ofMethod · 0.45

Tested by

no test coverage detected