/** * This method return all the fields (including private) from the given class and its super * classes. * * @param fieldClass Class * @return List<Field> * @should return all fields include private and super classes */ public static List<Field> getAllFields(Class<?> fieldClass) { List<Field> fields = ClassDataCacher.getInstance().getClassData(fieldClass).getFields(); return new ArrayList<>(fields); }
/** * Get all annotations present on the represented class * * @return the set of all annotations on the class this refers to */ public Set<Annotation> getClassAnnotations() { return new HashSet<Annotation>( classData.getAnnotations() ); }
public int compare(Member o1, Member o2) { String c1 = getModifierPrefix(o1.getModifiers()) + o1.getName(); String c2 = getModifierPrefix(o2.getModifiers()) + o2.getName(); return c1.compareTo(c2); } }
/** * Populates the fields from the class data object * @param includeNonPublic if true then all fields will be used, if false then only public fields */ private void populateFields(boolean includeNonPublic) { // set the fields List<Field> fields; if (includeNonPublic) { fields = classData.getFields(); } else { fields = classData.getPublicFields(); } for (Field field : fields) { if (! includeStaticFields && isStatic(field)) { continue; // skip statics } String fieldName = field.getName(); if (ignoredFieldNames.contains(fieldName)) { continue; // skip ignored names } if (! namesToProperties.containsKey(fieldName)) { ClassProperty p = new ClassProperty(fieldName, field); namesToProperties.put(fieldName, p); } } }
for (Method method : classData.getMethods()) { int paramCount = method.getParameterTypes().length; for (Field field : classData.getFields()) { try { String fieldName = field.getName();
throw new IllegalArgumentException("field class cannot be null"); classData = new ClassData<T>(fieldClass); fieldFindMode = findMode; includeClassField = includeClassFields; List<Annotation> annotations = classData.getAnnotations(); for (Annotation annotation : annotations) { List<Method> methods = cd.getMethods(); for (Method method : methods) { if (method.getName().equals("value")) { List<Method> methods = cd.getMethods(); for (Method method : methods) { if (method.getName().equals("value")) {
getAllAnnotations(type, annotations); constructors = new ArrayList<Constructor<T>>(5); fields = new ArrayList<Field>(5); interfaces = new ArrayList<Class<?>>(5); superclasses = new ArrayList<Class<?>>(5); getAllThings(type, fields, methods, constructors, interfaces, superclasses);
/** * Constructor for when you have descriptors and fields in arrays (if you have descriptors it is * easy to get the fields from the class using {@link Class#getFields()}), no arguments can be * null but the arrays can be empty * * @param fieldClass * this is the class whose fields are represented * @param descriptors * an array of descriptors, you can get these from * {@link BeanInfo#getPropertyDescriptors()} and you can get the {@link BeanInfo} * from {@link Introspector#getBeanInfo(Class)} * @param publicFields * array of public fields */ public ClassFields(Class<T> fieldClass, PropertyDescriptor[] descriptors, Field[] publicFields) { if (fieldClass == null || descriptors == null || publicFields == null) { throw new IllegalArgumentException("None of the params can be null"); } classData = new ClassData<T>(fieldClass); fieldFindMode = FieldFindMode.HYBRID; namesToProperties = new ArrayOrderedMap<String, ClassProperty>(descriptors.length + publicFields.length); populateProperties(descriptors); populateFields(publicFields); populateAnnotationsFields(); }
constructors = getClassDataCacher().getClassData(type).getConstructors(); } catch (IllegalArgumentException e) { try {
public Enum convertInterface(Object value, Class<? extends Enum> implementationType) { Enum convert = null; String name = value.toString(); // can only deal with strings // now we try to find the enum field in this enum class ClassFields<Enum> cf = (ClassFields<Enum>) getFieldUtils().analyzeClass(implementationType); List<Enum> enumConstants = cf.getClassData().getEnumConstants(); for (Enum e : enumConstants) { if (e.name().equals(name)) { // found the matching enum convert = e; break; } } if (convert == null) { throw new UnsupportedOperationException("Failure attempting to create enum for name ("+name+") in ("+implementationType+")"); } return convert; }
getAllThings(interfaces[i], fList, mList, cList, iList, sList); getAllThings(superClass, fList, mList, cList, iList, sList);
/** * Populates the fields from the class data object * @param includeNonPublic if true then all fields will be used, if false then only public fields */ private void populateFields(boolean includeNonPublic) { // set the fields List<Field> fields; if (includeNonPublic) { fields = classData.getFields(); } else { fields = classData.getPublicFields(); } for (Field field : fields) { if (! includeStaticFields && isStatic(field)) { continue; // skip statics } String fieldName = field.getName(); if (ignoredFieldNames.contains(fieldName)) { continue; // skip ignored names } if (! namesToProperties.containsKey(fieldName)) { ClassProperty p = new ClassProperty(fieldName, field); namesToProperties.put(fieldName, p); } } }
for (Method method : classData.getMethods()) { int paramCount = method.getParameterTypes().length; for (Field field : classData.getFields()) { try { String fieldName = field.getName();
throw new IllegalArgumentException("field class cannot be null"); classData = new ClassData<T>(fieldClass); fieldFindMode = findMode; includeClassField = includeClassFields; List<Annotation> annotations = classData.getAnnotations(); for (Annotation annotation : annotations) { List<Method> methods = cd.getMethods(); for (Method method : methods) { if (method.getName().equals("value")) { List<Method> methods = cd.getMethods(); for (Method method : methods) { if (method.getName().equals("value")) {
getAllAnnotations(type, annotations); constructors = new ArrayList<Constructor<T>>(5); fields = new ArrayList<Field>(5); interfaces = new ArrayList<Class<?>>(5); superclasses = new ArrayList<Class<?>>(5); getAllThings(type, fields, methods, constructors, interfaces, superclasses);
/** * Constructor for when you have descriptors and fields in arrays (if you have descriptors it is * easy to get the fields from the class using {@link Class#getFields()}), no arguments can be * null but the arrays can be empty * * @param fieldClass * this is the class whose fields are represented * @param descriptors * an array of descriptors, you can get these from * {@link BeanInfo#getPropertyDescriptors()} and you can get the {@link BeanInfo} * from {@link Introspector#getBeanInfo(Class)} * @param publicFields * array of public fields */ public ClassFields(Class<T> fieldClass, PropertyDescriptor[] descriptors, Field[] publicFields) { if (fieldClass == null || descriptors == null || publicFields == null) { throw new IllegalArgumentException("None of the params can be null"); } classData = new ClassData<T>(fieldClass); fieldFindMode = FieldFindMode.HYBRID; namesToProperties = new ArrayOrderedMap<String, ClassProperty>(descriptors.length + publicFields.length); populateProperties(descriptors); populateFields(publicFields); populateAnnotationsFields(); }
if ( ConstructorUtils.isClassBean(type) ) { constructors = getClassDataCacher().getClassData(type).getConstructors(); } else {
public Enum convertInterface(Object value, Class<? extends Enum> implementationType) { Enum convert = null; String name = value.toString(); // can only deal with strings // now we try to find the enum field in this enum class ClassFields<Enum> cf = (ClassFields<Enum>) getFieldUtils().analyzeClass(implementationType); List<Enum> enumConstants = cf.getClassData().getEnumConstants(); for (Enum e : enumConstants) { if (e.name().equals(name)) { // found the matching enum convert = e; break; } } if (convert == null) { throw new UnsupportedOperationException("Failure attempting to create enum for name ("+name+") in ("+implementationType+")"); } return convert; }
getAllThings(interfaces[i], fList, mList, cList, iList, sList); getAllThings(superClass, fList, mList, cList, iList, sList);
/** * Get the field if it exists for this class * @param cd the class data cache object * @param name the name of the field * @return the field if found OR null if not */ protected Field getFieldIfPossible(ClassData<?> cd, String name) { Field f = null; List<Field> fields = cd.getFields(); for (Field field : fields) { if (field.getName().equals(name)) { f = field; break; } } return f; }