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

Method extract_field

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

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