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

Method try_visit_hook

codegraph-kernel/src/kotlin.rs:586–646  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

584 // defer-shielded and not ported) ------------------------------------------------
585
586 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
587 if node.kind() != "property_declaration" {
588 return false;
589 }
590 let var_decl = (0..node.named_child_count())
591 .filter_map(|i| node.named_child(i))
592 .find(|c| c.kind() == "variable_declaration");
593 let name_node = var_decl.and_then(|vd| {
594 (0..vd.named_child_count())
595 .filter_map(|i| vd.named_child(i))
596 .find(|c| c.kind() == "simple_identifier")
597 });
598 let Some(name_node) = name_node else { return false }; // destructuring → decline
599 let name = self.text(name_node).to_string();
600 if name.is_empty() {
601 return false;
602 }
603
604 // Scope walk up the parent chain — first match wins.
605 let mut scope: &str = "const";
606 let mut p = node.parent();
607 while let Some(pn) = p {
608 match pn.kind() {
609 "function_body" | "function_declaration" | "lambda_literal"
610 | "anonymous_initializer" | "control_structure_body" | "getter" | "setter" => {
611 scope = "local";
612 break;
613 }
614 "companion_object" | "object_declaration" => {
615 scope = "const";
616 break;
617 }
618 "class_declaration" => {
619 scope = "instance";
620 break;
621 }
622 _ => {}
623 }
624 p = pn.parent();
625 }
626 if scope == "local" {
627 return true; // a local — extract nothing, subtree still scanned
628 }
629
630 let binding = (0..node.named_child_count())
631 .filter_map(|i| node.named_child(i))
632 .find(|c| c.kind() == "binding_pattern_kind");
633 let is_val = binding.map(|b| self.text(b) == "val").unwrap_or(false);
634 let kind: &'static str = if scope == "instance" {
635 "field"
636 } else if is_val {
637 "constant"
638 } else {
639 "variable"
640 };
641 // The `type`-field signature read is dead (zero fields) → signature
642 // undefined; NO docstring/visibility/isStatic — the modifiers merge in
643 // create_node still decorates expect/actual properties.

Callers 1

visit_nodeMethod · 0.45

Calls 2

textMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected