groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8236) Report more meaningful error for versions of Groovy not supporting @Repeatable
Date Sun, 25 Jun 2017 12:00:00 GMT

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

ASF GitHub Bot commented on GROOVY-8236:
----------------------------------------

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/565

    GROOVY-8236: Report more meaningful error for versions of Groovy not …

    …supporting @Repeatable

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy8236

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/565.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #565
    
----
commit b3a0e1634749dbd703f705795a767b71c11a7bec
Author: paulk <paulk@asert.com.au>
Date:   2017-06-25T11:57:36Z

    GROOVY-8236: Report more meaningful error for versions of Groovy not supporting @Repeatable

----


> Report more meaningful error for versions of Groovy not supporting @Repeatable
> ------------------------------------------------------------------------------
>
>                 Key: GROOVY-8236
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8236
>             Project: Groovy
>          Issue Type: New Feature
>         Environment: groovy 2.4.11
>            Reporter: Dmitry Lukyanov
>
> I cloned the issue. As well as providing support for @Repeatable, we should give a more
meaningful error message for any streams of Groovy where we don't support it. I'd guess supported
(2.5.0), unsupported (2.4.x); but in any case, this issue is to handle the unsupported case.
> Instead of:
> {noformat}
> java.lang.annotation.AnnotationFormatError ...
> {noformat}
> We could have something like:
> {noformat}
> Annotation @MyAnnotation has RUNTIME retention and 2 occurrences.
> Automatic repeated annotations are not allowed in this version of Groovy.
> Consider explicitly adding the @MyAnnotationArray collector annotation.
> {noformat}
> ---- original description -----
> raised on stackoverflow: https://stackoverflow.com/questions/44532632/is-the-repeatable-annotation-not-supported-by-groovy/44628119#44628119
> Problem: the following code in groovy 2.4.11 / java8
> {code}
>    @MyAnnotation(value = "val1")
>    @MyAnnotation(value = "val2")
>    void annotatedMethod() { println("annotated method called") }
> {code}
> should be compiled to this:
> {code}
>    @MyAnnotationArray({@MyAnnotation("val1"), @MyAnnotation("val2")})
>    void annotatedMethod() { println("annotated method called") }
> {code}
> but actually compiled to this:
> {code}
>    @MyAnnotation(value = "val1")
>    @MyAnnotation(value = "val2")
>    void annotatedMethod() { println("annotated method called") }
> {code}
> The full groovy script to reproduce problem is below.
> It throws exception: 
> {color:red}java.lang.annotation.AnnotationFormatError: Duplicate annotation for class:
interface MyAnnotation: @MyAnnotation(value=val2){color}
> at line `List annos = m.getAnnotations()`
> {code}
> import java.lang.annotation.*
> class MyClass 
> {
>     @MyAnnotation(value = "val1")
>     @MyAnnotation(value = "val2")
>     //change annotation to next line and the code will work
>     //@MyAnnotationArray( [@MyAnnotation("val1"), @MyAnnotation("val2")] )
>     public void annotatedMethod()
>     {
>       System.out.println("annotated method called");
>     }
>    public static void main(String... args)
>    {
>       MyClass ob = new MyClass()
>       ob.annotatedMethod()
>       java.lang.reflect.Method m = ob.getClass().getMethod("annotatedMethod")
>       List annos = m.getAnnotations()
>       println("annos = $annos")
>    }
> }
> @Target(ElementType.METHOD)
> @Retention(RetentionPolicy.RUNTIME)
> @Repeatable(MyAnnotationArray) 
> public @interface MyAnnotation
> {
>     String value() default "val0";
> }
> @Retention(RetentionPolicy.RUNTIME)
> public @interface MyAnnotationArray 
> {
>    MyAnnotation[] value()
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message