choigv / 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

How to get Constructors with a given annotation? #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If I configure the MethodAnnotationScanner to run and also annotate a no-args 
constructor for some class, I see an entry for the annotated constructor 
amongst the method values collected under <MethodAnnotationsScanner>, with a 
method name of <init()>, which is fine, but the getMethodsAnnotatedWith() 
method won't return it.  If I iterate the methods returned by 
getMethodsAnnotatedWith(), the set includes an entry with a null value for the 
Method.  It seems as if entries for constructors cause entries in the Set 
returned by getMethodsAnnotatedWith() having a value of null.  Meanwhile, there 
is no "getConstructorsAnnotatedWith()" method unless I missed it.
So how does one obtain constructors annotated with some annotation?
Thanks in advance...

What steps will reproduce the problem?
1.  Configure the MethodAnnotationScanner
2.  Annotate a no-args constructor in some class
3.  Run mvn process-classes
4.  Examine the generated XML, note that a value entry was generated for an 
"init()" method for that class
5.  Run getMethodsAnnotatedWith() for the indicated annotation and iterate the 
set.
     Notice that the set includes a null value, presumbly corresponding to the constructor

Set<Method> methods = fReflections.getMethodsAnnotatedWith(MyAnnotation.class);
for (Method method : methods) {
  // Reflections gives me null methods, have to do this to avoid NPE
  if (method == null)
    continue;
   ...
}

What is the expected output? What do you see instead?

Expect a non-null value for the "init()" method which is the no-args 
constructor.
Either that or no null entries in the set, but a getConstructorsAnnotatedWIth() 
method is provided.

What version of the product are you using? On what operating system?

0.9.8

Please provide any additional information below.

Original issue reported on code.google.com by nmerritt...@gmail.com on 22 Aug 2012 at 7:05

GoogleCodeExporter commented 9 years ago
fixed on trunk, comments are welcomed

Original comment by ronm...@gmail.com on 20 Feb 2013 at 9:04