/** * Get all fields in a class hierarchy. * * @param clazz * The class that should contain the fields. * @return An array of Field's. May be of length 0 but not {@code null} * */ public static Field[] fields(Class<?> clazz) { return WhiteboxImpl.getAllFields(clazz); }
/** * Get all fields in a class hierarchy. * * @param clazz * The class that should contain the fields. * @param firstFieldName * The name of the first field. * @param additionalfieldNames * The additional names of the fields that will be returned. * @return An array of Field's. May be of length 0 but not <code>null</code> * */ public static Field[] fields(Class<?> clazz) { return WhiteboxImpl.getAllFields(clazz); }
/** * Get an array of {@link Field}'s that matches the supplied list of field * names. Both instance and static fields are taken into account. * * @param clazz The class that should contain the fields. * @param fieldNames Names of the fields that will be returned. * @return An array of Field's. May be of length 0 but not . */ public static Field[] getFields(Class<?> clazz, String... fieldNames) { final List<Field> fields = new LinkedList<Field>(); for (Field field : getAllFields(clazz)) { for (String fieldName : fieldNames) { if (field.getName().equals(fieldName)) { fields.add(field); } } } final Field[] fieldArray = fields.toArray(new Field[fields.size()]); if (fieldArray.length == 0) { throw new FieldNotFoundException(String.format( "No fields matching the name(s) %s were found in the class hierarchy of %s.", concatenateStrings(fieldNames), getType(clazz))); } return fieldArray; }
/** * Get an array of {@link Field}'s that matches the supplied list of field * names. Both instance and static fields are taken into account. * * @param clazz * The class that should contain the fields. * @param fieldNames * Names of the fields that will be returned. * @return An array of Field's. May be of length 0 but not . */ public static Field[] getFields(Class<?> clazz, String... fieldNames) { final List<Field> fields = new LinkedList<Field>(); for (Field field : getAllFields(clazz)) { for (String fieldName : fieldNames) { if (field.getName().equals(fieldName)) { fields.add(field); } } } final Field[] fieldArray = fields.toArray(new Field[fields.size()]); if (fieldArray.length == 0) { throw new FieldNotFoundException(String.format( "No fields matching the name(s) %s were found in the class hierarchy of %s.", concatenateStrings(fieldNames), getType(clazz))); } return fieldArray; }