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

Method extract_field

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

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

Callers 1

visit_nodeMethod · 0.45

Calls 8

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

Tested by

no test coverage detected