List of usage examples for java.lang.reflect Field getType
public Class<?> getType()
From source file:com.cloudbees.jenkins.support.impl.LoadStats.java
/** * The fields that a {@link LoadStatistics} has change as you move from pre-1.607 to post 1.607, so better to * just look and see what there is rather than hard-code. * * @return the fields that correspond to {@link MultiStageTimeSeries} *///from w ww . j a v a2 s . com private static List<Field> findFields() { List<Field> result = new ArrayList<Field>(); for (Field f : LoadStatistics.class.getFields()) { if (Modifier.isPublic(f.getModifiers()) && MultiStageTimeSeries.class.isAssignableFrom(f.getType()) && f.getAnnotation(Deprecated.class) == null) { result.add(f); } } return result; }
From source file:com.github.strawberry.guice.config.ConfigLoader.java
private static Collection<?> nestedCollectionOf(Field field, Map properties, Set<String> redisKeys) { Collection collection = collectionImplementationOf(field.getType()); for (String redisKey : redisKeys) { collection.add(properties.get(redisKey)); }/*from w ww .j a va 2 s . com*/ return collection; }
From source file:jfix.util.Reflections.java
/** * Returns true if given possible referrer is referencing given reference * object in one or more of the given referring fields. *//*from w ww.j a v a2 s. c om*/ public static boolean isReferrer(Object possibleReferrer, Set<Field> referringFields, Object reference) { try { for (Field field : referringFields) { Object fieldValue = field.get(possibleReferrer); if (fieldValue != null && (fieldValue == reference || (field.getType().isArray() && ArrayUtils.contains((Object[]) fieldValue, reference)))) { return true; } } return false; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:net.minecraftforge.common.config.FieldWrapper.java
public static boolean hasWrapperFor(Field field) { if (ADAPTERS.get(field.getType()) != null) return true; else if (Enum.class.isAssignableFrom(field.getType())) return true; else if (Map.class.isAssignableFrom(field.getType())) return true; return false; }
From source file:com.jedi.oracle.OracleTypeUtils.java
private static void findCustomTypesRecursive(List<Field> fields, Map<String, Class<?>> map) { for (Field field : fields) { Class fieldType = field.getType(); if (List.class.isAssignableFrom(fieldType)) { ParameterizedType listType = (ParameterizedType) field.getGenericType(); fieldType = (Class<?>) listType.getActualTypeArguments()[0]; }//w w w .j a va2 s.c om if (fieldType.isAnnotationPresent(CustomTypeMapping.class)) { CustomTypeMapping mapping = (CustomTypeMapping) fieldType.getAnnotation(CustomTypeMapping.class); map.put(mapping.name(), fieldType); List<Field> oracleObjectFields = FieldUtils.getFieldsListWithAnnotation(fieldType, OracleObjectMapping.class); if (oracleObjectFields != null && !oracleObjectFields.isEmpty()) { findCustomTypesRecursive(oracleObjectFields, map); } } } }
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
private static void loadObject(Object retObj, Field f, JSONObject jsonObj) throws JSONSerializationException { String key = f.getName();/* w ww. j a v a 2s . c o m*/ Class type = f.getType(); try { if (type.isPrimitive()) { if (type == Integer.TYPE) { f.setInt(retObj, jsonObj.getInt(key)); } else if (type == Long.TYPE) { f.setLong(retObj, jsonObj.getInt(key)); } else if (type == Short.TYPE) { f.setShort(retObj, (short) jsonObj.getInt(key)); } else if (type == Boolean.TYPE) { f.setBoolean(retObj, jsonObj.getBoolean(key)); } else if (type == Double.TYPE) { f.setDouble(retObj, jsonObj.getDouble(key)); } else if (type == Float.TYPE) { f.setFloat(retObj, (float) jsonObj.getDouble(key)); } else if (type == Character.TYPE) { char ch = jsonObj.getString(key).charAt(0); f.setChar(retObj, ch); } else if (type == Byte.TYPE) { f.setByte(retObj, (byte) jsonObj.getInt(key)); } else { throw new JSONSerializationException("Unknown primitive: " + type); } } else if (type == String.class) { f.set(retObj, jsonObj.getString(key)); } else if (JSONSerializable.class.isAssignableFrom(type)) { JSONObject jObj = jsonObj.getJSONObject(key); JSONSerializable serObj = deSerialize(type, jObj); f.set(retObj, serObj); } } catch (Exception e) { throw new JSONSerializationException(e.getMessage(), e); } }
From source file:com.github.strawberry.guice.config.ConfigLoader.java
private static Collection<?> collectionOf(Field field, Map properties, String key) { Collection collection = collectionImplementationOf(field.getType()); Object list = properties.get(key); Option<Type> genericType = genericTypeOf(field, 0); if (list != null) { if (list instanceof List) { if (genericType.exists(isAssignableTo(Collection.class)) || genericType.exists(isEqualTo(Object.class))) { collection.add(list);/*from ww w .j a va 2 s. co m*/ } else { collection.addAll((List) list); } } else if (list instanceof Collection) { if (genericType.exists(isAssignableTo(Collection.class)) || genericType.exists(isEqualTo(Object.class))) { collection.add(list); } else { collection.addAll((Collection) list); } } else if (list instanceof Map) { collection.add(((Map) list)); } else { collection.add(list); } return collection; } else { return collection; } }
From source file:com.streamsets.datacollector.execution.preview.sync.SyncPreviewer.java
private static Object getValueFromParam(Field field, String stringValue) { Class<?> type = field.getType(); if (String.class.isAssignableFrom(type)) { return stringValue; } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) { return Integer.parseInt(stringValue); } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) { return Long.parseLong(stringValue); } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE == type) { return Boolean.parseBoolean(stringValue); }//from w w w . j a v a2s . com return null; }
From source file:fit.TypeAdapter.java
public static TypeAdapter on(Fixture fixture, Field field) { TypeAdapter a = on(fixture, field.getType()); a.target = fixture;//from w w w.jav a 2 s . co m a.field = field; return a; }
From source file:kina.utils.UtilMongoDB.java
/** * converts from BsonObject to an entity class with kina's anotations * * @param classEntity the entity name.//from w ww . j a va 2 s .c o m * @param bsonObject the instance of the BSONObjet to convert. * @param <T> return type. * @return the provided bsonObject converted to an instance of T. * @throws IllegalAccessException * @throws InstantiationException * @throws InvocationTargetException */ public static <T> T getObjectFromBson(Class<T> classEntity, BSONObject bsonObject) throws IllegalAccessException, InstantiationException, InvocationTargetException { T t = classEntity.newInstance(); Field[] fields = filterKinaFields(classEntity); Object insert; for (Field field : fields) { Method method = Utils.findSetter(field.getName(), classEntity, field.getType()); Class<?> classField = field.getType(); Object currentBson = bsonObject.get(kinaFieldName(field)); if (currentBson != null) { if (Iterable.class.isAssignableFrom(classField)) { Type type = field.getGenericType(); insert = subDocumentListCase(type, (List) bsonObject.get(kinaFieldName(field))); } else if (KinaType.class.isAssignableFrom(classField)) { insert = getObjectFromBson(classField, (BSONObject) bsonObject.get(kinaFieldName(field))); } else { insert = currentBson; } method.invoke(t, insert); } } return t; }