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

Method extract_anonymous_class

codegraph-kernel/src/csharp.rs:1213–1246  ·  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

1211 /// (object initializers are initializer_expression), so this is
1212 /// unreachable — mirrored from the shared TS path like java.rs.
1213 fn extract_anonymous_class(&mut self, node: Node<'t>, body: Node<'t>) {
1214 stack_guard!();
1215 let type_node = node
1216 .child_by_field_name("constructor")
1217 .or_else(|| node.child_by_field_name("type"))
1218 .or_else(|| node.child_by_field_name("name"))
1219 .or_else(|| node.named_child(0));
1220 let mut type_name =
1221 type_node.map(|t| self.text(t).to_string()).unwrap_or_else(|| "Object".to_string());
1222 type_name = strip_generic_and_qualifier(&type_name);
1223 if type_name.is_empty() {
1224 type_name = "Object".to_string();
1225 }
1226
1227 let anon_name = format!("<{type_name}$anon@{}>", node.start_position().row + 1);
1228 let Some(row) = self.create_node("class", &anon_name, node, Extra::default()) else {
1229 return;
1230 };
1231 // Bug-for-bug: the TS code uses `startPosition.row` (0-based) as the
1232 // LINE here — the one place it forgets the +1.
1233 let (line, column) = match type_node {
1234 Some(t) => (t.start_position().row as u32, self.col_of(t)),
1235 None => (node.start_position().row as u32, self.col_of(node)),
1236 };
1237 self.push_ref(row, &type_name, edge_kind_index("extends").unwrap(), line, column);
1238
1239 self.stack.push(Scope { row, kind: "class", name: anon_name });
1240 for i in 0..body.named_child_count() {
1241 if let Some(c) = body.named_child(i) {
1242 self.visit_node(c);
1243 }
1244 }
1245 self.stack.pop();
1246 }
1247
1248 /// extractStaticMemberRef — csharp ∈ STATIC_MEMBER_LANGS; C#'s
1249 /// member-access node with the `expression` receiver field.

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