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

Method extract_field

codegraph-kernel/src/php.rs:800–854  ·  view source on GitHub ↗

extractField — the php property_element branch (2077-2104): one `field` node per element, `$` re-added in the signature only, then RETURN — no decorators, no type-annotation refs from fields.

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

Source from the content-addressed store, hash-verified

798 /// node per element, `$` re-added in the signature only, then RETURN — no
799 /// decorators, no type-annotation refs from fields.
800 fn extract_field(&mut self, node: Node<'t>) {
801 let docstring = preceding_docstring(node, self.src);
802 let visibility = Some(self.visibility_of(node));
803 let is_static = Some(self.is_static(node));
804
805 let prop_elements: Vec<Node> = (0..node.named_child_count())
806 .filter_map(|i| node.named_child(i))
807 .filter(|c| c.kind() == "property_element")
808 .collect();
809 if prop_elements.is_empty() {
810 // The declarator/bare fallbacks find nothing on php shapes.
811 return;
812 }
813 // The type node: first namedChild that isn't a modifier or element.
814 // QUIRK: final_modifier/abstract_modifier are NOT excluded — a
815 // `final public Foo $x` takes `final` as the type text. PRESERVE.
816 let type_node = (0..node.named_child_count())
817 .filter_map(|i| node.named_child(i))
818 .find(|c| {
819 !matches!(
820 c.kind(),
821 "visibility_modifier" | "static_modifier" | "readonly_modifier"
822 | "property_element" | "var_modifier"
823 )
824 });
825 let type_text = type_node.map(|t| self.text(t).to_string());
826
827 for elem in prop_elements {
828 let var_name = (0..elem.named_child_count())
829 .filter_map(|i| elem.named_child(i))
830 .find(|c| c.kind() == "variable_name");
831 let Some(var_name) = var_name else { continue };
832 let name_node = (0..var_name.named_child_count())
833 .filter_map(|i| var_name.named_child(i))
834 .find(|c| c.kind() == "name");
835 let Some(name_node) = name_node else { continue };
836 let name = self.text(name_node).to_string();
837 let signature = match &type_text {
838 Some(t) => format!("{t} ${name}"),
839 None => format!("${name}"),
840 };
841 self.create_node(
842 "field",
843 &name,
844 elem,
845 Extra {
846 docstring: docstring.clone(),
847 signature: Some(signature),
848 visibility,
849 is_static,
850 ..Extra::default()
851 },
852 );
853 }
854 }
855
856 // --- imports -------------------------------------------------------------------
857

Callers 1

visit_nodeMethod · 0.45

Calls 6

preceding_docstringFunction · 0.85
textMethod · 0.65
visibility_ofMethod · 0.45
is_staticMethod · 0.45
collectMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected