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

Method try_visit_hook

codegraph-kernel/src/kotlin.rs:760–835  ·  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

758 /// initializers it walked as such (`walkInitializer`), which the caller's
759 /// fn-ref scan of the node skips.
760 fn try_visit_hook(&mut self, node: Node<'t>) -> Option<Vec<usize>> {
761 // An own-line accessor already walked by its owning property below. The
762 // ownership test re-derives the property's kind rather than remembering
763 // it: a destructured or local declaration mints no node, so its
764 // accessors were NOT consumed and must keep falling through.
765 if matches!(node.kind(), "getter" | "setter") {
766 return accessor_owner(node)
767 .and_then(|owner| self.property_kind(owner))
768 .map(|_| Vec::new());
769 }
770 if node.kind() != "property_declaration" {
771 return None;
772 }
773 let var_decl = (0..node.named_child_count())
774 .filter_map(|i| node.named_child(i))
775 .find(|c| c.kind() == "variable_declaration");
776 let name_node = var_decl.and_then(|vd| {
777 (0..vd.named_child_count())
778 .filter_map(|i| vd.named_child(i))
779 .find(|c| c.kind() == "simple_identifier")
780 });
781 // Destructuring (`val (a, b) = makePair()`): NEITHER arm mints a symbol
782 // for the destructured names — declining just routes the node to
783 // extractField/extractVariable, which both find nothing for kotlin and
784 // end in the same fn-ref scan. But the RHS is CODE, and it was vanishing
785 // whole. Consume the node here and walk it at the ENCLOSING scope (no
786 // symbol of its own to attribute to).
787 let Some(name_node) = name_node else {
788 for init in property_initializers(node) {
789 self.visit_function_body(init);
790 }
791 return Some(Vec::new());
792 };
793 let name = self.text(name_node).to_string();
794 if name.is_empty() {
795 return None;
796 }
797 let Some(kind) = self.property_kind(node) else {
798 // A local — no node is minted, but the initializer is still code.
799 // Walk it at the ENCLOSING scope: an `init { }` block's
800 // `val q = load()` is the CLASS calling load, and it used to
801 // disappear entirely (only the block's bare statements survived).
802 for init in property_initializers(node) {
803 self.visit_function_body(init);
804 }
805 return Some(Vec::new());
806 };
807 // The `type`-field signature read is dead (zero fields) → signature
808 // undefined; NO docstring/isStatic — the modifiers merge in
809 // create_node still decorates expect/actual properties. Visibility IS
810 // read: a `private val` is file-local to the resolver (#1731).
811 let extra = Extra { visibility: Some(self.visibility_of(node)), ..Extra::default() };
812 let row = self.create_node(kind, &name, node, extra);
813 // Walk the initializer ATTRIBUTED to the declared symbol (#693, the Go
814 // fix, ported): without this the subtree is only fn-ref-scanned, so a
815 // lambda / SAM / object initializer (`val cb = Runnable { target() }` —
816 // the idiomatic Android callback field) contributed NO call edge at all.
817 // 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