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

Method extract_decorators_for

codegraph-kernel/src/scala.rs:1021–1052  ·  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 // Walked back from the declaration itself. Finding its place first, by counting the
1042 // parent's children from the start, cost each declaration as much as it has
1043 // siblings before it: a file of twenty thousand took minutes.
1044 let mut sibling = decl.prev_named_sibling();
1045 while let Some(sib) = sibling {
1046 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1047 break;
1048 }
1049 self.consider_decorator(sib, decorated_row);
1050 sibling = sib.prev_named_sibling();
1051 }
1052 }
1053
1054 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1055 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 2

extract_classMethod · 0.45

Calls 3

walkMethod · 0.45
collectMethod · 0.45
consider_decoratorMethod · 0.45

Tested by

no test coverage detected