extractAnonymousClass — `new T() { ... }`.
(&mut self, node: Node<'t>, body: Node<'t>)
| 960 | |
| 961 | /// extractAnonymousClass — `new T() { ... }`. |
| 962 | fn extract_anonymous_class(&mut self, node: Node<'t>, body: Node<'t>) { |
| 963 | stack_guard!(); |
| 964 | let type_node = node |
| 965 | .child_by_field_name("constructor") |
| 966 | .or_else(|| node.child_by_field_name("type")) |
| 967 | .or_else(|| node.child_by_field_name("name")) |
| 968 | .or_else(|| node.named_child(0)); |
| 969 | let raw = type_node.map(|t| self.text(t).to_string()).unwrap_or_else(|| "Object".to_string()); |
| 970 | // The supertype as written (`Api.Listener` for `new Api.Listener() {…}`), |
| 971 | // type arguments cut from the first `<` past index 0, trimmed — the |
| 972 | // `extends` ref's name. The anon class's own name keeps the last segment. |
| 973 | let mut written = raw.clone(); |
| 974 | if let Some(lt) = written.find('<') { |
| 975 | if lt > 0 { |
| 976 | written.truncate(lt); |
| 977 | } |
| 978 | } |
| 979 | let mut written = written.trim().to_string(); |
| 980 | if written.is_empty() { |
| 981 | written = "Object".to_string(); |
| 982 | } |
| 983 | let mut type_name = strip_generic_and_qualifier(&raw); |
| 984 | if type_name.is_empty() { |
| 985 | type_name = "Object".to_string(); |
| 986 | } |
| 987 | |
| 988 | let anon_name = format!("<{type_name}$anon@{}>", node.start_position().row + 1); |
| 989 | let Some(row) = self.create_node("class", &anon_name, node, Extra::default()) else { |
| 990 | return; |
| 991 | }; |
| 992 | // Bug-for-bug: the TS code uses `startPosition.row` (0-based) as the |
| 993 | // LINE here — the one place it forgets the +1. |
| 994 | let (line, column) = match type_node { |
| 995 | Some(t) => (t.start_position().row as u32, self.col_of(t)), |
| 996 | None => (node.start_position().row as u32, self.col_of(node)), |
| 997 | }; |
| 998 | self.push_ref(row, &written, edge_kind_index("extends").unwrap(), line, column); |
| 999 | |
| 1000 | self.stack.push(Scope { row, kind: "class", name: anon_name }); |
| 1001 | for i in 0..body.named_child_count() { |
| 1002 | if let Some(c) = body.named_child(i) { |
| 1003 | self.visit_node(c); |
| 1004 | } |
| 1005 | } |
| 1006 | self.stack.pop(); |
| 1007 | } |
| 1008 | |
| 1009 | /// extractStaticMemberRef — `Type.CONST` value reads (java: field_access). |
| 1010 | fn extract_static_member_ref(&mut self, node: Node<'t>) { |
no test coverage detected