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