本文整理匯總了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);
}