You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/04/25 20:36:00 UTC

[jira] [Comment Edited] (GROOVY-9096) Repeatable annotation not wrapped with container type in class file

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

Eric Milles edited comment on GROOVY-9096 at 4/25/19 8:35 PM:
--------------------------------------------------------------

Looks like this has to do with {{CLASS}} retention vs {{RUNTIME}} retention.  This edit in {{ExtendedVerifier}} fixes the issue:
{code:java}
    protected void visitAnnotations(AnnotatedNode node, int target) {
        ...
        Map<String, List<AnnotationNode>> runtimeAnnotations = new LinkedHashMap<String, List<AnnotationNode>>();
        for (AnnotationNode unvisited : node.getAnnotations()) {
            AnnotationNode visited = visitAnnotation0(unvisited);
            String name = visited.getClassNode().getName();
            // GRECLIPSE edit
            //if (visited.hasRuntimeRetention()) {
            if (!visited.hasSourceRetention()) {
            // GRECLIPSE end
                List<AnnotationNode> seen = runtimeAnnotations.get(name);
                if (seen == null) {
                    seen = new ArrayList<AnnotationNode>();
                }
                seen.add(visited);
                runtimeAnnotations.put(name, seen);
            }
            ...
        }
        checkForDuplicateAnnotations(node, runtimeAnnotations);
    }
{code}

Probably want to rename the {{runtimeAnnotations}} map as well.


was (Author: emilles):
Looks like this has to do with {{CLASS}} retention vs {{RUNTIME}} retention.  This edit in {{ExtendedVerifier}} fixes the issue:
{code:java}
    protected void visitAnnotations(AnnotatedNode node, int target) {
        ...
        Map<String, List<AnnotationNode>> runtimeAnnotations = new LinkedHashMap<String, List<AnnotationNode>>();
        for (AnnotationNode unvisited : node.getAnnotations()) {
            AnnotationNode visited = visitAnnotation0(unvisited);
            String name = visited.getClassNode().getName();
            // GRECLIPSE edit
            //if (visited.hasRuntimeRetention()) {
            if (!visited.hasSourceRetention()) {
            // GRECLIPSE end
                List<AnnotationNode> seen = runtimeAnnotations.get(name);
                if (seen == null) {
                    seen = new ArrayList<AnnotationNode>();
                }
                seen.add(visited);
                runtimeAnnotations.put(name, seen);
            }
            ...
        }
        checkForDuplicateAnnotations(node, runtimeAnnotations);
    }
{code}

> Repeatable annotation not wrapped with container type in class file
> -------------------------------------------------------------------
>
>                 Key: GROOVY-9096
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9096
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.5.6
>            Reporter: Eric Milles
>            Priority: Major
>
> Consider the following:
> Anno.java
> {code:java}
> import java.lang.annotation.*;
> @Retention(RetentionPolicy.CLASS)
> @Repeatable(Annos.class)
> @interface Anno {
>   String value() default "";
> }
> @interface Annos {
>   Anno[] value();
> }
> {code}
> Pogo.groovy
> {code:groovy}
> @Anno @Anno('x')
> class Pogo {}
> {code}
> When this is compiled, the annotations in the class file are incorrect:
> {code}
> // Compiled from Pogo.groovy (version 1.8 : 52.0, super bit)
> @Anno@pack.Anno(value="x")
> public class Pogo implements groovy.lang.GroovyObject {
> {code}
> vs.
> {code}
> // Compiled from Pojo.java (version 1.8 : 52.0, super bit)
> @Annos(value={@Anno,@Anno(value="x")})
> public class Pojo {
> {code}
> See GROOVY-8234 for initial support for {{@Repeatable}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)