[
https://issues.apache.org/jira/browse/GROOVY-11878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18069137#comment-18069137
]
ASF GitHub Bot commented on GROOVY-11878:
-----------------------------------------
daniellansun merged PR #2400:
URL: https://github.com/apache/groovy/pull/2400
> Allow AST transforms to be applicable in more places, initially loop
> statements
> -------------------------------------------------------------------------------
>
> Key: GROOVY-11878
> URL: https://issues.apache.org/jira/browse/GROOVY-11878
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Priority: Major
>
> The JVM doesn't support adding annotations in the bytecode for statements and
> expressions. That doesn't mean that Groovy couldn't support source-level AST
> transforms in those places. Code injection can happen in the normal way, and
> the transform will be "forgotten" after compilation.
> Examples might be:
> {code}
> @Parallel
> for (int i in 1..4) {
> println i ** 2
> }
> {code}
> which might have this output:
> {noformat}
> 1
> 16
> 9
> 4
> {noformat}
> Or these:
> {code}
> int sum = 0
> @Invariant({ 0 <= i && i <= 4 })
> for (int i in 0..4) {
> sum += i
> }
> assert sum == 10
> {code}
> {code}
> int i = 10
> @Invariant({ i >= 0 })
> @Ensures({ i > old.i }) // i decreases
> while (i > 0) {
> i = i - 1
> }
> assert i == 0
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)