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

Method try_visit_hook

codegraph-kernel/src/kotlin.rs:808–883  ·  view source on GitHub ↗

The Kotlin visitNode hook: `Some` when it consumed the node, holding the initializers it walked as such (`walkInitializer`), which the caller's fn-ref scan of the node skips.

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

Source from the content-addressed store, hash-verified

806 /// initializers it walked as such (`walkInitializer`), which the caller's
807 /// fn-ref scan of the node skips.
808 fn try_visit_hook(&mut self, node: Node<'t>) -> Option<Vec<usize>> {
809 // An own-line accessor already walked by its owning property below. The
810 // ownership test re-derives the property's kind rather than remembering
811 // it: a destructured or local declaration mints no node, so its
812 // accessors were NOT consumed and must keep falling through.
813 if matches!(node.kind(), "getter" | "setter") {
814 return accessor_owner(node)
815 .and_then(|owner| self.property_kind(owner))
816 .map(|_| Vec::new());
817 }
818 if node.kind() != "property_declaration" {
819 return None;
820 }
821 let var_decl = (0..node.named_child_count())
822 .filter_map(|i| node.named_child(i))
823 .find(|c| c.kind() == "variable_declaration");
824 let name_node = var_decl.and_then(|vd| {
825 (0..vd.named_child_count())
826 .filter_map(|i| vd.named_child(i))
827 .find(|c| c.kind() == "simple_identifier")
828 });
829 // Destructuring (`val (a, b) = makePair()`): NEITHER arm mints a symbol
830 // for the destructured names — declining just routes the node to
831 // extractField/extractVariable, which both find nothing for kotlin and
832 // end in the same fn-ref scan. But the RHS is CODE, and it was vanishing
833 // whole. Consume the node here and walk it at the ENCLOSING scope (no
834 // symbol of its own to attribute to).
835 let Some(name_node) = name_node else {
836 for init in property_initializers(node) {
837 self.visit_function_body(init);
838 }
839 return Some(Vec::new());
840 };
841 let name = self.text(name_node).to_string();
842 if name.is_empty() {
843 return None;
844 }
845 let Some(kind) = self.property_kind(node) else {
846 // A local — no node is minted, but the initializer is still code.
847 // Walk it at the ENCLOSING scope: an `init { }` block's
848 // `val q = load()` is the CLASS calling load, and it used to
849 // disappear entirely (only the block's bare statements survived).
850 for init in property_initializers(node) {
851 self.visit_function_body(init);
852 }
853 return Some(Vec::new());
854 };
855 // The `type`-field signature read is dead (zero fields) → signature
856 // undefined; NO docstring/isStatic — the modifiers merge in
857 // create_node still decorates expect/actual properties. Visibility IS
858 // read: a `private val` is file-local to the resolver (#1731).
859 let extra = Extra { visibility: Some(self.visibility_of(node)), ..Extra::default() };
860 let row = self.create_node(kind, &name, node, extra);
861 // Walk the initializer ATTRIBUTED to the declared symbol (#693, the Go
862 // fix, ported): without this the subtree is only fn-ref-scanned, so a
863 // lambda / SAM / object initializer (`val cb = Runnable { target() }` —
864 // the idiomatic Android callback field) contributed NO call edge at all.
865 // The property also OWNS any accessor written on its own line, which the

Callers 1

visit_nodeMethod · 0.45

Calls 11

accessor_ownerFunction · 0.85
property_initializersFunction · 0.85
following_accessorsFunction · 0.85
mapMethod · 0.80
property_kindMethod · 0.80
pushMethod · 0.80
idMethod · 0.80
textMethod · 0.65
visit_function_bodyMethod · 0.45
visibility_ofMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected