private static Class<?> getConvertedType(Class<?> declaringClass, java.lang.reflect.Type convertedType, Class<?> javaType) { if (convertedType == null) { return javaType; } return ReflectionUtils.resolveType(declaringClass, convertedType); }
/** * Tries to resolve the type variable against the concrete class. The * concrete class has to be a subtype of the type in which the type variable * has been declared. This method tries to resolve the given type variable * by inspecting the subclasses of the class in which the type variable was * declared and as soon as the resolved type is instance of java.lang.Class * it stops and returns that class. * * @param concreteClass The class which is used to resolve the type. The type for the * type variable must be bound in this class or a superclass. * @param typeVariable The type variable to resolve. * @return The resolved type as class * @throws IllegalArgumentException Is thrown when the concrete class is not a subtype of the * class in which the type variable has been declared. */ public static Class<?> resolveTypeVariable(Class<?> concreteClass, TypeVariable<?> typeVariable) { Type resolvedType = resolveTypeVariableType(concreteClass, typeVariable); return resolveType(concreteClass, resolvedType); }
public static Class<?> resolveType(Class<?> concreteClass, Type type) { if (type instanceof TypeVariable<?>) { return resolveTypeVariable(concreteClass, (TypeVariable<?>) type); } else if (type instanceof ParameterizedType) { return (Class<?>) ((ParameterizedType) type).getRawType(); } else if (type instanceof GenericArrayType) { return getArrayClass((GenericArrayType) type); } else if (type instanceof WildcardType) { WildcardType wildcardType = ((WildcardType) type); if (wildcardType.getLowerBounds().length > 0) { return resolveType(concreteClass, wildcardType.getLowerBounds()[0]); } else { return resolveType(concreteClass, wildcardType.getUpperBounds()[0]); } } else { // We assume here that only class types, type variables and parameterized types are // possible as argument types for the parameterized type return (Class<?>) type; } }
public static Class<?>[] resolveTypeArguments(Class<?> concreteClass, ParameterizedType parameterizedType) { if (parameterizedType == null) { return null; } Type[] argumentTypes = parameterizedType.getActualTypeArguments(); Class<?>[] resolvedClasses = new Class<?>[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) { resolvedClasses[i] = resolveType(concreteClass, argumentTypes[i]); } return resolvedClasses; }
Class<?> type = ReflectionUtils.resolveType(entityViewClass, parameterType); boolean forceSingular = parameterAnnotations.containsKey(MappingSingular.class) || parameterAnnotations.containsKey(MappingParameter.class); boolean isCollection = !forceSingular && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)); declaredKeyType = typeArguments.length > 1 ? typeArguments[0] : null; declaredElementType = typeArguments[typeArguments.length - 1]; keyType = ReflectionUtils.resolveType(entityViewClass, declaredKeyType); elementType = ReflectionUtils.resolveType(entityViewClass, declaredElementType); } else { declaredType = parameterType;
resolvedType = resolveType(concreteClass, wildcardType.getLowerBounds()[0]); } else { resolvedType = resolveType(concreteClass, wildcardType.getUpperBounds()[0]);
public MethodAttributeMapping readMethodAttributeMapping(ViewMapping viewMapping, Annotation mapping, String attributeName, Method method) { Class<?> entityViewClass = viewMapping.getEntityViewClass(); Type returnType = ReflectionUtils.resolve(entityViewClass, method.getGenericReturnType()); Class<?> type = ReflectionUtils.resolveType(entityViewClass, returnType); boolean forceSingular = AnnotationUtils.findAnnotation(method, MappingSingular.class) != null || AnnotationUtils.findAnnotation(method, MappingParameter.class) != null; boolean isCollection = !forceSingular && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)); declaredKeyType = typeArguments.length > 1 ? typeArguments[0] : null; declaredElementType = typeArguments[typeArguments.length - 1]; keyType = ReflectionUtils.resolveType(entityViewClass, declaredKeyType); elementType = ReflectionUtils.resolveType(entityViewClass, declaredElementType); } else { declaredType = returnType;