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

Method extract_method

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

Source from the content-addressed store, hash-verified

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

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
positionMethod · 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

Tested by

no test coverage detected