(&mut self, node: Node<'t>)
| 1161 | // --- function-as-value refs (JAVA_SPEC: method references only) ---------------- |
| 1162 | |
| 1163 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1164 | let mode_field: Option<&str> = match node.kind() { |
| 1165 | "argument_list" => Some(""), // args: every named child |
| 1166 | "assignment_expression" => Some("right"), |
| 1167 | "variable_declarator" => Some("value"), |
| 1168 | _ => None, |
| 1169 | }; |
| 1170 | let Some(field) = mode_field else { return }; |
| 1171 | if self.stack.is_empty() { |
| 1172 | return; |
| 1173 | } |
| 1174 | let from = self.top_row(); |
| 1175 | |
| 1176 | let mut values: Vec<Node> = Vec::new(); |
| 1177 | if field.is_empty() { |
| 1178 | for c in node.named_children(&mut node.walk()) { |
| 1179 | values.push(c); |
| 1180 | } |
| 1181 | } else if field == "right" { |
| 1182 | if let Some(rhs) = node.child_by_field_name("right") { |
| 1183 | let lhs_text = node |
| 1184 | .child_by_field_name("left") |
| 1185 | .map(|l| self.text(l)) |
| 1186 | .unwrap_or(""); |
| 1187 | let lhs_last = util::lhs_last_name() |
| 1188 | .captures(lhs_text) |
| 1189 | .and_then(|c| c.get(1)) |
| 1190 | .map(|m| m.as_str()); |
| 1191 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 1192 | values.push(rhs); |
| 1193 | } |
| 1194 | } |
| 1195 | } else if let Some(v) = node.child_by_field_name("value") { |
| 1196 | // varinit — destructuring patterns don't exist in Java. |
| 1197 | values.push(v); |
| 1198 | } |
| 1199 | |
| 1200 | for v in values { |
| 1201 | if v.kind() != "method_reference" { |
| 1202 | continue; // idTypes is EMPTY for Java — only method references |
| 1203 | } |
| 1204 | let mut last_ident: Option<Node> = None; |
| 1205 | for c in v.named_children(&mut v.walk()) { |
| 1206 | if c.kind() == "identifier" { |
| 1207 | last_ident = Some(c); |
| 1208 | } |
| 1209 | } |
| 1210 | let Some(last) = last_ident else { continue }; |
| 1211 | let m = self.text(last); |
| 1212 | let text = self.text(v); |
| 1213 | let name = if text.starts_with("this::") || text.starts_with("super::") { |
| 1214 | format!("this.{m}") |
| 1215 | } else if let Some(c) = method_ref_type_re().captures(text) { |
| 1216 | if m == "new" { |
| 1217 | continue; |
| 1218 | } |
| 1219 | format!("{}::{m}", &c[1]) |
| 1220 | } else { |
no test coverage detected