cailin186 / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Annotation (non-)inheritance incorrectly handled by getTypesAnnotatedWith? #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run the attached file.

What is the expected output? What do you see instead?
I would expect:

    member: class org.reflections.annotation.inheritance.Super

What I see is:

    member: class org.reflections.annotation.inheritance.Super
    member: class org.reflections.annotation.inheritance.Sub

Reflections.getTypesAnnotatedWith() seems to behave as though all annotations 
Xyz are @Inherited, 
even when they aren't.

What version of the product are you using? On what operating system?
Reflections 0.9.5-RC1
Java 1.5.0_22
Mac OS X 10.5.8
NetBeans 6.8
Maven 2.2.0

Please provide any additional information below.
Seems to be related to issue 19 
(http://code.google.com/p/reflections/issues/detail?
id=19&can=1&q=inherited)...

Original issue reported on code.google.com by stephen....@gmail.com on 25 Jan 2010 at 6:37

Attachments:

GoogleCodeExporter commented 9 years ago
I modified Store. getAllTypesAnnotatedWith() as follows and it now does what I 
expect. And the JUnit tests 
still succeed :-)

The change consists of adding the test

  isInheritedAnnotation(annotation) && 

to the "else if". 

    public Set<String> getAllTypesAnnotatedWith(final String annotation) {
        ImmutableSet.Builder<String> result = ImmutableSet.builder();

        for (String typeAnnotatedWith : get(TypeAnnotationsScanner.class, annotation)) {
            result.add(typeAnnotatedWith);

            if (isAnnotation(typeAnnotatedWith)) {
                result.addAll(getTypesAnnotatedWith(annotation));
            } else if (isInheritedAnnotation(annotation) && hasSubTypes(typeAnnotatedWith)) {
                result.addAll(getSubTypesOf(typeAnnotatedWith));
            }
        }

        return result.build();
    }

Original comment by stephen....@gmail.com on 26 Jan 2010 at 4:50

GoogleCodeExporter commented 9 years ago
fixed on trunk

Original comment by ronm...@gmail.com on 14 May 2010 at 2:23

GoogleCodeExporter commented 9 years ago

Original comment by ronm...@gmail.com on 17 May 2010 at 4:21