Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groovy parser does not support annotations on variable declarations #5001

Conversation

jevanlingen
Copy link
Contributor

@jevanlingen jevanlingen commented Feb 7, 2025

What's changed?

Annotations on variables are supported as well.

What's your motivation?

Any additional context

The @groovy.transform.Field annotation is a transformer annotation, it changes the scope of a variable within a script to the class level for the script (see javadoc). This means that the original DeclarationExpression is gone, but the Groovy Compiler replaced it by a semi empty ConstantExpression.

I put in some work to make it work again, by recreating a DeclarationExpression. This is done very roughly, so the code is neither beautiful nor does restore all type information. At least we can parse @Field annotation now, instead of failing. If you have a better idea how to handle this, my ears are open!

@jevanlingen jevanlingen linked an issue Feb 7, 2025 that may be closed by this pull request
@jevanlingen jevanlingen self-assigned this Feb 7, 2025
@jevanlingen jevanlingen added enhancement New feature or request parser-groovy labels Feb 7, 2025
@jevanlingen jevanlingen changed the title 4853-groovy-parser-does-not-support-annotations-on-variable-declarations Groovy parser does not support annotations on variable declarations Feb 7, 2025
@sambsnyd sambsnyd merged commit b33def6 into main Feb 7, 2025
2 checks passed
@sambsnyd sambsnyd deleted the 4853-groovy-parser-does-not-support-annotations-on-variable-declarations branch February 7, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request parser-groovy
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Groovy parser does not support annotations on variable declarations
2 participants