Multiple Annotations of the Same Type

Since I already made one small modification today, I also looked at allowing multiple annotations of the same type on an annotated element. Again, it was a very simple change in the compiler.

Both the modified compiler and the extended annotation framework now allow you to repeat the same annotation multiple times. Unfortunately, if the original reflection API is used, Java throws a  java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface TestMulti$MultiAnnotation: @TestMulti$MultiAnnotation(value=bar) exception (or similar), so make sure to use the new API in subannot.jar if you use this feature.

Since I couldn’t rely on Java’s reflection API anymore (because of the exception), I had to rework my framework a bit. The most complicated change involved the distinction between getAnnotations() and getDeclaredAnnotations(). I now have to inherit annotations to subclasses myself.

All that is done now, though. I still need to make a more thorough write-up and announce xajavac on several discussion boards. I don’t know when I’ll do that, though; I’ve had an incredibly productive day, but I’ve been working for 12 hours straight already. On the other hand, I’m rained in at the office and everyone else has left for Thanksgiving…


About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in xajavac. Bookmark the permalink.

Leave a Reply