probe_code/language/
java.rs1use super::language_trait::LanguageImpl;
2use tree_sitter::{Language as TSLanguage, Node};
3
4pub struct JavaLanguage;
6
7impl Default for JavaLanguage {
8 fn default() -> Self {
9 Self::new()
10 }
11}
12
13impl JavaLanguage {
14 pub fn new() -> Self {
15 JavaLanguage
16 }
17}
18
19impl LanguageImpl for JavaLanguage {
20 fn get_tree_sitter_language(&self) -> TSLanguage {
21 tree_sitter_java::LANGUAGE.into()
22 }
23
24 fn get_extension(&self) -> &'static str {
25 "java"
26 }
27
28 fn is_acceptable_parent(&self, node: &Node) -> bool {
29 matches!(
30 node.kind(),
31 "method_declaration"
32 | "class_declaration"
33 | "interface_declaration"
34 | "enum_declaration"
35 | "constructor_declaration"
36 )
37 }
38
39 fn is_test_node(&self, node: &Node, source: &[u8]) -> bool {
40 let debug_mode = std::env::var("DEBUG").unwrap_or_default() == "1";
41 let node_type = node.kind();
42
43 if node_type == "method_declaration" {
45 let mut cursor = node.walk();
46 for child in node.children(&mut cursor) {
47 if child.kind() == "modifiers" {
48 let mut subcursor = child.walk();
49 for annotation in child.children(&mut subcursor) {
50 if annotation.kind() == "annotation" {
51 let annotation_text = annotation.utf8_text(source).unwrap_or("");
52 if annotation_text.contains("@Test") {
53 if debug_mode {
54 println!("DEBUG: Test node detected (Java): @Test method");
55 }
56 return true;
57 }
58 }
59 }
60 }
61 }
62 }
63
64 false
65 }
66}