/** * Searches for the typevariable definition in the inClass hierarchy. * * @param type * @param inClass * @return the resolved type or type if unable to resolve it. */ public final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass) { return resolveTypeVariable(type, genericDeclarationToClass(type.getGenericDeclaration()), inClass); }
/** * Searches for the typevariable definition in the inClass hierarchy. * * @param type * @param inClass * @return the resolved type or type if unable to resolve it. */ public final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass) { return resolveTypeVariable(type, genericDeclarationToClass(type.getGenericDeclaration()), inClass); }
final static Type expand(Type type, Class<?> inClass) { Type expandedType = null; if (type instanceof TypeVariable) { @SuppressWarnings("unchecked") // for the moment we assume it is a class, we can later handle ctr and methods TypeVariable<GenericDeclaration> tvType = (TypeVariable<GenericDeclaration>) type; if (inClass == null) inClass = genericDeclarationToClass(tvType.getGenericDeclaration()); expandedType = resolveTypeVariable(tvType, inClass); if (type.equals(expandedType)) expandedType = tvType.getBounds()[0]; } else if (type instanceof WildcardType) { WildcardType wType = (WildcardType) type; expandedType = wType.getUpperBounds().length > 0 ? expand(wType.getUpperBounds()[0], inClass) : Object.class; } else return type; return expandedType == null || type.equals(expandedType) ? Object.class : expandedType; }
final static Type expand(Type type, Class<?> inClass) { Type expandedType = null; if (type instanceof TypeVariable) { @SuppressWarnings("unchecked") // for the moment we assume it is a class, we can later handle ctr and methods TypeVariable<GenericDeclaration> tvType = (TypeVariable<GenericDeclaration>) type; if (inClass == null) inClass = genericDeclarationToClass(tvType.getGenericDeclaration()); expandedType = resolveTypeVariable(tvType, inClass); if (type.equals(expandedType)) expandedType = tvType.getBounds()[0]; } else if (type instanceof WildcardType) { WildcardType wType = (WildcardType) type; expandedType = wType.getUpperBounds().length > 0 ? expand(wType.getUpperBounds()[0], inClass) : Object.class; } else return type; return expandedType == null || type.equals(expandedType) ? Object.class : expandedType; }
String typeName = tvType.getName(); int idx = 0; for (TypeVariable<?> parameter : genericDeclarationToClass(tvType.getGenericDeclaration()) .getTypeParameters()) { if (typeName.equals(parameter.getName())) {
String typeName = tvType.getName(); int idx = 0; for (TypeVariable<?> parameter : genericDeclarationToClass(tvType.getGenericDeclaration()) .getTypeParameters()) { if (typeName.equals(parameter.getName())) {