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

Method property_kind

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

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>)

Source from the content-addressed store, hash-verified

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

Callers 1

try_visit_hookMethod · 0.80

Calls 2

mapMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected