On 10/25/2013 12:29 PM, Peter Levart wrote:

Hi Joe,

So, the order must be respected, right.

There's a bug. I think you wanted to call:

((Class) this).getSuperclass()

Instead of:

thisClass.getSuperclass()

...which would always return Object.class...


Well, this is not the only change needed, of course. What about something like the following (prefer iteration to recursion and use AnnotationType.isInherited() which is faster):


default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
        T[] result = getDeclaredAnnotationsByType(annotationClass);
        if (result.length == 0 && this instanceof Class &&
AnnotationType.getInstance(annotationClass).isInherited()) {
            for (Class<?> clazz = ((Class<?>) this).getSuperclass();
                 clazz != null; clazz = clazz.getSuperclass()) {
result = clazz.getDeclaredAnnotationsByType(annotationClass);
                if (result.length > 0) {
                    break;
                }
            }
        }
        return result;
    }


Regards, Peter

Regards, Peter

On Oct 25, 2013 10:40 AM, "Joe Darcy" <joe.da...@oracle.com <mailto:joe.da...@oracle.com>> wrote:

    Hi Joel and Peter,

    On 10/24/2013 07:10 AM, Peter Levart wrote:
    Hi Joe,

    I see two problems with the implementation in
    *AnnotatedElementSupport*. The first is the treatment of
    declared-only annotations where the code returns either directly
    present or in-directly present repeatable annotations, but not
    both. So in the following example:

    @Ann(1)
    @AnnCont({@Ann(2), @Ann(3)})

    it will only return [@Ann(1)], but I think it should return all
    of them [@Ann(1), @Ann(2), @Ann(3)] - does the spec. define that?


    [snip]

    From your feedback (and a closer reading of the specifciation),
    I've reworked the specifications and implemenations of the default
    methods for get[Declared]AnnotationsByType:

    http://cr.openjdk.java.net/~darcy/8005294.2/
    <http://cr.openjdk.java.net/%7Edarcy/8005294.2/>

    Tests still need to be written, but this implementation should be
    much closed to what is needed.

    Thanks,

    -Joe


Reply via email to