protected static Type getCallbackType(InvocationCallback<?> callback) { Class<?> cls = callback.getClass(); ParameterizedType pt = findCallbackType(cls); Type actualType = null; for (Type tp : pt.getActualTypeArguments()) { actualType = tp; break; } if (actualType instanceof TypeVariable) { actualType = InjectionUtils.getSuperType(cls, (TypeVariable<?>)actualType); } return actualType; }
protected static Type getCallbackType(InvocationCallback<?> callback) { Class<?> cls = callback.getClass(); ParameterizedType pt = findCallbackType(cls); Type actualType = null; for (Type tp : pt.getActualTypeArguments()) { actualType = tp; break; } if (actualType instanceof TypeVariable) { actualType = InjectionUtils.getSuperType(cls, (TypeVariable<?>)actualType); } return actualType; }
public static Type getSuperType(Class<?> serviceClass, TypeVariable<?> var) { int pos = 0; GenericDeclaration genericDeclaration = var.getGenericDeclaration(); TypeVariable<?>[] vars = genericDeclaration.getTypeParameters(); for (; pos < vars.length; pos++) { if (vars[pos].getName().equals(var.getName())) { break; } } ParameterizedType genericSubtype = findGenericDeclaration(genericDeclaration, serviceClass); Type result = null; if (genericSubtype != null) { result = genericSubtype.getActualTypeArguments()[pos]; } if (result instanceof TypeVariable) { result = getSuperType(serviceClass, (TypeVariable<?>) result); } if (result == null || result == Object.class) { for (Type bound : var.getBounds()) { if (bound != Object.class) { result = bound; break; } } } return result; }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(type))) { TypeVariable<?> typeVar = (TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); Class<?> cls = theType instanceof Class ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0); type = new ParameterizedCollectionType(cls); } if (type == null || type == Object.class) { type = paramCls; } return type; }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType)type; if (pt.getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(pt))) { TypeVariable<?> typeVar = (TypeVariable<?>)pt.getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); if (theType instanceof Class) { type = new ParameterizedCollectionType((Class<?>)theType); } else { type = processGenericTypeIfNeeded(serviceCls, paramCls, theType); type = new ParameterizedCollectionType(type); } } } if (type == null || type == Object.class) { type = paramCls; } return type; }