本文整理汇总了Java中java.lang.reflect.TypeVariable.getGenericDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java TypeVariable.getGenericDeclaration方法的具体用法?Java TypeVariable.getGenericDeclaration怎么用?Java TypeVariable.getGenericDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.TypeVariable
的用法示例。
在下文中一共展示了TypeVariable.getGenericDeclaration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInheritGenericType
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
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;
if (ptype.getRawType() == gd) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tvs[i] == tv) return types[i];
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
示例2: createByParamName
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static JavaType createByParamName(final ImplementClass implementClass, final TypeVariable<?> variable) {
GenericDeclaration declaration = variable.getGenericDeclaration();
String name = variable.getName();
TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
for (int index = 0; index < typeParameters.length; index++) {
TypeVariable<?> type = typeParameters[index];
if (name.equals(type.getName())) {
if (declaration instanceof Class) {
Class<?> declarationClass = (Class<?>) declaration;
Class<?> sub = implementClass.getSubclass(declarationClass);
if (sub != null) {
Type genericSuperclass = implementClass.getGenericParentClass(declarationClass);
if (genericSuperclass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
return create(implementClass, parameterizedType.getActualTypeArguments()[index]);
}
// Generics未指定
}
return new VariableJavaType(implementClass, type);
} else if (declaration instanceof Executable) {
return new VariableJavaType(implementClass, type);
}
}
}
throw new IllegalArgumentException();
}
示例3: equals
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
if (o instanceof TypeVariable) {
TypeVariable that = (TypeVariable) o;
GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName();
return
(genericDeclaration == null ?
thatDecl == null :
genericDeclaration.equals(thatDecl)) &&
(name == null ?
thatName == null :
name.equals(thatName));
} else
return false;
}
示例4: translateTypeVariable
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static Type translateTypeVariable(Map<String, Type> lookup, TypeVariable var) {
GenericDeclaration declaredBy = var.getGenericDeclaration();
if (!(declaredBy instanceof Class)) {
// if the <T> is not defined by class, there is no way to get the actual type
return Object.class;
}
Class clazz = (Class) declaredBy;
Type actualType = lookup.get(var.getName() + "@" + clazz.getCanonicalName());
if (actualType == null) {
// should not happen
return Object.class;
}
if (actualType instanceof TypeVariable) {
// translate to another variable, try again
return translateTypeVariable(lookup, (TypeVariable) actualType);
}
return actualType;
}
示例5: equals
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
@Override
public boolean equals(Object o) {
if (o instanceof TypeVariable &&
o.getClass() == TypeVariableImpl.class) {
TypeVariable<?> that = (TypeVariable<?>) o;
GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName();
return Objects.equals(genericDeclaration, thatDecl) &&
Objects.equals(name, thatName);
} else
return false;
}
示例6: check2
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static void check2(Type t, String what) {
if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) t;
check(pt.getActualTypeArguments(), "type argument", what);
} else if (t instanceof TypeVariable) {
TypeVariable<?> tv = (TypeVariable<?>) t;
check(tv.getBounds(), "bound", what);
GenericDeclaration gd = tv.getGenericDeclaration();
if (gd instanceof Type)
check((Type) gd, "declaration containing " + what);
} else if (t instanceof WildcardType) {
WildcardType wt = (WildcardType) t;
check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
} else if (t instanceof Class<?>) {
Class<?> c = (Class<?>) t;
check(c.getGenericInterfaces(), "superinterface", c.toString());
check(c.getGenericSuperclass(), "superclass of " + c);
check(c.getTypeParameters(), "type parameter", c.toString());
} else if (t instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) t;
Type comp = gat.getGenericComponentType();
if (comp instanceof Class) {
fail("Type " + t + " uses GenericArrayType when plain " +
"array would do, in " + what);
} else
check(comp, "component type of " + what);
} else {
fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
}
}
示例7: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static Class<?> declaringClassOf(TypeVariable typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class
? (Class<?>) genericDeclaration
: null;
}
示例8: equals
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns true if {@code a} and {@code b} are equal.
*/
static boolean equals(Type a, Type b) {
if (a == b) {
return true; // Also handles (a == null && b == null).
} else if (a instanceof Class) {
return a.equals(b); // Class already specifies equals().
} else if (a instanceof ParameterizedType) {
if (!(b instanceof ParameterizedType)) return false;
ParameterizedType pa = (ParameterizedType) a;
ParameterizedType pb = (ParameterizedType) b;
return equal(pa.getOwnerType(), pb.getOwnerType())
&& pa.getRawType().equals(pb.getRawType())
&& Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());
} else if (a instanceof GenericArrayType) {
if (!(b instanceof GenericArrayType)) return false;
GenericArrayType ga = (GenericArrayType) a;
GenericArrayType gb = (GenericArrayType) b;
return equals(ga.getGenericComponentType(), gb.getGenericComponentType());
} else if (a instanceof WildcardType) {
if (!(b instanceof WildcardType)) return false;
WildcardType wa = (WildcardType) a;
WildcardType wb = (WildcardType) b;
return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
&& Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());
} else if (a instanceof TypeVariable) {
if (!(b instanceof TypeVariable)) return false;
TypeVariable<?> va = (TypeVariable<?>) a;
TypeVariable<?> vb = (TypeVariable<?>) b;
return va.getGenericDeclaration() == vb.getGenericDeclaration()
&& va.getName().equals(vb.getName());
} else {
return false; // This isn't a type we support!
}
}
示例9: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static Class<?> declaringClassOf(TypeVariable typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class
? (Class<?>) genericDeclaration
: null;
}
示例10: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class
? (Class<?>) genericDeclaration
: null;
}
示例11: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
}
示例12: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static @Nullable Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null;
}
示例13: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null;
}
示例14: declaringClassOf
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
* a class.
*/
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null;
}
示例15: equals
import java.lang.reflect.TypeVariable; //导入方法依赖的package包/类
/**
* Returns true if {@code a} and {@code b} are equal.
*/
public static boolean equals(Type a, Type b) {
if (a == b) {
// also handles (a == null && b == null)
return true;
} else if (a instanceof Class) {
// Class already specifies equals().
return a.equals(b);
} else if (a instanceof ParameterizedType) {
if (!(b instanceof ParameterizedType)) {
return false;
}
// TODO: save a .clone() call
ParameterizedType pa = (ParameterizedType) a;
ParameterizedType pb = (ParameterizedType) b;
return Objects.equals(pa.getOwnerType(), pb.getOwnerType())
&& pa.getRawType().equals(pb.getRawType())
&& Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());
} else if (a instanceof GenericArrayType) {
if (!(b instanceof GenericArrayType)) {
return false;
}
GenericArrayType ga = (GenericArrayType) a;
GenericArrayType gb = (GenericArrayType) b;
return equals(ga.getGenericComponentType(), gb.getGenericComponentType());
} else if (a instanceof WildcardType) {
if (!(b instanceof WildcardType)) {
return false;
}
WildcardType wa = (WildcardType) a;
WildcardType wb = (WildcardType) b;
return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
&& Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());
} else if (a instanceof TypeVariable) {
if (!(b instanceof TypeVariable)) {
return false;
}
TypeVariable<?> va = (TypeVariable) a;
TypeVariable<?> vb = (TypeVariable) b;
return va.getGenericDeclaration() == vb.getGenericDeclaration()
&& va.getName().equals(vb.getName());
} else {
// This isn't a type we support. Could be a generic array type, wildcard type, etc.
return false;
}
}