(&mut self, node: Node<'t>)
| 1128 | // --- function-as-value refs (JAVA_SPEC: method references only) ---------------- |
| 1129 | |
| 1130 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1131 | let mode_field: Option<&str> = match node.kind() { |
| 1132 | "argument_list" => Some(""), // args: every named child |
| 1133 | "assignment_expression" => Some("right"), |
| 1134 | "variable_declarator" => Some("value"), |
| 1135 | _ => None, |
| 1136 | }; |
| 1137 | let Some(field) = mode_field else { return }; |
| 1138 | if self.stack.is_empty() { |
| 1139 | return; |
| 1140 | } |
| 1141 | let from = self.top_row(); |
| 1142 | |
| 1143 | let mut values: Vec<Node> = Vec::new(); |
| 1144 | if field.is_empty() { |
| 1145 | for i in 0..node.named_child_count() { |
| 1146 | if let Some(c) = node.named_child(i) { |
| 1147 | values.push(c); |
| 1148 | } |
| 1149 | } |
| 1150 | } else if field == "right" { |
| 1151 | if let Some(rhs) = node.child_by_field_name("right") { |
| 1152 | let lhs_text = node |
| 1153 | .child_by_field_name("left") |
| 1154 | .map(|l| self.text(l)) |
| 1155 | .unwrap_or(""); |
| 1156 | let lhs_last = util::lhs_last_name() |
| 1157 | .captures(lhs_text) |
| 1158 | .and_then(|c| c.get(1)) |
| 1159 | .map(|m| m.as_str()); |
| 1160 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 1161 | values.push(rhs); |
| 1162 | } |
| 1163 | } |
| 1164 | } else if let Some(v) = node.child_by_field_name("value") { |
| 1165 | // varinit — destructuring patterns don't exist in Java. |
| 1166 | values.push(v); |
| 1167 | } |
| 1168 | |
| 1169 | for v in values { |
| 1170 | if v.kind() != "method_reference" { |
| 1171 | continue; // idTypes is EMPTY for Java — only method references |
| 1172 | } |
| 1173 | let mut last_ident: Option<Node> = None; |
| 1174 | for i in 0..v.named_child_count() { |
| 1175 | if let Some(c) = v.named_child(i) { |
| 1176 | if c.kind() == "identifier" { |
| 1177 | last_ident = Some(c); |
| 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | let Some(last) = last_ident else { continue }; |
| 1182 | let m = self.text(last); |
| 1183 | let text = self.text(v); |
| 1184 | let name = if text.starts_with("this::") || text.starts_with("super::") { |
| 1185 | format!("this.{m}") |
| 1186 | } else if let Some(c) = method_ref_type_re().captures(text) { |
| 1187 | if m == "new" { |
no test coverage detected