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

Method extract_call

codegraph-kernel/src/java.rs:874–940  ·  view source on GitHub ↗

extractCall — the Java method_invocation paths.

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

872
873 /// extractCall — the Java method_invocation paths.
874 fn extract_call(&mut self, node: Node<'t>) {
875 if self.stack.is_empty() {
876 return;
877 }
878 let caller = self.top_row();
879 let name_field = node.child_by_field_name("name");
880 let object_field = node
881 .child_by_field_name("object")
882 .or_else(|| node.child_by_field_name("scope"));
883
884 let mut callee_name = String::new();
885 if let (Some(name_field), Some(object_field)) = (name_field, object_field) {
886 let method_name = self.text(name_field);
887
888 // Static-factory / fluent chain: `Foo.getInstance().bar()` →
889 // `<inner-receiver>.<inner-method>().<method>` (#645/#608).
890 if !method_name.is_empty() && object_field.kind() == "method_invocation" {
891 let inner_obj = object_field.child_by_field_name("object");
892 let inner_name = object_field.child_by_field_name("name");
893 if let (Some(io), Some(inm)) = (inner_obj, inner_name) {
894 let callee = format!("{}.{}().{}", self.text(io), self.text(inm), method_name);
895 self.push_ref_at(caller, &callee, edge_kind_index("calls").unwrap(), node);
896 return;
897 }
898 }
899
900 // `this.userbo.toLogin2()` — unwrap the field after `this.`.
901 let receiver_name = if object_field.kind() == "field_access" {
902 let inner = object_field.child_by_field_name("object");
903 let fld = object_field.child_by_field_name("field");
904 match (inner, fld) {
905 (Some(inner), Some(fld))
906 if matches!(inner.kind(), "this" | "this_expression") =>
907 {
908 self.text(fld).to_string()
909 }
910 _ => self.text(object_field).to_string(),
911 }
912 } else {
913 self.text(object_field).to_string()
914 };
915 let receiver_name = receiver_name.strip_prefix('$').unwrap_or(&receiver_name);
916
917 if !method_name.is_empty() {
918 if matches!(receiver_name, "self" | "this" | "cls" | "super" | "parent" | "static") {
919 callee_name = method_name.to_string();
920 } else {
921 callee_name = format!("{receiver_name}.{method_name}");
922 }
923 }
924 } else {
925 // Bare call `foo()` — the generic tail: function field ?? first child.
926 let func = node
927 .child_by_field_name("function")
928 .or_else(|| node.named_child(0));
929 if let Some(func) = func {
930 callee_name = self.text(func).to_string();
931 }

Callers 2

visit_nodeMethod · 0.45

Calls 5

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected