本文整理了Java中org.powermock.reflect.internal.WhiteboxImpl.getAllFields()
方法的一些代码示例,展示了WhiteboxImpl.getAllFields()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WhiteboxImpl.getAllFields()
方法的具体详情如下:
包路径:org.powermock.reflect.internal.WhiteboxImpl
类名称:WhiteboxImpl
方法名:getAllFields
[英]Get all fields in a class hierarchy! Both declared an non-declared (no duplicates).
[中]获取类层次结构中的所有字段!两者都声明为未声明(无重复)。
代码示例来源:origin: org.powermock/powermock-api-support
/**
* 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);
}
代码示例来源:origin: org.powermock.api/powermock-api-support
/**
* 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);
}
代码示例来源:origin: org.powermock/powermock-reflect
/**
* 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;
}
代码示例来源:origin: org.powermock.reflect/powermock-reflect
/**
* 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;
}
内容来源于网络,如有侵权,请联系作者删除!