MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_anonymous_class

Method extract_anonymous_class

codegraph-kernel/src/java.rs:960–1005  ·  view source on GitHub ↗

extractAnonymousClass — `new T() { ... }`.

(&mut self, node: Node<'t>, body: Node<'t>)

Source from the content-addressed store, hash-verified

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

Callers 2

visit_nodeMethod · 0.45

Calls 10

edge_kind_indexFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
create_nodeMethod · 0.45
col_ofMethod · 0.45
push_refMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected