Hi Andreas,
I think this is correct now. By coincidence, Joe Darcy is trying to
implement default methods in interface AnnotatedElement and I think
those two attempts could be merged. The s.r.a.AnnotationSupport static
methods: getDirectlyAndIndirectlyPresent & getAssociatedAnnotations
could be implemented in terms of AnnotatedElement's
getDeclaredAnnotation(Class) - not needing to pass annotation maps
around and not needing JavaLangAccess. The major obstacle that you have
already solved somehow in your implementation is keeping the right order
of returned annotations. For example:
#1
@Ann(1)
@AnnCont({@Ann(2), @Ann(3)})
vs.
#2
@AnnCont({@Ann(2), @Ann(3)})
@Ann(1)
Is this corner case really so important that specification could not be
"tweaked" a little to say that #2 is equivalent to #1 as far as order or
returned annotations is concerned (first comes any directly present and
then any in-directly present annotations). If spec. could be tweaked,
the implementations would be much simpler. Here's a rough sketch of such
simplified AnnotatioSupport:
http://cr.openjdk.java.net/~plevart/jdk8-tl/RepeatingAnnotations/webrev.01/
Regards, Peter
On 10/23/2013 05:36 PM, Andreas Lundblad wrote:
On 10/22/2013 03:20 PM, Peter Levart wrote:
I think the problem could be solved in two ways:
- by explicitly scanning the inheritance chain for the 1st class that
has the annotations of type T present directly or indirectly (by
containment).
- by "canonicalizing" the representation of the repeating annotations
in the class file attributes. By this I mean that each repeating
annotation is placed inside it's container at compile-time even if it
is a single annotation of a particular type. This would mean that
some features like specifying different @Targets or @Retentions for
repeating annotation types and their containers would be prohibited
and the specification would have to be changed. But I think this way
the "inheritance" aspect of repeating annotations would be consistent
even if not "looking through" containers (by using the old JDK7 API)...
The "canonicalization" could be performed at runtime though, and I
think there were such attempts already in the past. What happened to
them?
Regards, Peter
Hi Peter,
A new patch is available for review here:
http://cr.openjdk.java.net/~alundblad/inherited-associated/
This includes a new test based on your code. The test passes after
applying the patch.
best regards,
Andreas Lundblad