01: package org.caramba.annotations;
02:
03: import java.lang.reflect.Field;
04: import java.util.List;
05: import java.util.AbstractList;
06: import java.util.ArrayList;
07:
08: /**
09: * Utilitiy for Annotation Usage.
10: * @author Pieter Degraeuwe
11: */
12: public class AnnotationUtil {
13: /**
14: * Gets all Declared field of the given class, including the declared fields of the super classes.
15: * @param pClass the class of which the fields are requested
16: * @return the requested fields
17: */
18: public static List<Field> getAllDeclaredFields(Class pClass) {
19: return getAllDeclaredFields(new ArrayList<Field>(), pClass);
20: }
21:
22: private static List<Field> getAllDeclaredFields(List<Field> pList,
23: Class pClass) {
24: Field[] declaredFields = pClass.getDeclaredFields();
25: for (int i = 0; i < declaredFields.length; i++) {
26: Field declaredField = declaredFields[i];
27: pList.add(declaredField);
28: }
29: Class super class = pClass.getSuperclass();
30: if (!super class.equals(Object.class)) {
31: return getAllDeclaredFields(pList, superclass);
32: }
33: return pList;
34: }
35:
36: }
|