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

Method extract_call

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

extractCall — the Java method_invocation paths.

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

Source from the content-addressed store, hash-verified

853
854 /// extractCall — the Java method_invocation paths.
855 fn extract_call(&mut self, node: Node<'t>) {
856 if self.stack.is_empty() {
857 return;
858 }
859 let caller = self.top_row();
860 let name_field = node.child_by_field_name("name");
861 let object_field = node
862 .child_by_field_name("object")
863 .or_else(|| node.child_by_field_name("scope"));
864
865 let mut callee_name = String::new();
866 if let (Some(name_field), Some(object_field)) = (name_field, object_field) {
867 let method_name = self.text(name_field);
868
869 // Static-factory / fluent chain: `Foo.getInstance().bar()` →
870 // `<inner-receiver>.<inner-method>().<method>` (#645/#608).
871 if !method_name.is_empty() && object_field.kind() == "method_invocation" {
872 let inner_obj = object_field.child_by_field_name("object");
873 let inner_name = object_field.child_by_field_name("name");
874 if let (Some(io), Some(inm)) = (inner_obj, inner_name) {
875 let callee = format!("{}.{}().{}", self.text(io), self.text(inm), method_name);
876 self.push_ref_at(caller, &callee, edge_kind_index("calls").unwrap(), node);
877 return;
878 }
879 }
880
881 // `this.userbo.toLogin2()` — unwrap the field after `this.`.
882 let receiver_name = if object_field.kind() == "field_access" {
883 let inner = object_field.child_by_field_name("object");
884 let fld = object_field.child_by_field_name("field");
885 match (inner, fld) {
886 (Some(inner), Some(fld))
887 if matches!(inner.kind(), "this" | "this_expression") =>
888 {
889 self.text(fld).to_string()
890 }
891 _ => self.text(object_field).to_string(),
892 }
893 } else {
894 self.text(object_field).to_string()
895 };
896 let receiver_name = receiver_name.strip_prefix('$').unwrap_or(&receiver_name);
897
898 if !method_name.is_empty() {
899 if matches!(receiver_name, "self" | "this" | "cls" | "super" | "parent" | "static") {
900 callee_name = method_name.to_string();
901 } else {
902 callee_name = format!("{receiver_name}.{method_name}");
903 }
904 }
905 } else {
906 // Bare call `foo()` — the generic tail: function field ?? first child.
907 let func = node
908 .child_by_field_name("function")
909 .or_else(|| node.named_child(0));
910 if let Some(func) = func {
911 callee_name = self.text(func).to_string();
912 }

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