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

Method extract_field

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

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

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