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