/** * Given a type variable resolve the Java class of that variable. * * @param c the concrete class from which all type variables are resolved * @param dc the declaring class where the type variable was defined * @param tv the type variable * @return the resolved Java class and type, otherwise null if the type variable could not be resolved */ public static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv) { return resolveTypeVariable(c, dc, tv, new HashMap<TypeVariable, Type>()); }
/** * Given a type variable resolve the Java class of that variable. * * @param c the concrete class from which all type variables are resolved * @param dc the declaring class where the type variable was defined * @param tv the type variable * @return the resolved Java class and type, otherwise null if the type variable could not be resolved */ public static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv) { return resolveTypeVariable(c, dc, tv, new HashMap<TypeVariable, Type>()); }
/** * Get the parameterized type arguments for a declaring class that declares a generic interface type. * * @param p the declaring class * @return the parameterized type arguments, or null if the generic interface type is not a parameterized type. */ public static Type[] getParameterizedTypeArguments(DeclaringClassInterfacePair p) { if (p.genericInterface instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) p.genericInterface; Type[] as = pt.getActualTypeArguments(); Type[] ras = new Type[as.length]; for (int i = 0; i < as.length; i++) { Type a = as[i]; if (a instanceof Class) { ras[i] = a; } else if (a instanceof ParameterizedType) { pt = (ParameterizedType) a; ras[i] = a; } else if (a instanceof TypeVariable) { ClassTypePair ctp = resolveTypeVariable(p.concreteClass, p.declaringClass, (TypeVariable) a); ras[i] = ctp.t; } } return ras; } else { return null; } }
/** * Get the parameterized type arguments for a declaring class that declares a generic interface type. * * @param p the declaring class * @return the parameterized type arguments, or null if the generic interface type is not a parameterized type. */ public static Type[] getParameterizedTypeArguments(DeclaringClassInterfacePair p) { if (p.genericInterface instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) p.genericInterface; Type[] as = pt.getActualTypeArguments(); Type[] ras = new Type[as.length]; for (int i = 0; i < as.length; i++) { Type a = as[i]; if (a instanceof Class) { ras[i] = a; } else if (a instanceof ParameterizedType) { pt = (ParameterizedType) a; ras[i] = a; } else if (a instanceof TypeVariable) { ClassTypePair ctp = resolveTypeVariable(p.concreteClass, p.declaringClass, (TypeVariable) a); ras[i] = ctp.t; } } return ras; } else { return null; } }
private static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv, Map<TypeVariable, Type> map) { Type[] gis = c.getGenericInterfaces(); for (Type gi : gis) { if (gi instanceof ParameterizedType) { // process pt of interface ParameterizedType pt = (ParameterizedType) gi; ClassTypePair ctp = resolveTypeVariable(pt, (Class) pt.getRawType(), dc, tv, map); if (ctp != null) { return ctp; } } } Type gsc = c.getGenericSuperclass(); if (gsc instanceof ParameterizedType) { // process pt of class ParameterizedType pt = (ParameterizedType) gsc; return resolveTypeVariable(pt, c.getSuperclass(), dc, tv, map); } else if (gsc instanceof Class) { return resolveTypeVariable(c.getSuperclass(), dc, tv, map); } return null; }
private static ClassTypePair resolveTypeVariable(Class c, Class dc, TypeVariable tv, Map<TypeVariable, Type> map) { Type[] gis = c.getGenericInterfaces(); for (Type gi : gis) { if (gi instanceof ParameterizedType) { // process pt of interface ParameterizedType pt = (ParameterizedType) gi; ClassTypePair ctp = resolveTypeVariable(pt, (Class) pt.getRawType(), dc, tv, map); if (ctp != null) { return ctp; } } } Type gsc = c.getGenericSuperclass(); if (gsc instanceof ParameterizedType) { // process pt of class ParameterizedType pt = (ParameterizedType) gsc; return resolveTypeVariable(pt, c.getSuperclass(), dc, tv, map); } else if (gsc instanceof Class) { return resolveTypeVariable(c.getSuperclass(), dc, tv, map); } return null; }
/** * Get the parameterized class arguments for a declaring class that declares a generic interface type. * * @param p the declaring class * @return the parameterized class arguments, or null if the generic interface type is not a parameterized type. */ public static Class[] getParameterizedClassArguments(DeclaringClassInterfacePair p) { if (p.genericInterface instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) p.genericInterface; Type[] as = pt.getActualTypeArguments(); Class[] cas = new Class[as.length]; for (int i = 0; i < as.length; i++) { Type a = as[i]; if (a instanceof Class) { cas[i] = (Class) a; } else if (a instanceof ParameterizedType) { pt = (ParameterizedType) a; cas[i] = (Class) pt.getRawType(); } else if (a instanceof TypeVariable) { ClassTypePair ctp = resolveTypeVariable(p.concreteClass, p.declaringClass, (TypeVariable) a); cas[i] = (ctp != null) ? ctp.c : Object.class; } else if (a instanceof GenericArrayType) { cas[i] = getClassOfType(a); } } return cas; } else { return null; } }
/** * Get the parameterized class arguments for a declaring class that declares a generic interface type. * * @param p the declaring class * @return the parameterized class arguments, or null if the generic interface type is not a parameterized type. */ public static Class[] getParameterizedClassArguments(DeclaringClassInterfacePair p) { if (p.genericInterface instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) p.genericInterface; Type[] as = pt.getActualTypeArguments(); Class[] cas = new Class[as.length]; for (int i = 0; i < as.length; i++) { Type a = as[i]; if (a instanceof Class) { cas[i] = (Class) a; } else if (a instanceof ParameterizedType) { pt = (ParameterizedType) a; cas[i] = (Class) pt.getRawType(); } else if (a instanceof TypeVariable) { ClassTypePair ctp = resolveTypeVariable(p.concreteClass, p.declaringClass, (TypeVariable) a); cas[i] = (ctp != null) ? ctp.c : Object.class; } else if (a instanceof GenericArrayType) { cas[i] = getClassOfType(a); } } return cas; } else { return null; } }
return resolveTypeVariable(c, dc, tv, submap);
return resolveTypeVariable(c, dc, tv, submap);