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

Method extract_field

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

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