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

Method extract_decorators_for

codegraph-kernel/src/python.rs:797–812  ·  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

795 /// (python's `call` kind isn't `call_expression`, and `attribute` isn't in
796 /// the target-kind list — mirrored exactly).
797 fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
798 for child in decl.named_children(&mut decl.walk()) {
799 self.consider_decorator(child, decorated_row);
800 }
801 // Walked back from the declaration itself. Finding its place first, by counting the
802 // parent's children from the start, cost each declaration as much as it has
803 // siblings before it: a file of twenty thousand took minutes.
804 let mut sibling = decl.prev_named_sibling();
805 while let Some(sib) = sibling {
806 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
807 break;
808 }
809 self.consider_decorator(sib, decorated_row);
810 sibling = sib.prev_named_sibling();
811 }
812 }
813
814 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
815 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 3

extract_functionMethod · 0.45
extract_methodMethod · 0.45
extract_classMethod · 0.45

Calls 2

walkMethod · 0.45
consider_decoratorMethod · 0.45

Tested by

no test coverage detected