use of java.lang.reflect.GenericDeclaration in project fastjson by alibaba.
the class FieldInfo method getInheritGenericType.
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
Type superGenericType = clazz.getGenericSuperclass();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
Type rawType = ptype.getRawType();
boolean eq = gd.equals(rawType) || (gd instanceof Class && rawType instanceof Class && ((Class) gd).isAssignableFrom((Class) rawType));
if (eq) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tv.equals(tvs[i])) {
return types[i];
}
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
use of java.lang.reflect.GenericDeclaration in project XobotOS by xamarin.
the class ImplForVariable method resolve.
void resolve() {
if (formalVar != null) {
return;
}
GenericDeclaration curLayer = declOfVarUser;
TypeVariable var;
while ((var = findFormalVar(curLayer, name)) == null) {
curLayer = nextLayer(curLayer);
if (curLayer == null) {
throw new AssertionError("illegal type variable reference");
}
}
formalVar = (ImplForVariable<D>) var;
this.genericDeclaration = formalVar.genericDeclaration;
this.bounds = formalVar.bounds;
}
Aggregations