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

Method extract_field

codegraph-kernel/src/php.rs:803–857  ·  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

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

Callers 1

visit_nodeMethod · 0.45

Calls 7

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

Tested by

no test coverage detected