use of java.lang.reflect.GenericDeclaration in project j2objc by google.
the class TypeVariableImpl method resolve.
void resolve() {
// if (formalVar != null) {
if (genericDeclaration != 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");
}
}
TypeVariableImpl<D> formalVar = (TypeVariableImpl<D>) var;
this.genericDeclaration = formalVar.genericDeclaration;
this.bounds = formalVar.bounds;
}
use of java.lang.reflect.GenericDeclaration in project cxf by apache.
the class InjectionUtils method getSuperType.
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;
}
use of java.lang.reflect.GenericDeclaration in project uavstack by uavorg.
the class FieldInfo method getInheritGenericType.
private static Type getInheritGenericType(Class<?> clazz, Type type, TypeVariable<?> tv) {
GenericDeclaration gd = tv.getGenericDeclaration();
Class<?> class_gd = null;
if (gd instanceof Class) {
class_gd = (Class<?>) tv.getGenericDeclaration();
}
Type[] arguments = null;
if (class_gd == clazz) {
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
arguments = ptype.getActualTypeArguments();
}
} else {
for (Class<?> c = clazz; c != null && c != Object.class && c != class_gd; c = c.getSuperclass()) {
Type superType = c.getGenericSuperclass();
if (superType instanceof ParameterizedType) {
ParameterizedType p_superType = (ParameterizedType) superType;
Type[] p_superType_args = p_superType.getActualTypeArguments();
getArgument(p_superType_args, c.getTypeParameters(), arguments);
arguments = p_superType_args;
}
}
}
if (arguments == null || class_gd == null) {
return null;
}
Type actualType = null;
TypeVariable<?>[] typeVariables = class_gd.getTypeParameters();
for (int j = 0; j < typeVariables.length; ++j) {
if (tv.equals(typeVariables[j])) {
actualType = arguments[j];
break;
}
}
return actualType;
}
use of java.lang.reflect.GenericDeclaration in project nutz by nutzam.
the class ReflectTool method getInheritGenericType.
/**
* 获取泛型类clazz中某个TypeVariable对应的真实Type.
* @param clazz
* @param tv
* @return
*/
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
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 = Lang.getTypeClass(type);
} while (type != null);
return null;
}
Aggregations