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

Method extract_decorators_for

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

Source from the content-addressed store, hash-verified

1943 // --- extractDecoratorsFor (:4897-5024) — the sibling scan -------------
1944
1945 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
1946 // Scan 1: direct children (+ modifiers descent) — inert for dart
1947 // (annotations are preceding siblings), ported for fidelity.
1948 let mut cursor = decl.walk();
1949 let kids: Vec<Node<'t>> = decl.named_children(&mut cursor).collect();
1950 for child in kids {
1951 self.consider_decorator(child, decorated_row);
1952 if child.kind() == "modifiers" {
1953 let mut mc = child.walk();
1954 let inner: Vec<Node<'t>> = child.named_children(&mut mc).collect();
1955 for m in inner {
1956 self.consider_decorator(m, decorated_row);
1957 }
1958 }
1959 }
1960 // Scan 2: preceding siblings, backward, stop at the first
1961 // non-annotation — stacked annotations emit in REVERSE source order.
1962 // A `declaration`-wrapped member's annotations precede the wrapper,
1963 // and the comments between annotations and declaration are stepped over.
1964 let anchor = self.declaration_wrapper(decl).unwrap_or(decl);
1965 if let Some(parent) = anchor.parent() {
1966 let decl_start = anchor.start_byte();
1967 let mut decl_idx: Option<usize> = None;
1968 for i in 0..parent.named_child_count() {
1969 if let Some(sib) = parent.named_child(i) {
1970 if sib.start_byte() == decl_start {
1971 decl_idx = Some(i);
1972 break;
1973 }
1974 }
1975 }
1976 if let Some(di) = decl_idx {
1977 for j in (0..di).rev() {
1978 let Some(sib) = parent.named_child(j) else { continue };
1979 if DECORATOR_STEP_OVER.contains(&sib.kind()) {
1980 continue;
1981 }
1982 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1983 break;
1984 }
1985 self.consider_decorator(sib, decorated_row);
1986 }
1987 }
1988 }
1989 }
1990
1991 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1992 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 3

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45

Calls 4

walkMethod · 0.80
collectMethod · 0.45
consider_decoratorMethod · 0.45
declaration_wrapperMethod · 0.45

Tested by

no test coverage detected