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

Method extract_decorators_for

codegraph-kernel/src/python.rs:627–658  ·  view source on GitHub ↗

extractDecoratorsFor — python decorators are PRECEDING SIBLINGS inside decorated_definition. Only bare-identifier decorators yield a target (python's `call` kind isn't `call_expression`, and `attribute` isn't in the target-kind list — mirrored exactly).

(&mut self, decl: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

625 /// (python's `call` kind isn't `call_expression`, and `attribute` isn't in
626 /// the target-kind list — mirrored exactly).
627 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
628 for i in 0..decl.named_child_count() {
629 if let Some(child) = decl.named_child(i) {
630 self.consider_decorator(child, decorated_row);
631 }
632 }
633 let Some(parent) = decl.parent() else { return };
634 let decl_start = decl.start_byte();
635 let mut decl_idx: isize = -1;
636 for i in 0..parent.named_child_count() {
637 if let Some(sib) = parent.named_child(i) {
638 if sib.start_byte() == decl_start {
639 decl_idx = i as isize;
640 break;
641 }
642 }
643 }
644 if decl_idx > 0 {
645 let mut j = decl_idx - 1;
646 while j >= 0 {
647 let Some(sib) = parent.named_child(j as usize) else {
648 j -= 1;
649 continue;
650 };
651 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
652 break;
653 }
654 self.consider_decorator(sib, decorated_row);
655 j -= 1;
656 }
657 }
658 }
659
660 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
661 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 3

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45

Calls 1

consider_decoratorMethod · 0.45

Tested by

no test coverage detected