(&mut self, node: Node<'t>)
| 1203 | // --- function-as-value refs (JAVA_SPEC: method references only) ---------------- |
| 1204 | |
| 1205 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1206 | let mode_field: Option<&str> = match node.kind() { |
| 1207 | "argument_list" => Some(""), // args: every named child |
| 1208 | "assignment_expression" => Some("right"), |
| 1209 | "variable_declarator" => Some("value"), |
| 1210 | _ => None, |
| 1211 | }; |
| 1212 | let Some(field) = mode_field else { return }; |
| 1213 | if self.stack.is_empty() { |
| 1214 | return; |
| 1215 | } |
| 1216 | let from = self.top_row(); |
| 1217 | |
| 1218 | let mut values: Vec<Node> = Vec::new(); |
| 1219 | if field.is_empty() { |
| 1220 | for i in 0..node.named_child_count() { |
| 1221 | if let Some(c) = node.named_child(i) { |
| 1222 | values.push(c); |
| 1223 | } |
| 1224 | } |
| 1225 | } else if field == "right" { |
| 1226 | if let Some(rhs) = node.child_by_field_name("right") { |
| 1227 | let lhs_text = node |
| 1228 | .child_by_field_name("left") |
| 1229 | .map(|l| self.text(l)) |
| 1230 | .unwrap_or(""); |
| 1231 | let lhs_last = util::lhs_last_name() |
| 1232 | .captures(lhs_text) |
| 1233 | .and_then(|c| c.get(1)) |
| 1234 | .map(|m| m.as_str()); |
| 1235 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 1236 | values.push(rhs); |
| 1237 | } |
| 1238 | } |
| 1239 | } else if let Some(v) = node.child_by_field_name("value") { |
| 1240 | // varinit — destructuring patterns don't exist in Java. |
| 1241 | values.push(v); |
| 1242 | } |
| 1243 | |
| 1244 | for v in values { |
| 1245 | if v.kind() != "method_reference" { |
| 1246 | continue; // idTypes is EMPTY for Java — only method references |
| 1247 | } |
| 1248 | let mut last_ident: Option<Node> = None; |
| 1249 | for i in 0..v.named_child_count() { |
| 1250 | if let Some(c) = v.named_child(i) { |
| 1251 | if c.kind() == "identifier" { |
| 1252 | last_ident = Some(c); |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | let Some(last) = last_ident else { continue }; |
| 1257 | let m = self.text(last); |
| 1258 | let text = self.text(v); |
| 1259 | let name = if text.starts_with("this::") || text.starts_with("super::") { |
| 1260 | format!("this.{m}") |
| 1261 | } else if let Some(c) = method_ref_type_re().captures(text) { |
| 1262 | if m == "new" { |
no test coverage detected