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

Method extract_field

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

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

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