Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10585

`@AutoFinal` does not use annotation parameters when used with `ASTTransformationCustomizer`

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.1
    • 2.5.17, 3.0.11, 4.0.2
    • None
    • None

    Description

      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:

      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')
        }
      }
      

      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.

      Attachments

        Activity

          People

            emilles Eric Milles
            azurvii V
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: