Check if a node has a specific modifier (public, private, static, final, abstract, etc.).
(&self, node: &Node, source: &str, modifier: &str)
| 552 | |
| 553 | /// Check if a node has a specific modifier (public, private, static, final, abstract, etc.). |
| 554 | fn has_modifier(&self, node: &Node, source: &str, modifier: &str) -> bool { |
| 555 | let mut cursor = node.walk(); |
| 556 | for child in node.children(&mut cursor) { |
| 557 | if child.kind() == "modifiers" { |
| 558 | let text = self.node_text(&child, source); |
| 559 | return text.contains(modifier); |
| 560 | } |
| 561 | // Also check direct modifier children (some tree-sitter versions) |
| 562 | if self.node_text(&child, source) == modifier { |
| 563 | return true; |
| 564 | } |
| 565 | // Stop once we hit the name/type — modifiers come before |
| 566 | if child.kind() == "identifier" |
| 567 | || child.kind() == "type_identifier" |
| 568 | || child.kind() == "void_type" |
| 569 | || child.kind() == "class" |
| 570 | || child.kind() == "interface" |
| 571 | || child.kind() == "enum" |
| 572 | { |
| 573 | break; |
| 574 | } |
| 575 | } |
| 576 | false |
| 577 | } |
| 578 | |
| 579 | /// Get the visibility modifier as a string ("public ", "private ", "protected ", or ""). |
| 580 | fn get_visibility(&self, node: &Node, source: &str) -> String { |
no test coverage detected