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

Method extract_field

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

extractField (2046) — field_declaration; each declarator becomes a field/constant node anchored at the DECLARATOR.

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

Source from the content-addressed store, hash-verified

800 /// extractField (2046) — field_declaration; each declarator becomes a
801 /// field/constant node anchored at the DECLARATOR.
802 fn extract_field(&mut self, node: Node<'t>) {
803 let docstring = preceding_docstring(node, self.src);
804 let visibility = Some(self.visibility_of(node));
805 let is_static = Some(self.is_static(node));
806 // `const` / `static readonly` → constant (value-ref targets).
807 let field_kind: &'static str = if self.is_const(node) { "constant" } else { "field" };
808
809 // Direct declarators (Java shape) — none for C#; the wrapper path:
810 let mut declarators: Vec<Node> = (0..node.named_child_count())
811 .filter_map(|i| node.named_child(i))
812 .filter(|c| c.kind() == "variable_declarator")
813 .collect();
814 let var_decl = (0..node.named_child_count())
815 .filter_map(|i| node.named_child(i))
816 .find(|c| c.kind() == "variable_declaration");
817 if declarators.is_empty() {
818 if let Some(vd) = var_decl {
819 declarators = (0..vd.named_child_count())
820 .filter_map(|i| vd.named_child(i))
821 .filter(|c| c.kind() == "variable_declarator")
822 .collect();
823 }
824 }
825 // (PHP property_element branch: unreachable for C#.)
826
827 if !declarators.is_empty() {
828 let type_search = var_decl.unwrap_or(node);
829 let type_node = (0..type_search.named_child_count())
830 .filter_map(|i| type_search.named_child(i))
831 .find(|c| {
832 !matches!(
833 c.kind(),
834 "modifiers" | "modifier" | "variable_declarator" | "variable_declaration"
835 | "marker_annotation" | "annotation"
836 )
837 });
838 let type_text = type_node.map(|t| self.text(t).to_string());
839
840 for decl in declarators {
841 let name_node = decl.child_by_field_name("name").or_else(|| {
842 (0..decl.named_child_count())
843 .filter_map(|i| decl.named_child(i))
844 .find(|c| c.kind() == "identifier")
845 });
846 let Some(name_node) = name_node else { continue };
847 let name = self.text(name_node).to_string();
848 let signature = match &type_text {
849 Some(t) => format!("{t} {name}"),
850 None => name.clone(),
851 };
852 let row = self.create_node(
853 field_kind,
854 &name,
855 decl,
856 Extra {
857 docstring: docstring.clone(),
858 signature: Some(signature),
859 visibility,

Callers 1

visit_nodeMethod · 0.45

Calls 8

preceding_docstringFunction · 0.85
visibility_ofMethod · 0.45
is_staticMethod · 0.45
is_constMethod · 0.45
collectMethod · 0.45
textMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected