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

Method extract_anonymous_class

codegraph-kernel/src/csharp.rs:1089–1121  ·  view source on GitHub ↗

extractAnonymousClass — `new T() { ... }`. The C# grammar never produces a class_body/declaration_list child on object_creation (object initializers are initializer_expression), so this is unreachable — mirrored from the shared TS path like java.rs.

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

Source from the content-addressed store, hash-verified

1087 /// (object initializers are initializer_expression), so this is
1088 /// unreachable — mirrored from the shared TS path like java.rs.
1089 fn extract_anonymous_class(&mut self, node: Node<'t>, body: Node<'t>) {
1090 let type_node = node
1091 .child_by_field_name("constructor")
1092 .or_else(|| node.child_by_field_name("type"))
1093 .or_else(|| node.child_by_field_name("name"))
1094 .or_else(|| node.named_child(0));
1095 let mut type_name =
1096 type_node.map(|t| self.text(t).to_string()).unwrap_or_else(|| "Object".to_string());
1097 type_name = strip_generic_and_qualifier(&type_name);
1098 if type_name.is_empty() {
1099 type_name = "Object".to_string();
1100 }
1101
1102 let anon_name = format!("<{type_name}$anon@{}>", node.start_position().row + 1);
1103 let Some(row) = self.create_node("class", &anon_name, node, Extra::default()) else {
1104 return;
1105 };
1106 // Bug-for-bug: the TS code uses `startPosition.row` (0-based) as the
1107 // LINE here — the one place it forgets the +1.
1108 let (line, column) = match type_node {
1109 Some(t) => (t.start_position().row as u32, self.col_of(t)),
1110 None => (node.start_position().row as u32, self.col_of(node)),
1111 };
1112 self.push_ref(row, &type_name, edge_kind_index("extends").unwrap(), line, column);
1113
1114 self.stack.push(Scope { row, kind: "class", name: anon_name });
1115 for i in 0..body.named_child_count() {
1116 if let Some(c) = body.named_child(i) {
1117 self.visit_node(c);
1118 }
1119 }
1120 self.stack.pop();
1121 }
1122
1123 /// extractStaticMemberRef — csharp ∈ STATIC_MEMBER_LANGS; C#'s
1124 /// member-access node with the `expression` receiver field.

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