[ 
https://issues.apache.org/jira/browse/GROOVY-11118?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-11118:
-------------------------------
    Description: 
[JEP 445: Unnamed Classes and Instance Main 
Methods|https://openjdk.org/jeps/445] provides features that improve using Java 
for scripting purposes. While these features offer a subset of the features 
offered by Groovy for scripting, it would be nice to offer some interworking 
for cut-n-paste compatibility and leveraging the updated launch protocol.

(i) This description will contain the most update-to-date proposal for the 
design but may undergo change during discussions. If needed, a separate GEP 
section in the wiki will capture the final design.

h2. Scripting semantics

||Source file characteristics||Semantics determined||
| Contains class declaration | Compiled as a class |
| Contains uncontained non-declaration statements
or a static main method | Compiled as a Groovy script |
| Contains an instance main method | Compiled as a JEP 445 compatible class |

Groovy scripts are wrapped into an encompassing class that extends 
{{groovy.lang.Script}}.
Such classes have a {{public static void main}} added which (summarising) 
creates a class instance and calls its {{run}} method.
Uncontained statements within the script can be though of as belonging within 
the {{run}} method.
Declaration statements within the script are treated as local variable 
definitions (also within the {{run}} method).
Field definitions can be obtained by annotating declaration statements with the 
{{@Field}} annotation.

JEP 445 scripts do not extend {{Script}} and do not have any methods added.
Declaration statements within the script are treated as field definitions.

h2. Script runner

Groovy's runner mechanism will be extended to follow a similar protocol to 
Java's revised launch protocol. This should be available for JDK11+ and a 
JEP-445 compatible class could be invoked using JDK21+ with preview enabled 
(with Groovy on the classpath unless a POJO class is created).
 

  was:
[JEP 445: Unnamed Classes and Instance Main 
Methods|https://openjdk.org/jeps/445] provides features that improve using Java 
for scripting purposes. While these features offer a subset of the features 
offered by Groovy for scripting, it would be nice to offer some interworking 
for cut-n-paste compatibility and leveraging the updated launch protocol.

(i) This description will contain the most update-to-date proposal for the 
design but may undergo change during discussions. If needed, a separate GEP 
section in the wiki will capture the final design.

h2. Scripting semantics

||Source file characteristics||Semantics determined||
| Contains class declaration | Compiled as a class |
| Contains uncontained non-declaration statements | Compiled as a Groovy script 
|
| Contains a static main method | Compiled as a Groovy script |
| Contains an instance main method | Compiled as a JEP 445 compatible class |

Groovy scripts are wrapped into an encompassing class that extends 
{{groovy.lang.Script}}.
Such classes have a {{public static void main}} added which (summarising) 
creates a class instance and calls its {{run}} method.
Uncontained statements within the script can be though of as belonging within 
the {{run}} method.
Declaration statements within the script are treated as local variable 
definitions (also within the {{run}} method).
Field definitions can be obtained by annotating declaration statements with the 
{{@Field}} annotation.

JEP 445 scripts do not extend {{Script}} and do not have any methods added.
Declaration statements within the script are treated as field definitions.

h2. Script runner

Groovy's runner mechanism will be extended to follow a similar protocol to 
Java's revised launch protocol. This should be available for JDK11+ and a 
JEP-445 compatible class could be invoked using JDK21+ with preview enabled 
(with Groovy on the classpath unless a POJO class is created).
 


> Partial JEP 445 compatibility
> -----------------------------
>
>                 Key: GROOVY-11118
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11118
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>              Labels: GEP
>             Fix For: 5.x
>
>
> [JEP 445: Unnamed Classes and Instance Main 
> Methods|https://openjdk.org/jeps/445] provides features that improve using 
> Java for scripting purposes. While these features offer a subset of the 
> features offered by Groovy for scripting, it would be nice to offer some 
> interworking for cut-n-paste compatibility and leveraging the updated launch 
> protocol.
> (i) This description will contain the most update-to-date proposal for the 
> design but may undergo change during discussions. If needed, a separate GEP 
> section in the wiki will capture the final design.
> h2. Scripting semantics
> ||Source file characteristics||Semantics determined||
> | Contains class declaration | Compiled as a class |
> | Contains uncontained non-declaration statements
> or a static main method | Compiled as a Groovy script |
> | Contains an instance main method | Compiled as a JEP 445 compatible class |
> Groovy scripts are wrapped into an encompassing class that extends 
> {{groovy.lang.Script}}.
> Such classes have a {{public static void main}} added which (summarising) 
> creates a class instance and calls its {{run}} method.
> Uncontained statements within the script can be though of as belonging within 
> the {{run}} method.
> Declaration statements within the script are treated as local variable 
> definitions (also within the {{run}} method).
> Field definitions can be obtained by annotating declaration statements with 
> the {{@Field}} annotation.
> JEP 445 scripts do not extend {{Script}} and do not have any methods added.
> Declaration statements within the script are treated as field definitions.
> h2. Script runner
> Groovy's runner mechanism will be extended to follow a similar protocol to 
> Java's revised launch protocol. This should be available for JDK11+ and a 
> JEP-445 compatible class could be invoked using JDK21+ with preview enabled 
> (with Groovy on the classpath unless a POJO class is created).
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to