From 42bbf6150b3a570be147b6f0900a959e509ac965 Mon Sep 17 00:00:00 2001 From: Karl-Erik Enkelmann Date: Mon, 5 Jan 2026 11:40:25 +0100 Subject: [PATCH 1/2] Add support for @Nested test classes in runnables --- languages/java/runnables.scm | 53 ++++++++++++++++++++++++++++++++++++ languages/java/tasks.json | 34 +++++++++++------------ 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/languages/java/runnables.scm b/languages/java/runnables.scm index 75f786e..531d7b0 100644 --- a/languages/java/runnables.scm +++ b/languages/java/runnables.scm @@ -64,6 +64,33 @@ (#set! tag java-test-method) ) +; Run nested test function +( + (package_declaration + (scoped_identifier) @java_package_name + ) + (class_declaration + name: (identifier) @java_outer_class_name + body: (class_body + (class_declaration + name: (identifier) @java_class_name + body: (class_body + (method_declaration + (modifiers + (marker_annotation + name: (identifier) @annotation_name + ) + ) + name: (identifier) @run @java_method_name + (#eq? @annotation_name "Test") + ) + ) + ) @_ + ) + ) + (#set! tag java-test-method-nested) +) + ; Run test class ( (package_declaration @@ -84,3 +111,29 @@ ) @_ (#set! tag java-test-class) ) + +; Run nested test class +( + (package_declaration + (scoped_identifier) @java_package_name + ) + (class_declaration + name: (identifier) @java_outer_class_name + body: (class_body + (class_declaration + name: (identifier) @run @java_class_name + body: (class_body + (method_declaration + (modifiers + (marker_annotation + name: (identifier) @annotation_name + ) + ) + (#eq? @annotation_name "Test") + ) + ) + ) @_ + ) + ) + (#set! tag java-test-class-nested) +) diff --git a/languages/java/tasks.json b/languages/java/tasks.json index 280bfc7..4816928 100644 --- a/languages/java/tasks.json +++ b/languages/java/tasks.json @@ -1,23 +1,23 @@ [ - { - "label": "Run $ZED_CUSTOM_java_class_name", - "command": "pkg=\"${ZED_CUSTOM_java_package_name:}\"; cls=\"$ZED_CUSTOM_java_class_name\"; if [ -n \"$pkg\" ]; then c=\"$pkg.$cls\"; else c=\"$cls\"; fi; if [ -f pom.xml ]; then ./mvnw clean compile exec:java -Dexec.mainClass=\"$c\"; elif [ -f gradlew ]; then ./gradlew run -PmainClass=\"$c\"; else find . -name '*.java' -not -path './bin/*' -not -path './target/*' -not -path './build/*' -print0 | xargs -0 javac -d bin && java -cp bin \"$c\"; fi;", - "use_new_terminal": false, - "reveal": "always", - "tags": ["java-main"], - "shell": { - "with_arguments": { - "program": "/bin/sh", - "args": ["-c"] - } + { + "label": "Run $ZED_CUSTOM_java_class_name", + "command": "pkg=\"${ZED_CUSTOM_java_package_name:}\"; cls=\"$ZED_CUSTOM_java_class_name\"; if [ -n \"$pkg\" ]; then c=\"$pkg.$cls\"; else c=\"$cls\"; fi; if [ -f pom.xml ]; then ./mvnw clean compile exec:java -Dexec.mainClass=\"$c\"; elif [ -f gradlew ]; then ./gradlew run -PmainClass=\"$c\"; else find . -name '*.java' -not -path './bin/*' -not -path './target/*' -not -path './build/*' -print0 | xargs -0 javac -d bin && java -cp bin \"$c\"; fi;", + "use_new_terminal": false, + "reveal": "always", + "tags": ["java-main"], + "shell": { + "with_arguments": { + "program": "/bin/sh", + "args": ["-c"] } - }, + } + }, { - "label": "Test $ZED_CUSTOM_java_class_name.$ZED_CUSTOM_java_method_name", - "command": "c=\"$ZED_CUSTOM_java_package_name.$ZED_CUSTOM_java_class_name\"; m=\"$ZED_CUSTOM_java_method_name\"; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$c#$m\"; elif [ -f gradlew ]; then ./gradlew test --tests $c.$m; else >&2 echo 'No build system found'; exit 1; fi;", + "label": "$ZED_CUSTOM_java_class_name.${ZED_CUSTOM_java_outer_class_name:}.$ZED_CUSTOM_java_method_name", + "command": "package=\"$ZED_CUSTOM_java_package_name\"; outer=\"${ZED_CUSTOM_java_outer_class_name:}\"; inner=\"$ZED_CUSTOM_java_class_name\"; method=\"$ZED_CUSTOM_java_method_name\"; sep=\"$\"; if [ -n \"$outer\" ]; then c=\"$outer$sep$inner\"; else c=\"$inner\"; fi; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$package.$c#$method\"; elif [ -f gradlew ]; then ./gradlew test --tests \"$package.$c.$method\"; else >&2 echo 'No build system found'; exit 1; fi;", "use_new_terminal": false, "reveal": "always", - "tags": ["java-test-method"], + "tags": ["java-test-method", "java-test-method-nested"], "shell": { "with_arguments": { "program": "/bin/sh", @@ -27,10 +27,10 @@ }, { "label": "Test class $ZED_CUSTOM_java_class_name", - "command": "c=\"$ZED_CUSTOM_java_package_name.$ZED_CUSTOM_java_class_name\"; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$c\"; elif [ -f gradlew ]; then ./gradlew test --tests $c; else >&2 echo 'No build system found'; exit 1; fi;", + "command": "package=\"$ZED_CUSTOM_java_package_name\"; outer=\"${ZED_CUSTOM_java_outer_class_name:}\"; inner=\"$ZED_CUSTOM_java_class_name\"; sep=\"$\"; if [ -n \"$outer\" ]; then c=\"$outer$sep$inner\"; else c=\"$inner\"; fi; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$package.$c\"; elif [ -f gradlew ]; then ./gradlew test --tests \"$package.$c\"; else >&2 echo 'No build system found'; exit 1; fi;", "use_new_terminal": false, "reveal": "always", - "tags": ["java-test-class"], + "tags": ["java-test-class", "java-test-class-nested"], "shell": { "with_arguments": { "program": "/bin/sh", From 550357e9f9b0988812b6ec4bda33e329c7c6d8fb Mon Sep 17 00:00:00 2001 From: Karl-Erik Enkelmann Date: Mon, 5 Jan 2026 11:58:02 +0100 Subject: [PATCH 2/2] Require `@Nested` annotation for inner classes --- languages/java/runnables.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/languages/java/runnables.scm b/languages/java/runnables.scm index 531d7b0..a8a2b2e 100644 --- a/languages/java/runnables.scm +++ b/languages/java/runnables.scm @@ -73,6 +73,11 @@ name: (identifier) @java_outer_class_name body: (class_body (class_declaration + (modifiers + (marker_annotation + name: (identifier) @nested_annotation + ) + ) name: (identifier) @java_class_name body: (class_body (method_declaration @@ -85,6 +90,7 @@ (#eq? @annotation_name "Test") ) ) + (#eq? @nested_annotation "Nested") ) @_ ) ) @@ -121,6 +127,11 @@ name: (identifier) @java_outer_class_name body: (class_body (class_declaration + (modifiers + (marker_annotation + name: (identifier) @nested_annotation + ) + ) name: (identifier) @run @java_class_name body: (class_body (method_declaration @@ -132,6 +143,7 @@ (#eq? @annotation_name "Test") ) ) + (#eq? @nested_annotation "Nested") ) @_ ) )