You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/09/02 06:55:13 UTC

[groovy] branch master updated: GROOVY-11165: JEP 445 compatibility additional functionality (document @BaseScript case)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c6644bfe3 GROOVY-11165: JEP 445 compatibility additional functionality (document @BaseScript case)
5c6644bfe3 is described below

commit 5c6644bfe30c130af6d734bf6b371a2259efe10d
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Sep 2 16:55:02 2023 +1000

    GROOVY-11165: JEP 445 compatibility additional functionality (document @BaseScript case)
---
 src/spec/doc/core-domain-specific-languages.adoc |  8 ++++++++
 src/spec/test/BaseScriptSpecTest.groovy          | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/spec/doc/core-domain-specific-languages.adoc b/src/spec/doc/core-domain-specific-languages.adoc
index 3838f7c815..988f46932b 100644
--- a/src/spec/doc/core-domain-specific-languages.adoc
+++ b/src/spec/doc/core-domain-specific-languages.adoc
@@ -226,6 +226,14 @@ the base script class as a member of the `@BaseScript` annotation itself:
 include::../test/BaseScriptSpecTest.groovy[tags=use_basescript_alt,indent=0]
 ----
 
+When using the special no-args `run` method, you can even annotate
+that method as shown here:
+
+[source,groovy]
+----
+include::../test/BaseScriptSpecTest.groovy[tags=jep445_example,indent=0]
+----
+
 === Alternate abstract method
 
 We have seen that the base script class is a single abstract method type that needs to implement the `run` method. The
diff --git a/src/spec/test/BaseScriptSpecTest.groovy b/src/spec/test/BaseScriptSpecTest.groovy
index c6db6a0ded..f24143c099 100644
--- a/src/spec/test/BaseScriptSpecTest.groovy
+++ b/src/spec/test/BaseScriptSpecTest.groovy
@@ -103,7 +103,6 @@ assert (this instanceof Script)
         '''
     }
 
-
     void testBaseClassCustomRunMethod() {
         assertScript '''import org.codehaus.groovy.control.CompilerConfiguration
 
@@ -139,4 +138,19 @@ assert (this instanceof Script)
         '''
     }
 
+    void testBaseClassJep445Example() {
+        assertScript '''import groovy.transform.BaseScript
+            // tag::jep445_example[]
+            abstract class CustomScript extends Script {
+                int getTheMeaningOfLife() { 42 }
+            }
+
+            @BaseScript(CustomScript)
+            def run() {
+              assert theMeaningOfLife == 42
+            }
+            // end::jep445_example[]
+        '''
+    }
+
 }