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

Method extract_decorators_for

codegraph-kernel/src/scala.rs:1021–1062  ·  view source on GitHub ↗
(&mut self, decl: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

1019 // --- extractDecoratorsFor (:4897-5024) --------------------------------
1020
1021 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
1022 // consider(): scala annotations are `annotation` nodes; the name is
1023 // the first identifier-ish child (type_identifier for scala), with
1024 // call_expression unwrap for invoked decorators.
1025 // Scan 1: direct children (+ modifiers descent — inert for scala,
1026 // annotations aren't inside modifiers in this grammar, but ported).
1027 let mut cursor = decl.walk();
1028 let kids: Vec<Node<'t>> = decl.named_children(&mut cursor).collect();
1029 for child in kids {
1030 self.consider_decorator(child, decorated_row);
1031 if child.kind() == "modifiers" {
1032 let mut mc = child.walk();
1033 let inner: Vec<Node<'t>> = child.named_children(&mut mc).collect();
1034 for m in inner {
1035 self.consider_decorator(m, decorated_row);
1036 }
1037 }
1038 }
1039 // Scan 2: preceding siblings (TS class style — inert for scala where
1040 // annotations are children, ported for fidelity).
1041 if let Some(parent) = decl.parent() {
1042 let decl_start = decl.start_byte();
1043 let mut decl_idx: Option<usize> = None;
1044 for i in 0..parent.named_child_count() {
1045 if let Some(sib) = parent.named_child(i) {
1046 if sib.start_byte() == decl_start {
1047 decl_idx = Some(i);
1048 break;
1049 }
1050 }
1051 }
1052 if let Some(di) = decl_idx {
1053 for j in (0..di).rev() {
1054 let Some(sib) = parent.named_child(j) else { continue };
1055 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1056 break;
1057 }
1058 self.consider_decorator(sib, decorated_row);
1059 }
1060 }
1061 }
1062 }
1063
1064 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1065 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 2

extract_classMethod · 0.45

Calls 3

walkMethod · 0.80
collectMethod · 0.45
consider_decoratorMethod · 0.45

Tested by

no test coverage detected