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

Method extract_field

codegraph-kernel/src/java.rs:712–780  ·  view source on GitHub ↗

extractField — each declarator becomes a field/constant node.

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

Source from the content-addressed store, hash-verified

710
711 /// extractField — each declarator becomes a field/constant node.
712 fn extract_field(&mut self, node: Node<'t>) {
713 let docstring = preceding_docstring(node, self.src);
714 let visibility = self.visibility_of(node);
715 let is_static = Some(self.is_static(node));
716 let field_kind: &'static str = if self.is_const(node) { "constant" } else { "field" };
717
718 let declarators: Vec<Node> = (0..node.named_child_count())
719 .filter_map(|i| node.named_child(i))
720 .filter(|c| c.kind() == "variable_declarator")
721 .collect();
722
723 if !declarators.is_empty() {
724 let type_node = (0..node.named_child_count())
725 .filter_map(|i| node.named_child(i))
726 .find(|c| {
727 !matches!(
728 c.kind(),
729 "modifiers" | "modifier" | "variable_declarator" | "variable_declaration"
730 | "marker_annotation" | "annotation"
731 )
732 });
733 let type_text = type_node.map(|t| self.text(t).to_string());
734
735 for decl in declarators {
736 let name_node = decl.child_by_field_name("name").or_else(|| {
737 (0..decl.named_child_count())
738 .filter_map(|i| decl.named_child(i))
739 .find(|c| c.kind() == "identifier")
740 });
741 let Some(name_node) = name_node else { continue };
742 let name = self.text(name_node).to_string();
743 let signature = match &type_text {
744 Some(t) => format!("{t} {name}"),
745 None => name.clone(),
746 };
747 let row = self.create_node(
748 field_kind,
749 &name,
750 decl,
751 Extra {
752 docstring: docstring.clone(),
753 signature: Some(signature),
754 visibility,
755 is_static,
756 ..Extra::default()
757 },
758 );
759 if let Some(row) = row {
760 self.extract_decorators_for(node, row);
761 self.extract_type_annotations(node, row);
762 }
763 }
764 } else {
765 let name_node = node.child_by_field_name("name").or_else(|| {
766 (0..node.named_child_count())
767 .filter_map(|i| node.named_child(i))
768 .find(|c| c.kind() == "identifier")
769 });

Callers 1

visit_nodeMethod · 0.45

Calls 9

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