reflections icon indicating copy to clipboard operation
reflections copied to clipboard

Meta annotations on methoods are not resolved

Open godart opened this issue 5 years ago • 1 comments

getMethodsAnnotatedWith() does not return methods with meta-annotations like getTypesAnnotatedWith

Example:

@Target({METHOD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@interface MetaMethod { }

@MetaMethod
@Target(METHOD)
@Retention(RUNTIME)
@interface AM {}

@MetaMethod
@Target(METHOD)
@Retention(RUNTIME)
@interface BM {}

class A1 {
    @AM public void inA1() {}
}
class B1 {
    @BM public void inB1() {}
}
class A2 {
    @AM public void inA2() {}
}

public class Annotations {

    public static void main(String[] args) {
        Reflections reflections = new Reflections(
                new ConfigurationBuilder()
                        .forPackages("org.jsondoc.springmvc.scanner")
                        .addScanners(new MethodAnnotationsScanner()));
        System.out.println("MetaMethods:");
        for (Method type: reflections.getMethodsAnnotatedWith(MetaMethod.class)) {
            System.out.println(type.getName());
        }
        System.out.println("AnnotatedMethdos");
        for (Method type: reflections.getMethodsAnnotatedWith(AM.class)) {
            System.out.println(type.getName());
        }
    }
}

prints

MetaMethods:
AnnotatedMethdos
inA2
inA1

expected:

MetaMethods:
inA1
inA2
inB1
AnnotatedMethdos
inA2
inA1

godart avatar Oct 09 '19 09:10 godart

#208 describes a similar inconsistency for type annotations.

godart avatar Oct 09 '19 09:10 godart