A property's node kind, or None when the declaration mints no node at all: destructuring, an unreadable name, or a local (inside a function body / `init` block / lambda / accessor). Kind by enclosing scope — a singleton `object` / `companion object` (and a top-level property) holds SHARED values (`val`→constant, `var`→variable, the Scala-object rule; a `const val` is just a val); a class/interface
(&self, node: Node<'t>)
| 709 | /// `const val` is just a val); a class/interface/enum instance `val`/`var` |
| 710 | /// is per-instance state → `field`. |
| 711 | fn property_kind(&self, node: Node<'t>) -> Option<&'static str> { |
| 712 | let var_decl = (0..node.named_child_count()) |
| 713 | .filter_map(|i| node.named_child(i)) |
| 714 | .find(|c| c.kind() == "variable_declaration")?; |
| 715 | let name_node = (0..var_decl.named_child_count()) |
| 716 | .filter_map(|i| var_decl.named_child(i)) |
| 717 | .find(|c| c.kind() == "simple_identifier")?; |
| 718 | if self.text(name_node).is_empty() { |
| 719 | return None; |
| 720 | } |
| 721 | let mut scope: &str = "const"; |
| 722 | let mut p = node.parent(); |
| 723 | while let Some(pn) = p { |
| 724 | match pn.kind() { |
| 725 | "function_body" | "function_declaration" | "lambda_literal" |
| 726 | | "anonymous_initializer" | "control_structure_body" | "getter" | "setter" => { |
| 727 | scope = "local"; |
| 728 | break; |
| 729 | } |
| 730 | "companion_object" | "object_declaration" => { |
| 731 | scope = "const"; |
| 732 | break; |
| 733 | } |
| 734 | "class_declaration" => { |
| 735 | scope = "instance"; |
| 736 | break; |
| 737 | } |
| 738 | _ => {} |
| 739 | } |
| 740 | p = pn.parent(); |
| 741 | } |
| 742 | if scope == "local" { |
| 743 | return None; |
| 744 | } |
| 745 | let binding = (0..node.named_child_count()) |
| 746 | .filter_map(|i| node.named_child(i)) |
| 747 | .find(|c| c.kind() == "binding_pattern_kind"); |
| 748 | let is_val = binding.map(|b| self.text(b) == "val").unwrap_or(false); |
| 749 | Some(if scope == "instance" { |
| 750 | "field" |
| 751 | } else if is_val { |
| 752 | "constant" |
| 753 | } else { |
| 754 | "variable" |
| 755 | }) |
| 756 | } |
| 757 | |
| 758 | /// The Kotlin visitNode hook: `Some` when it consumed the node, holding the |
| 759 | /// initializers it walked as such (`walkInitializer`), which the caller's |
no test coverage detected