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

Paul King closed GROOVY-11884.
------------------------------

> Close gaps in Groovy annotation validation
> ------------------------------------------
>
>                 Key: GROOVY-11884
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11884
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>              Labels: breaking
>             Fix For: 6.0.0-alpha-1
>
>
> Groovy lets you have annotations like @Grab on various nodes and various 
> statements including imports. Targeting imports is not possible in Java, but 
> this is part of Groovy's stance of providing more flexibility.
> Groovy also does validation that annotations don't appear in incorrect 
> places. Currently there is a gap in our validation - we ignore things like 
> checking what things can be on imports, e.g. the following is currently valid 
> but totally ignored:
> {code}
> @Deprecated
> import java.lang.String
> {code}
> As well as @Grab, @Newify and @BaseScript can also appear on imports.
> With the new incubating AST transforms on loops, @Invariant can now appear on 
> loops.
> I propose we create some additional classes to capture these extended 
> annotation targets and close the gaps in validation. Something like:
> {code}
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.ANNOTATION_TYPE)
> public @interface ExtendedTarget {
>     ExtendedElementType[] value();
> }
> {code}
> And:
> {code}
> public enum ExtendedElementType {
>     /** Import statement. */
>     IMPORT,
>     /** Loop statement ({@code for}, {@code while}, {@code do-while}). */
>     LOOP
> }
> {code}
> And then things like @BaseScript would change from this:
> {code}
> @Retention(RetentionPolicy.SOURCE)
> @Target({ElementType.LOCAL_VARIABLE, ElementType.PACKAGE, ElementType.TYPE 
> /*, ElementType.IMPORT*/})
> @GroovyASTTransformationClass("org.codehaus.groovy.transform.BaseScriptASTTransformation")
> public @interface BaseScript {
>     Class value() default Script.class;
> }
> {code}
> to this:
> {code}
> @Retention(RetentionPolicy.SOURCE)
> @Target({ElementType.LOCAL_VARIABLE, ElementType.PACKAGE, ElementType.TYPE})
> @ExtendedTarget(ExtendedElementType.IMPORT)
> @GroovyASTTransformationClass("org.codehaus.groovy.transform.BaseScriptASTTransformation")
> public @interface BaseScript {
>     Class value() default Script.class;
> }
> {code}
> This would be a breaking change if any codebases are relying on Groovy's 
> leniency, e.g. maybe they had a convention of putting @Deprecated on an 
> import if they were hoping to eventually get rid of the related dependency. 
> We don't know anyone doing this, but in such cases, folks would need to now 
> make and use an annotation with @ExtendedTarget.



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

Reply via email to