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

Method extract_field

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

extractField — each declarator becomes a field/constant node. Returns the initializers walked under their fields, for the declaration scan to skip.

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

Source from the content-addressed store, hash-verified

727 /// the initializers walked under their fields, for the declaration scan to
728 /// skip.
729 fn extract_field(&mut self, node: Node<'t>) -> Vec<usize> {
730 let mut walked = Vec::new();
731 let docstring = preceding_docstring(node, self.src);
732 let visibility = self.visibility_of(node);
733 let is_static = Some(self.is_static(node));
734 let field_kind: &'static str = if self.is_const(node) { "constant" } else { "field" };
735
736 let declarators: Vec<Node> = (0..node.named_child_count())
737 .filter_map(|i| node.named_child(i))
738 .filter(|c| c.kind() == "variable_declarator")
739 .collect();
740
741 if !declarators.is_empty() {
742 let type_node = (0..node.named_child_count())
743 .filter_map(|i| node.named_child(i))
744 .find(|c| {
745 !matches!(
746 c.kind(),
747 "modifiers" | "modifier" | "variable_declarator" | "variable_declaration"
748 | "marker_annotation" | "annotation"
749 )
750 });
751 let type_text = type_node.map(|t| self.text(t).to_string());
752
753 for decl in declarators {
754 let name_node = decl.child_by_field_name("name").or_else(|| {
755 (0..decl.named_child_count())
756 .filter_map(|i| decl.named_child(i))
757 .find(|c| c.kind() == "identifier")
758 });
759 let Some(name_node) = name_node else { continue };
760 let name = self.text(name_node).to_string();
761 let signature = match &type_text {
762 Some(t) => format!("{t} {name}"),
763 None => name.clone(),
764 };
765 let row = self.create_node(
766 field_kind,
767 &name,
768 decl,
769 Extra {
770 docstring: docstring.clone(),
771 signature: Some(signature),
772 visibility,
773 is_static,
774 ..Extra::default()
775 },
776 );
777 if let Some(row) = row {
778 self.extract_decorators_for(node, row);
779 self.extract_type_annotations(node, row);
780 // Walk the initializer ATTRIBUTED to the declared field
781 // (#693, the Go fix): the dispatcher only fn-ref-scans this
782 // subtree, so a lambda / method reference / anonymous class
783 // in `private final Runnable r = () -> target();` emitted no
784 // call edge at all.
785 if let Some(value) = decl.child_by_field_name("value") {
786 self.stack.push(Scope { row, kind: field_kind, name: name.clone() });

Callers 1

visit_nodeMethod · 0.45

Calls 13

preceding_docstringFunction · 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
create_nodeMethod · 0.45

Tested by

no test coverage detected