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

Method extract_field

codegraph-kernel/src/java.rs:704–772  ·  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

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

Callers 1

visit_nodeMethod · 0.45

Calls 9

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