本文整理匯總了Java中org.reflections.ReflectionUtils.getAllFields方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils.getAllFields方法的具體用法?Java ReflectionUtils.getAllFields怎麽用?Java ReflectionUtils.getAllFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getAllFields方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: EsPropertyNamingStrategy
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public EsPropertyNamingStrategy(Class type, Class<? extends EsStore> store) {
this.effectiveType = type;
for (Field field : ReflectionUtils.getAllFields(type)) {
JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class);
EsStoreMappingProperty
storeSpecificProperty =
field.getAnnotation(EsStoreMappingProperty.class);
if ((jsonProperty == null && storeSpecificProperty == null)
|| (storeSpecificProperty != null && storeSpecificProperty.ignore())) {
continue;
}
if (storeSpecificProperty == null || storeSpecificProperty.store() != store) {
fieldToJsonMapping.put(jsonProperty.value(), jsonProperty.value());
} else if (storeSpecificProperty.value().indexOf('.') < 0) {
fieldToJsonMapping.put(jsonProperty.value(), storeSpecificProperty.value());
}
}
}
示例2: createClassViewDescriptor
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private static ClassViewDescriptor createClassViewDescriptor(final Class<?> dataType)
{
@SuppressWarnings("unchecked")
final Set<Field> fields = ReflectionUtils.getAllFields(dataType, ReflectionUtils.withAnnotations(ViewColumn.class));
final ImmutableList<ClassViewColumnDescriptor> columns = fields.stream()
.map(field -> createClassViewColumnDescriptor(field))
.collect(ImmutableList.toImmutableList());
if (columns.isEmpty())
{
return ClassViewDescriptor.EMPTY;
}
return ClassViewDescriptor.builder()
// .className(dataType.getName())
.columns(columns)
.build();
}
示例3: resolveQueryParams
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SneakyThrows
private WebTarget resolveQueryParams(WebTarget target, SchemaLink link, String method) {
UriTemplate uriTemplate = link.getHref();
if (method.equalsIgnoreCase("get") && requestObject != null) {
List<String> vars = uriTemplate.getTemplateVariables();
Set<Field> matchingFields = ReflectionUtils.getAllFields(requestObject.getClass(),
f -> !vars.contains(f.getName()));
for (Field field : matchingFields) {
field.setAccessible(true);
if (field.get(requestObject) != null) {
if (Collection.class.isAssignableFrom(field.getType())) {
Collection<?> value = (Collection<?>) field.get(requestObject);
String[] values = value.stream().map(Object::toString).collect(Collectors.toList())
.toArray(new String[0]);
target = target.queryParam(field.getName(), values);
} else {
target = target.queryParam(field.getName(), field.get(requestObject).toString());
}
}
}
}
return target;
}
示例4: findDefinedColumnNames
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private final Set<String> findDefinedColumnNames()
{
//
// Collect all columnnames
final ImmutableSet.Builder<String> columnNamesBuilder = ImmutableSet.builder();
ReflectionUtils.getAllFields(modelClass, new Predicate<Field>()
{
@Override
public boolean apply(final Field field)
{
final String fieldName = field.getName();
if (fieldName.startsWith("COLUMNNAME_"))
{
final String columnName = fieldName.substring("COLUMNNAME_".length());
columnNamesBuilder.add(columnName);
}
return false;
}
});
return columnNamesBuilder.build();
}
示例5: invoke
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Extracts all beans with annotation {@link ImmutableRegistry} from Spring
* context and converts all fields with the type {@link Map} to
* {@link ImmutableMap}.
*
* @param context
*/
@SuppressWarnings("unchecked")
public static void invoke(ApplicationContext context) {
Collection<Object> registries = context.getBeansWithAnnotation(ImmutableRegistry.class).values();
for (Object registry : registries) {
Set<Field> mapFields = ReflectionUtils.getAllFields(registry.getClass(),
new AssignableFromPredicate(Map.class));
for (Field mapField : mapFields) {
try {
mapField.setAccessible(true);
Map<?, ?> sourceMap = (Map<?, ?>) mapField.get(registry);
if (sourceMap != null && !(sourceMap instanceof ImmutableMap)) {
mapField.set(registry, ImmutableMap.copyOf(sourceMap));
log.info("Convert to immutable map: " + registry + " -> " + mapField);
}
mapField.setAccessible(false);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
}
示例6: render
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@Override
@SuppressWarnings({ "unchecked" })
public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) {
Map<String, Object> fieldMap = new HashMap<String, Object>();
Set<Field> jsonPathFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(JSONPath.class));
String jsonStr = response.getContent();
jsonStr = jsonp2Json(jsonStr);
if (jsonStr == null) {
return;
}
try {
Object json = JSON.parse(jsonStr);
for (Field field : jsonPathFields) {
Object value = injectJsonField(request, field, json);
if(value != null) {
fieldMap.put(field.getName(), value);
}
}
} catch(JSONException ex) {
//throw new RenderException(ex.getMessage(), bean.getClass());
RenderException.log("json parse error : " + request.getUrl(), bean.getClass(), ex);
}
beanMap.putAll(fieldMap);
}
示例7: extractAnyColumn
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void extractAnyColumn() {
Set<Field> anyColumnFields = ReflectionUtils.getAllFields(type, withAnnotation(AnyColumn.class));
if (anyColumnFields.size() > 0) {
if (anyColumnFields.size() > 1) {
throw new XceliteException("Multiple AnyColumn fields are not allowed");
}
Field anyColumnField = anyColumnFields.iterator().next();
if (!anyColumnField.getType().isAssignableFrom(Map.class)) {
throw new XceliteException(
String.format("AnyColumn field \"%s\" should be of type Map.class or assignable from Map.class",
anyColumnField.getName()));
}
anyColumn = new Col(anyColumnField.getName(), anyColumnField.getName());
anyColumn.setAnyColumn(true);
AnyColumn annotation = anyColumnField.getAnnotation(AnyColumn.class);
anyColumn.setType(annotation.as());
if (annotation.converter() != NoConverterClass.class) {
anyColumn.setConverter(annotation.converter());
}
}
}
示例8: initializeInterceptor
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private void initializeInterceptor() {
AbstractWebApplication application = (AbstractWebApplication) getApplication();
for (Field field : ReflectionUtils.getAllFields(this.getClass())) {
if (field.getAnnotation(Setting.class) != null) {
Setting setting = field.getAnnotation(Setting.class);
if (field.getType() != FileUpload.class
&& field.getType() != FileUpload[].class) {
try {
FieldUtils.writeField(
field,
this,
application.select(setting.name(),
field.getType()), true);
} catch (IllegalAccessException e) {
}
}
}
}
org.apache.wicket.markup.html.form.TextField<String> repository = (org.apache.wicket.markup.html.form.TextField<String>) getFormComponent("repository");
getForm().add(new LocalRepositoryValidator(repository));
}
示例9: initializeInterceptor
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private void initializeInterceptor() {
AbstractWebApplication application = (AbstractWebApplication) getApplication();
for (Field field : ReflectionUtils.getAllFields(this.getClass())) {
if (field.getAnnotation(Setting.class) != null) {
Setting setting = field.getAnnotation(Setting.class);
if (field.getType() != FileUpload.class
&& field.getType() != FileUpload[].class) {
try {
FieldUtils.writeField(
field,
this,
application.select(setting.name(),
field.getType()), true);
} catch (IllegalAccessException e) {
}
}
}
}
org.apache.wicket.markup.html.form.TextField<String> local = (org.apache.wicket.markup.html.form.TextField<String>) getFormComponent("repository");
getForm().add(new LocalRepositoryValidator(local));
}
示例10: GenericEntityMapper
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public GenericEntityMapper(Class<T> clazz) {
this.clazz = clazz;
if (org.springframework.core.annotation.AnnotationUtils.findAnnotation(
this.clazz, Entity.class) == null) {
throw new DatabaseException(clazz.getSimpleName()
+ " is not entity");
}
for (Field field : ReflectionUtils.getAllFields(this.clazz)) {
Column column = field.getAnnotation(Column.class);
if (column != null) {
fields.put(column.name(), field.getName());
types.put(field.getName(), field);
}
}
}
示例11: getSimpleORMFieldInEntity
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* 獲取實體中所有簡單的數據庫映射字段
*/
public static List<String> getSimpleORMFieldInEntity(Class entityClass){
if(entityClass==null){
return null ;
}
//獲取所有聲明的字段
Set<Field> fields = ReflectionUtils.getAllFields(entityClass) ;
List<String> simpleFields = new ArrayList<String>() ;
for (Field field : fields) {
if(isSimpleORMField(field)){
simpleFields.add(field.getName()) ;
}
}
return simpleFields ;
}
示例12: getAllFields
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
public static Map<String, Field> getAllFields(Class classType) {
if (!classAllFieldsCache.containsKey(classType)) {
Set<Field> objectFieldsSet = ReflectionUtils.getAllFields(classType);
Map<String, Field> objectFieldsMap = new HashMap<>();
for (Field f : objectFieldsSet) {
objectFieldsMap.put(f.getName(), f);
}
classAllFieldsCache.put(classType, objectFieldsMap);
}
return classAllFieldsCache.get(classType);
}
示例13: getFollowUpClass
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private Class<?> getFollowUpClass(PropertyDescriptor propertyDescriptor, Class<?> clazzBefore) {
Class<?> clazz = propertyDescriptor.getElementClass();
if (Collection.class.isAssignableFrom(clazz)) {
final Predicate<? super Field> predicate = f -> f.getName().equals(propertyDescriptor
.getPropertyName());
@SuppressWarnings("unchecked")
Set<Field> field = ReflectionUtils.getAllFields(clazzBefore, predicate);
Type typeArgument = ((ParameterizedType) field.iterator().next().getGenericType())
.getActualTypeArguments()[0];
return (Class<?>) typeArgument;
} else {
return clazz;
}
}
示例14: configure
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@Override
protected void configure() {
Set<Field> f = ReflectionUtils.getAllFields(instanceToReadMocksFrom.getClass());
for (Field field : f) {
if (field.getAnnotation(Mock.class) != null || field.getAnnotation(Spy.class) != null) {
try {
field.setAccessible(true);
bindReflectedInstance(field.get(instanceToReadMocksFrom), field.getType());
} catch (Exception e) {
throw new IllegalArgumentException("Unable to bind mock field " + field.getName() + " from "
+ instanceToReadMocksFrom.getClass().getName(), e);
}
}
}
}
示例15: extractFieldsFromRequestObjectFor
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Set<Field> extractFieldsFromRequestObjectFor(String var) {
if (requestObject == null) {
return Collections.emptySet();
}
return ReflectionUtils.getAllFields(requestObject.getClass(), f -> f.getName().equals(var));
}