import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.List;
/**
* 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<Accessor> analyse(Class aClass,
Class<? extends Annotation> aAnnotation) {
+ List<Accessor> result = new ArrayList<Accessor>();
+
List<Field> fields = ReflectionUtils.getAllFields(aClass);
for (Field field : fields) {
if (field.isAnnotationPresent(aAnnotation)) {
- return new FieldAccessor(field);
+ result.add(new FieldAccessor(field));
}
}
List<Method> methods = ReflectionUtils.getAllMethods(aClass,
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;
}
}