Skip to content

Repeatable Annotations #144

@ssmoss

Description

@ssmoss

I am using reflections version 0.9.10 with javassist version 3.20.0-GA. I have the following annotations and classes:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Names {
    Name[] value() default {};
}

@Repeatable(Names.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Names {
    String name();
}

@Name(name = "foo")
public class SingleName extends BaseClass {}

@Name(name = "foo")
@Name(name = "bar")
public class MultiName extends BaseClass {}

I am trying to look up all classes that have occurrence of the @Name annotation. I used the following to try to do that:

new Reflections(BaseClass.class.getPackage().getName()).getTypesAnnotatedWith(Name.class)

The above only works when the class has as single @Name. To get a classes with more than one occurrence of the @Name I need to use the following:

new Reflections(BaseClass.class.getPackage().getName()).getTypesAnnotatedWith(Names.class)

I ideally I would like to not have to merge the results from both of these calls. It seems that java supports that because when I do the following:

SingleName.class.getAnnotationsByType(Name.class); //Return an array of one
MultiName.class.getAnnotationsByType(Name.class); //Returns an array of two

Does reflections currently support this and I am using it wrong? If not would it be possible to add support for repeatable annotations? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions