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

Method extract_anonymous_class

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

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

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

Source from the content-addressed store, hash-verified

939
940 /// extractAnonymousClass — `new T() { ... }`.
941 fn extract_anonymous_class(&mut self, node: Node<'t>, body: Node<'t>) {
942 stack_guard!();
943 let type_node = node
944 .child_by_field_name("constructor")
945 .or_else(|| node.child_by_field_name("type"))
946 .or_else(|| node.child_by_field_name("name"))
947 .or_else(|| node.named_child(0));
948 let raw = type_node.map(|t| self.text(t).to_string()).unwrap_or_else(|| "Object".to_string());
949 // The supertype as written (`Api.Listener` for `new Api.Listener() {…}`),
950 // type arguments cut from the first `<` past index 0, trimmed — the
951 // `extends` ref's name. The anon class's own name keeps the last segment.
952 let mut written = raw.clone();
953 if let Some(lt) = written.find('<') {
954 if lt > 0 {
955 written.truncate(lt);
956 }
957 }
958 let mut written = written.trim().to_string();
959 if written.is_empty() {
960 written = "Object".to_string();
961 }
962 let mut type_name = strip_generic_and_qualifier(&raw);
963 if type_name.is_empty() {
964 type_name = "Object".to_string();
965 }
966
967 let anon_name = format!("<{type_name}$anon@{}>", node.start_position().row + 1);
968 let Some(row) = self.create_node("class", &anon_name, node, Extra::default()) else {
969 return;
970 };
971 // Bug-for-bug: the TS code uses `startPosition.row` (0-based) as the
972 // LINE here — the one place it forgets the +1.
973 let (line, column) = match type_node {
974 Some(t) => (t.start_position().row as u32, self.col_of(t)),
975 None => (node.start_position().row as u32, self.col_of(node)),
976 };
977 self.push_ref(row, &written, edge_kind_index("extends").unwrap(), line, column);
978
979 self.stack.push(Scope { row, kind: "class", name: anon_name });
980 for c in body.named_children(&mut body.walk()) {
981 self.visit_node(c);
982 }
983 self.stack.pop();
984 }
985
986 /// extractStaticMemberRef — `Type.CONST` value reads (java: field_access).
987 fn extract_static_member_ref(&mut self, node: Node<'t>) {

Callers 2

visit_nodeMethod · 0.45

Calls 11

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
walkMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected