[ 
https://issues.apache.org/jira/browse/GROOVY-10585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17523471#comment-17523471
 ] 

V commented on GROOVY-10585:
----------------------------

[~emilles] What you proposed was exactly what I was using. But apparently 
`@AutoFinal` is cascading into nested types, so the `source()` solution would 
throw an exception for cases like:

{code:groovy}
class Foo {
  interface Bar {}
}
{code}

This (trying to apply `@AutoFinal(enabled = false)` is only one attempt I'm 
trying to find a good solution. I feel this is not gonna work (the cascading 
should still generate an error I think), but this (`enabled = false` is 
ignored) is an issue I found. Thus the report.

I'm inclined to propose that `@AutoFinal` should simply ignore interfaces on 
its own, silently, without an error or a message. Groovy's `interface` does not 
allow static or default methods, so I think it makes sense `@AutoFinal` is not 
applicable on an interface anyway. That could simplify the config script to be 
just `ast(AutoFinal)`. Even if in the future methods with implementations are 
allowed in Groovy interfaces, `AutoFinal` should be simply ignoring the 
abstract methods, silently. However, that's a totally different discussion, not 
directly related to this issue.

> `@AutoFinal` does not use annotation parameters when used with 
> `ASTTransformationCustomizer`
> --------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10585
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10585
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.1
>            Reporter: V
>            Assignee: Eric Milles
>            Priority: Major
>
> When used with `ASTTransformationCustomizer` (like below) or in a 
> configscript (`ast(AutoFinal)`, which I think is also using an 
> `ASTTransformationCustomizer`), `@AutoFinal` does not seem to take the 
> annotation parameters. Applying it individually seems to be fine. A test case 
> to demonstrate this:
> {code:groovy}
> class AnnotationParameterTest {
>   private static GroovyShell getLoggerShell() {
>     final CompilerConfiguration configuration = new CompilerConfiguration()
>     configuration.addCompilationCustomizers(
>         new ASTTransformationCustomizer(Log, value: 'logger'),
>         new ASTTransformationCustomizer(AutoFinal, enabled: false))
>     return new GroovyShell(configuration)
>   }
>   @Test
>   void testAnnotationParameters() {
>     getLoggerShell().run('''
>       @groovy.transform.AutoFinal(enabled = false) // Removing this line 
> would fail the test.
>       class Foo {
>         void testMutation(int i) {
>           i = 1
>           logger.severe("i = $i")
>         }
>       }
>       new Foo().testMutation(2)''', 'Test')
>   }
> }
> {code}
> If the `AutoFinal` annotation *in the script* is removed, the test will fail. 
> In which case, `AutoFinal` is applied, but not with the annotation 
> parameters. I added a `Log` AST transformation just to make sure I used the 
> right way to apply an AST transformation with annotation parameters.
> Not so related:
> Why do I want `AutoFinal(enabled = false)` via `ASTTransformationCustomizer`? 
> I was trying to apply `AutoFinal` on all possible types. However `AutoFinal` 
> would throw an exception when applied on an interface. And I was testing 
> whether I could use `SourceAwareCustomizer` to disable `AutoFinal` for 
> interfaces.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to