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

Method extract_decorators_for

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

Source from the content-addressed store, hash-verified

994 // --- extractDecoratorsFor (:4897-5024) --------------------------------
995
996 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
997 // consider(): scala annotations are `annotation` nodes; the name is
998 // the first identifier-ish child (type_identifier for scala), with
999 // call_expression unwrap for invoked decorators.
1000 // Scan 1: direct children (+ modifiers descent — inert for scala,
1001 // annotations aren't inside modifiers in this grammar, but ported).
1002 let mut cursor = decl.walk();
1003 let kids: Vec<Node<'t>> = decl.named_children(&mut cursor).collect();
1004 for child in kids {
1005 self.consider_decorator(child, decorated_row);
1006 if child.kind() == "modifiers" {
1007 let mut mc = child.walk();
1008 let inner: Vec<Node<'t>> = child.named_children(&mut mc).collect();
1009 for m in inner {
1010 self.consider_decorator(m, decorated_row);
1011 }
1012 }
1013 }
1014 // Scan 2: preceding siblings (TS class style — inert for scala where
1015 // annotations are children, ported for fidelity).
1016 if let Some(parent) = decl.parent() {
1017 let decl_start = decl.start_byte();
1018 let mut decl_idx: Option<usize> = None;
1019 for i in 0..parent.named_child_count() {
1020 if let Some(sib) = parent.named_child(i) {
1021 if sib.start_byte() == decl_start {
1022 decl_idx = Some(i);
1023 break;
1024 }
1025 }
1026 }
1027 if let Some(di) = decl_idx {
1028 for j in (0..di).rev() {
1029 let Some(sib) = parent.named_child(j) else { continue };
1030 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1031 break;
1032 }
1033 self.consider_decorator(sib, decorated_row);
1034 }
1035 }
1036 }
1037 }
1038
1039 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1040 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 2

extract_classMethod · 0.45

Calls 2

collectMethod · 0.45
consider_decoratorMethod · 0.45

Tested by

no test coverage detected