本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.getFieldsListWithAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.getFieldsListWithAnnotation方法的具体用法?Java FieldUtils.getFieldsListWithAnnotation怎么用?Java FieldUtils.getFieldsListWithAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.getFieldsListWithAnnotation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassParameters
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private Map<String, String> getClassParameters() {
final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(getType(),
ru.yandex.qatools.allure.annotations.Parameter.class);
return fields.stream().collect(
Collectors.toMap(Allure1Utils::getParameterName, f -> Allure1Utils.getParameterValue(f, target))
);
}
示例2: getIdField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private Field getIdField(Class<?> domainClass) {
Field idField = null;
final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, Id.class);
if (fields.isEmpty()) {
idField = ReflectionUtils.findField(getJavaType(), "id");
} else if (fields.size() == 1) {
idField = fields.get(0);
} else {
throw new IllegalArgumentException("only one field with @Id annotation!");
}
if (idField != null && idField.getType() != String.class) {
throw new IllegalArgumentException("type of id field must be String");
}
return idField;
}
示例3: getPartitionKeyField
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private Field getPartitionKeyField(Class<?> domainClass) {
Field partitionKeyField = null;
final List<Field> fields = FieldUtils.getFieldsListWithAnnotation(domainClass, PartitionKey.class);
if (fields.size() == 1) {
partitionKeyField = fields.get(0);
} else if (fields.size() > 1) {
throw new IllegalArgumentException("Azure Cosmos DB supports only one partition key, " +
"only one field with @PartitionKey annotation!");
}
if (partitionKeyField != null && partitionKeyField.getType() != String.class) {
throw new IllegalArgumentException("type of PartitionKey field must be String");
}
return partitionKeyField;
}
示例4: injectContainers
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private void injectContainers() {
List<Field> fields = FieldUtils.getFieldsListWithAnnotation(testClass, InjectContainer.class);
for (Field field : fields) {
if (!Container.class.isAssignableFrom(field.getType())) {
continue;
}
InjectContainer container = field.getAnnotation(InjectContainer.class);
Container instance = controller.getContainer(container.name(), field.getType().asSubclass(Container.class));
LOG.info("Binding [{}] -> [{}]", container.name(), instance.getName());
try {
FieldUtils.writeField(field, target, instance, true);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Could not set field:" + field.getName());
}
}
}
示例5: inject
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
private void inject(Object mediator) {
List<Field> list = FieldUtils.getFieldsListWithAnnotation(mediator.getClass(), Port.class);
for (Field field : list) {
Port annotation = field.getAnnotation(Port.class);
if (field.getType().isAssignableFrom(Sink.class)) {
Sink<Object> sink = getSinkOrFail(annotation.value());
ReflectionHelper.set(mediator, field, sink);
} else if (field.getType().isAssignableFrom(Source.class)) {
Source<Object> source = getSourceOrFail(annotation.value());
ReflectionHelper.set(mediator, field, source);
}
}
}
示例6: buildPropertyNameAndAliasMap
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* 提取 klass {@link Alias} 注释,将 属性名字和 {@link Alias#name()} 组成map 返回.
*
* @param klass
* the klass
* @return 如果<code>klass</code> 没有 {@link Alias} 注释,返回 {@link Collections#emptyMap()}
* @throws NullPointerException
* 如果 <code>klass</code> 是null
* @since 1.8.1
*/
private static Map<String, String> buildPropertyNameAndAliasMap(Class<?> klass){
Validate.notNull(klass, "klass can't be null!");
List<Field> aliasFieldsList = FieldUtils.getFieldsListWithAnnotation(klass, Alias.class);
if (isNullOrEmpty(aliasFieldsList)){
return emptyMap();
}
//属性名字和key的对应关系
Map<String, String> propertyNameAndAliasMap = newHashMap(aliasFieldsList.size());
for (Field field : aliasFieldsList){
Alias alias = field.getAnnotation(Alias.class);
propertyNameAndAliasMap.put(field.getName(), alias.name());
}
return propertyNameAndAliasMap;
}
示例7: deserializeFormFields
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static void deserializeFormFields(Object target, ValueMap input) throws DeserializeException {
List<Field> fields = FieldUtils.getFieldsListWithAnnotation(target.getClass(), FormField.class);
deserializeFields(target, fields, input);
}
示例8: annotatedFields
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Get all fields of target instance annotated by given annotation type
*
* @param annotationClass type of annotation
* @return annotated fields
*/
public List<Field> annotatedFields(Class<? extends Annotation> annotationClass) {
return FieldUtils.getFieldsListWithAnnotation(clazz, annotationClass);
}