X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Freflection%2FAnnotationUtils.java;h=5ea776b3217dac607e939adcfcc49025c2eeb8df;hb=4c6867aaa3873fb90890ed5129e195ee13fb661b;hp=d31163fb11812487096953b9662d716f7dca5d1b;hpb=3b46fd24cf5269eda5ca1b74ac7cc028ad371b5e;p=utils diff --git a/support/general/src/main/java/org/wamblee/reflection/AnnotationUtils.java b/support/general/src/main/java/org/wamblee/reflection/AnnotationUtils.java index d31163fb..5ea776b3 100644 --- a/support/general/src/main/java/org/wamblee/reflection/AnnotationUtils.java +++ b/support/general/src/main/java/org/wamblee/reflection/AnnotationUtils.java @@ -18,6 +18,7 @@ package org.wamblee.reflection; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; /** @@ -35,15 +36,17 @@ public class AnnotationUtils { * Class to analyse. * @param aAnnotation * Annotation that must be present. - * @return Accessor to use or null if the annotation is not present. + * @return List of accessors. Empty list is returned if no match is found. */ // TODO move generic analysis part to the reflection package. - public static Accessor analyse(Class aClass, + public static List analyse(Class aClass, Class aAnnotation) { + List result = new ArrayList(); + List fields = ReflectionUtils.getAllFields(aClass); for (Field field : fields) { if (field.isAnnotationPresent(aAnnotation)) { - return new FieldAccessor(field); + result.add(new FieldAccessor(field)); } } List methods = ReflectionUtils.getAllMethods(aClass, @@ -60,14 +63,14 @@ public class AnnotationUtils { Class returnType = method.getReturnType(); Method setter = method.getDeclaringClass() .getDeclaredMethod(setterName, returnType); - return new PropertyAccessor(method, setter); + result.add(new PropertyAccessor(method, setter)); } catch (NoSuchMethodException e) { throw new RuntimeException("Error obtaining setter for " + method.getName() + " in class " + aClass.getName(), e); } } } - return null; + return result; } }