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

Method extract_field

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

extractField (2046) — field_declaration; each declarator becomes a field/constant node anchored at the DECLARATOR, and the declarator — its `= initializer` — is walked with that node on the stack. Returns the walked declarators, for the fn-ref scan to skip.

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

Source from the content-addressed store, hash-verified

864 /// its `= initializer` — is walked with that node on the stack. Returns
865 /// the walked declarators, for the fn-ref scan to skip.
866 fn extract_field(&mut self, node: Node<'t>) -> Vec<usize> {
867 let mut walked = Vec::new();
868 let docstring = preceding_docstring(node, self.src);
869 let visibility = Some(self.visibility_of(node));
870 let is_static = Some(self.is_static(node));
871 // `const` / `static readonly` → constant (value-ref targets).
872 let field_kind: &'static str = if self.is_const(node) { "constant" } else { "field" };
873
874 // Direct declarators (Java shape) — none for C#; the wrapper path:
875 let mut declarators: Vec<Node> = (0..node.named_child_count())
876 .filter_map(|i| node.named_child(i))
877 .filter(|c| c.kind() == "variable_declarator")
878 .collect();
879 let var_decl = (0..node.named_child_count())
880 .filter_map(|i| node.named_child(i))
881 .find(|c| c.kind() == "variable_declaration");
882 if declarators.is_empty() {
883 if let Some(vd) = var_decl {
884 declarators = (0..vd.named_child_count())
885 .filter_map(|i| vd.named_child(i))
886 .filter(|c| c.kind() == "variable_declarator")
887 .collect();
888 }
889 }
890 // (PHP property_element branch: unreachable for C#.)
891
892 if !declarators.is_empty() {
893 let type_search = var_decl.unwrap_or(node);
894 let type_node = (0..type_search.named_child_count())
895 .filter_map(|i| type_search.named_child(i))
896 .find(|c| {
897 !matches!(
898 c.kind(),
899 "modifiers" | "modifier" | "variable_declarator" | "variable_declaration"
900 | "marker_annotation" | "annotation"
901 )
902 });
903 let type_text = type_node.map(|t| self.text(t).to_string());
904
905 for decl in declarators {
906 let name_node = decl.child_by_field_name("name").or_else(|| {
907 (0..decl.named_child_count())
908 .filter_map(|i| decl.named_child(i))
909 .find(|c| c.kind() == "identifier")
910 });
911 let Some(name_node) = name_node else { continue };
912 let name = self.text(name_node).to_string();
913 let signature = match &type_text {
914 Some(t) => format!("{t} {name}"),
915 None => name.clone(),
916 };
917 let row = self.create_node(
918 field_kind,
919 &name,
920 decl,
921 Extra {
922 docstring: docstring.clone(),
923 signature: Some(signature),

Callers 1

visit_nodeMethod · 0.45

Calls 14

preceding_docstringFunction · 0.85
last_named_childFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
idMethod · 0.80
textMethod · 0.65
visibility_ofMethod · 0.45
is_staticMethod · 0.45
is_constMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected