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

Method extract_decorators_for

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

Source from the content-addressed store, hash-verified

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