atteo / classindex

Index classes, do not scan them!
Apache License 2.0
263 stars 43 forks source link

Added support for repeated annotations in java 8 #48

Closed marendil closed 5 years ago

marendil commented 5 years ago

If you want to annotate class few times with the same annotation you could do it this way:

  1. Java 6 and 7

    @ExampleAnnotations(@ExampleAnnotation("Example1"), @ExampleAnnotation("Example2"))
    public class SomeClass {//...
  2. Java 8 and above

    @ExampleAnnotation("Example1")
    @ExampleAnnotation("Example2")
    public class SomeClass {//...

In first case before my modification you have to mark @ExampleAnnotations with @IndexAnnotated, and search for classes annotated with @ExampleAnnotations instead of @ExampleAnnotation after fix everything work as it should without any additional code.

In second case @ExampleAnnotation had to have @Repeatable annotation with value set as ExampleAnnotations.class. @Repeatable annotation is compiled by another Annotation Processor which creates on-the-fly synthesized @ExampleAnnotations(@ExampleAnnotation("Example1"), @ExampleAnnotation("Example2")) with missing metadata so it did not work. After my fix everything works fine.

I've done it by adding new function in ClassIndexProcessor which checks every field in found annotation does it return list of another indexed annotations.

In pom.xml I've added testSource and testTarget to 8 and leave source and target as 1.7 because I don't know if you want to upgrade whole project to java 8. It makes little problem in IntelliJ because it doesn't support different java versions in one module but maven build work as it should.

marendil commented 5 years ago

Hi, is there any possibility that you will merge this pull request into master in near future?

sentinelt commented 5 years ago

@marendil Thank you for your contribution and sorry for the delay. I will try to look at this patch this weekend.

marendil commented 5 years ago

Thank You very much for merge. When do you plan to make new release? I'm not hiding that we are using ClassIndex in our project and don't want to use any snapshot version

sentinelt commented 5 years ago

I've merged your pull request. I've also fixed small issue where annotations not marked with Repeatable would also be indexed (see: https://github.com/atteo/classindex/commit/cec5878b4f6de9f68e5e4017cffbffed010d7d0c). I will push the release to Maven Central shortly.

sentinelt commented 5 years ago

Spoko :-)

Please take into account that it takes a few days for a release to propagate to Maven Central.