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

Method extract_anonymous_class

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

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

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

Source from the content-addressed store, hash-verified

902
903 /// extractAnonymousClass — `new T() { ... }`.
904 fn extract_anonymous_class(&mut self, node: Node<'t>, body: Node<'t>) {
905 let type_node = node
906 .child_by_field_name("constructor")
907 .or_else(|| node.child_by_field_name("type"))
908 .or_else(|| node.child_by_field_name("name"))
909 .or_else(|| node.named_child(0));
910 let mut type_name = type_node.map(|t| self.text(t).to_string()).unwrap_or_else(|| "Object".to_string());
911 type_name = strip_generic_and_qualifier(&type_name);
912 if type_name.is_empty() {
913 type_name = "Object".to_string();
914 }
915
916 let anon_name = format!("<{type_name}$anon@{}>", node.start_position().row + 1);
917 let Some(row) = self.create_node("class", &anon_name, node, Extra::default()) else {
918 return;
919 };
920 // Bug-for-bug: the TS code uses `startPosition.row` (0-based) as the
921 // LINE here — the one place it forgets the +1.
922 let (line, column) = match type_node {
923 Some(t) => (t.start_position().row as u32, self.col_of(t)),
924 None => (node.start_position().row as u32, self.col_of(node)),
925 };
926 self.push_ref(row, &type_name, edge_kind_index("extends").unwrap(), line, column);
927
928 self.stack.push(Scope { row, kind: "class", name: anon_name });
929 for i in 0..body.named_child_count() {
930 if let Some(c) = body.named_child(i) {
931 self.visit_node(c);
932 }
933 }
934 self.stack.pop();
935 }
936
937 /// extractStaticMemberRef — `Type.CONST` value reads (java: field_access).
938 fn extract_static_member_ref(&mut self, node: Node<'t>) {

Callers 2

visit_nodeMethod · 0.45

Calls 8

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
textMethod · 0.45
create_nodeMethod · 0.45
col_ofMethod · 0.45
push_refMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected