return getTypeArguments(type, toClass, null);
public static Type getTypeArgument(Type genericType) { Type[] types = getTypeArguments(genericType); if(types.length == 0) { return Object.class; } if(types.length == 1) { Type type = types[0]; if (type instanceof WildcardType) { types = ((WildcardType) type).getUpperBounds(); if (types.length != 1) { throw new IllegalArgumentException("Found multi upper bounds at type argument '" + type + "'"); } type = types[0]; } return type; } throw new IllegalArgumentException("Found multi type arguments of '" + genericType + "'"); }
public static Class<?>[] getActualTypeArguments(Type genericType){ return getActualTypes(getTypeArguments(genericType)); }
return getTypeArguments((Class<?>) type, toClass, subtypeVarAssigns); return getTypeArguments((ParameterizedType) type, toClass, subtypeVarAssigns); return getTypeArguments(((GenericArrayType) type).getGenericComponentType(), toClass.isArray() ? toClass.getComponentType() : toClass, subtypeVarAssigns); return getTypeArguments(bound, toClass, subtypeVarAssigns); return getTypeArguments(bound, toClass, subtypeVarAssigns);
Map<TypeVariable<?>, Type> fromTypeVarAssigns = getTypeArguments(type, toClass, null); Map<TypeVariable<?>, Type> toTypeVarAssigns = getTypeArguments(toParameterizedType, toClass, typeVarAssigns);
protected static Map doConvert(ConvertContext context, Map from, Class<?> targetType, Type genericType) { Type[] typeArguments = Types.getTypeArguments(genericType); Class<?> keyType = Types.getActualType(typeArguments[0]); Class<?> valType = Types.getActualType(typeArguments[1]); Map to = createMap(targetType); for(Object o : from.entrySet()){ Entry entry = (Entry)o; Object key = Converts.convert(entry.getKey(), keyType, typeArguments[0], context); Object val = Converts.convert(entry.getValue(), valType, typeArguments[1], context); to.put(key,val); } return to; }
typeVarAssigns = getTypeArguments(parameterizedOwnerType, getRawType(parameterizedOwnerType), subtypeVarAssigns); } else { return getTypeArguments(getClosestParentType(cls, toClass), toClass, typeVarAssigns);
return getTypeArguments(getClosestParentType(cls, toClass), toClass, typeVarAssigns);
protected Type[] getDictionaryTypes(Class<?> type, Type genericType) { Type[] types = Types.getTypeArguments(genericType); if(types.length != 2) { for(Type genericInterface : type.getGenericInterfaces()) { Class<?> c = Types.getActualType(genericInterface); if(Map.class.isAssignableFrom(c)) { return getDictionaryTypes(c, genericInterface); } } Type genericSuperClass = type.getGenericSuperclass(); if(null != genericSuperClass) { Class<?> c = Types.getActualType(genericSuperClass); if(Map.class.isAssignableFrom(c)) { return getDictionaryTypes(c, genericSuperClass); } } } return types; }
Map<TypeVariable<?>, Type> typeVarAssigns = getTypeArguments(assigningType, (Class<?>) genericDeclaration);
return getTypeArguments(superType, superClass, null);
Type[] types = Types.getTypeArguments(genericType); if(types.length != 2) { return null;