本文整理汇总了Java中com.googlecode.gentyref.GenericTypeReflector.getTypeParameter方法的典型用法代码示例。如果您正苦于以下问题:Java GenericTypeReflector.getTypeParameter方法的具体用法?Java GenericTypeReflector.getTypeParameter怎么用?Java GenericTypeReflector.getTypeParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.gentyref.GenericTypeReflector
的用法示例。
在下文中一共展示了GenericTypeReflector.getTypeParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inferCollection
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private static GenericType inferCollection(Type type) {
CollectionGenericType ret = new CollectionGenericType();
Type valueType = GenericTypeReflector.getTypeParameter(type, Collection.class.getTypeParameters()[0]);
ret.isInferred = valueType != null;
if (valueType == null) {
return ret;
}
ret.valueType = GenericTypeReflector.erase(valueType);
if (Map.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferMap(valueType);
} else if (Collection.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferCollection(valueType);
}
return ret;
}
示例2: bindProperty
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Binds {@code property} with {@code propertyType} to the field in the
* {@code objectWithMemberFields} instance using {@code memberField} as a
* reference to a member.
*
* @param objectWithMemberFields
* the object that contains (Java) member fields to build and bind
* @param memberField
* reference to a member field to bind
* @param propertyName
* property name to bind
* @param propertyType
* type of the property
* @return {@code true} if property is successfully bound
*/
protected boolean bindProperty(Object objectWithMemberFields, Field memberField, String propertyName,
Class<?> propertyType) {
log.log(Level.INFO, "Binding property, field={0}, property={1}",
new Object[] { memberField.getName(), propertyName });
Type valueType = GenericTypeReflector.getTypeParameter(memberField.getGenericType(),
HasValue.class.getTypeParameters()[0]);
if (valueType == null) {
throw new IllegalStateException(
String.format("Unable to detect value type for the member '%s' in the " + "class '%s'.",
memberField.getName(), objectWithMemberFields.getClass().getName()));
}
HasValue<?> field;
// Get the field from the object
try {
field = (HasValue<?>) ReflectTools.getJavaFieldValue(objectWithMemberFields, memberField, HasValue.class);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
log.log(Level.INFO, "Not able to determine type of field");
// If we cannot determine the value, just skip the field
return false;
}
bind(field, propertyName);
return true;
}
示例3: getActualType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private Type getActualType(final Class rawType, final Type type)
{
if (CompletableFuture.class.isAssignableFrom(rawType))
{
return GenericTypeReflector.getTypeParameter(type,
CompletableFuture.class.getTypeParameters()[0]);
}
return type;
}
示例4: inferMap
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private static GenericType inferMap(Type type) {
MapGenericType ret = new MapGenericType();
Type keyType = GenericTypeReflector.getTypeParameter(type, Map.class.getTypeParameters()[0]);
Type valueType = GenericTypeReflector.getTypeParameter(type, Map.class.getTypeParameters()[1]);
ret.isInferred = keyType != null && valueType != null;
if (keyType == null || valueType == null) {
return ret;
}
ret.keyType = GenericTypeReflector.erase(keyType);
ret.valueType = GenericTypeReflector.erase(valueType);
if (!ret.isInferred) {
return ret;
}
if (Map.class.isAssignableFrom(ret.keyType)) {
ret.nestedGenericKey = inferMap(keyType);
} else if (Collection.class.isAssignableFrom(ret.keyType)) {
ret.nestedGenericKey = inferCollection(keyType);
}
if (Map.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferMap(valueType);
} else if (Collection.class.isAssignableFrom(ret.valueType)) {
ret.nestedGenericValue = inferCollection(valueType);
}
return ret;
}
示例5: _collectionComponentType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Tries to guess a collection's component concrete type
* If it cannot guess the type, {@link Object} is returned
* @param type
* @param typeVar
* @return
*/
private static Class<?> _collectionComponentType(final Type type,final TypeVariable<? extends Class<?>> typeVar) {
Class<?> outComponentType = null;
Type compType = GenericTypeReflector.getTypeParameter(type,typeVar);
outComponentType = (compType != null
&& compType instanceof Class
&& !Modifier.isAbstract(((Class<?>)compType).getModifiers())) ? (Class<?>)compType
: Object.class;
return outComponentType;
}
示例6: CollectionTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public CollectionTranslater(TypeAndAnnos info) {
colType = GenericTypeReflector.erase(info.type);
colParamType = GenericTypeReflector.getTypeParameter(info.type, Collection.class.getTypeParameters()[0]);
if (colParamType == null)
colParamType = Object.class;
strictType = info.annos.isAnnotationPresent(StrictType.class);
el = info.annos;
}
示例7: MapTranslater
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public MapTranslater(TypeAndAnnos info) {
mapClass = (Class<T>) GenericTypeReflector.erase(info.type);
mapKType = GenericTypeReflector.getTypeParameter(info.type, Map.class.getTypeParameters()[0]);
mapVType = GenericTypeReflector.getTypeParameter(info.type, Map.class.getTypeParameters()[1]);
if (mapVType == null)
mapVType = Object.class;
strictType = info.annos.isAnnotationPresent(StrictType.class);
el = info.annos;
}
示例8: getPresentationTypeForField
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <PRESENTATION> Optional<Class<PRESENTATION>> getPresentationTypeForField(HasValue<PRESENTATION> field) {
// Unfortunately HasValue in Vaadin does not define a getType() method.
// Try to find the field type using reflection. This will work for any fields
// except fields with generic types.
Type valueType = GenericTypeReflector.getTypeParameter(field.getClass(), HasValue.class.getTypeParameters()[0]);
if (valueType != null) {
if (valueType instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) valueType;
return Optional.of((Class<PRESENTATION>) pType.getRawType());
}
return Optional.of((Class<PRESENTATION>) valueType);
}
// Not possible to find using reflection (due to type erasure).
// If field is an instance of HasGenericType
if (field instanceof HasGenericType) {
HasGenericType<PRESENTATION> type = (HasGenericType<PRESENTATION>) field;
return Optional.of(type.getGenericType());
}
// The road to success is paved with dirty hacks....
// If the field has a non null empty value we can fetch the type from this
PRESENTATION emptyValue = field.getEmptyValue();
if (emptyValue != null) {
return Optional.of((Class<PRESENTATION>) emptyValue.getClass());
}
// If the field has a current value we can fetch the type from this
PRESENTATION currentValue = field.getValue();
if (currentValue != null) {
return Optional.of((Class<PRESENTATION>) currentValue.getClass());
}
// If the field has items we can fetch the type from the first item
if (field instanceof HasItems) {
HasItems<PRESENTATION> hasItems = (HasItems<PRESENTATION>) field;
DataProvider<?, ?> dp = hasItems.getDataProvider();
Query<?, ?> q = new Query<>(0, 1, null, null, null);
if (dp.size((Query) q) > 0) {
return hasItems.getDataProvider().fetch((Query) q).findFirst().map(e -> e.getClass());
}
}
return Optional.empty();
}