本文整理汇总了Java中com.googlecode.gentyref.GenericTypeReflector.getExactSuperType方法的典型用法代码示例。如果您正苦于以下问题:Java GenericTypeReflector.getExactSuperType方法的具体用法?Java GenericTypeReflector.getExactSuperType怎么用?Java GenericTypeReflector.getExactSuperType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.gentyref.GenericTypeReflector
的用法示例。
在下文中一共展示了GenericTypeReflector.getExactSuperType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExactReturnType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Returns the exact return type of the given method in the given type. This
* may be different from <tt>m.getGenericReturnType()</tt> when the method
* was declared in a superclass, or <tt>type</tt> has a type parameter that
* is used in the return type, or <tt>type</tt> is a raw type.
*/
protected Type getExactReturnType(Method m, Type type) throws IllegalArgumentException{
Inputs.checkNull(m,type);
Type returnType = m.getGenericReturnType();
Type exactDeclaringType = GenericTypeReflector.getExactSuperType(GenericTypeReflector.capture(type),
m.getDeclaringClass());
if (exactDeclaringType == null) { // capture(type) is not a subtype of m.getDeclaringClass()
logger.info("The method " + m + " is not a member of type " + type
+ " - declared in " + m.getDeclaringClass());
return m.getReturnType();
}
//if (exactDeclaringType.equals(type)) {
// logger.debug("Returntype: " + returnType + ", " + exactDeclaringType);
// return returnType;
//}
return mapTypeParameters(returnType, exactDeclaringType);
}
示例2: getExactParameterTypes
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Returns the exact parameter types of the given method in the given type.
* This may be different from <tt>m.getGenericParameterTypes()</tt> when the
* method was declared in a superclass, or <tt>type</tt> has a type
* parameter that is used in one of the parameters, or <tt>type</tt> is a
* raw type.
*/
public Type[] getExactParameterTypes(Method m, Type type) {
Type[] parameterTypes = m.getGenericParameterTypes();
Type exactDeclaringType = GenericTypeReflector.getExactSuperType(GenericTypeReflector.capture(type),
m.getDeclaringClass());
if (exactDeclaringType == null) { // capture(type) is not a subtype of m.getDeclaringClass()
logger.info("The method " + m + " is not a member of type " + type
+ " - declared in " + m.getDeclaringClass());
return m.getParameterTypes();
}
Type[] result = new Type[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
result[i] = mapTypeParameters(parameterTypes[i], exactDeclaringType);
}
return result;
}
示例3: getExactParameterTypes
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Returns the exact parameter types of the given method in the given type.
* This may be different from <tt>m.getGenericParameterTypes()</tt> when the
* method was declared in a superclass, or <tt>type</tt> has a type
* parameter that is used in one of the parameters, or <tt>type</tt> is a
* raw type.
*/
public Type[] getExactParameterTypes(Constructor<?> m, Type type) {
Type[] parameterTypes = m.getGenericParameterTypes();
Type exactDeclaringType = GenericTypeReflector.getExactSuperType(GenericTypeReflector.capture(type),
m.getDeclaringClass());
if (exactDeclaringType == null) { // capture(type) is not a subtype of m.getDeclaringClass()
throw new IllegalArgumentException("The constructor " + m
+ " is not a member of type " + type);
}
Type[] result = new Type[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
result[i] = mapTypeParameters(parameterTypes[i], exactDeclaringType);
}
return result;
}
示例4: calculateExactType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
private void calculateExactType(ParameterizedType type) {
logger.info("Calculating exact tyep for parameterized type " + type);
Class<?> rawClass = GenericTypeReflector.erase(type);
Type exactType = type;
for (VariableReference var : typeMap.get(type)) {
ParameterizedType currentType = (ParameterizedType) var.getType();
logger.info("Assigned variable of type: " + currentType);
Type candidateType = GenericTypeReflector.getExactSuperType(currentType,
rawClass);
logger.info("Resulting type: " + candidateType);
if (TypeUtils.isAssignable(candidateType, exactType)) {
exactType = candidateType;
}
}
logger.info("Result: " + exactType);
}
示例5: _mapFieldKeyValueComponentTypes
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Devuelve el tipo de elementos la clave y valor de un Mapa {@link Map} parametrizado (Map<K,V>)
* NOTA: Debido al type erasure de los genericos en java el tipo de K y V en un Map<K,V> SOLO se puede obtener
* si se trata de un field de una clase (miembro), pero NO si se trata de una variable en un m�todo
* @param type el tipo donde est� definido el field
* @param field el miembro de una clase
* @return un array de dos posiciones: 0=tipo de la clave, 1=tipo del value
*/
@SuppressWarnings("unchecked")
public static Class<?>[] _mapFieldKeyValueComponentTypes(final Type type,final Field field) {
Class<?>[] outKeyAndValueTypes = new Class<?>[2]; // array de dos posiciones: 0=key, 1=value
Type genericFieldType = field.getGenericType();
if (genericFieldType instanceof Class) {
// Se trata de una clase que extiende de un mapa parametrizado
// Ej: public class LanguageTexts extends Map<Language,String> {...}
// Hay que obtener un type = Map<Language,String>
genericFieldType = GenericTypeReflector.getExactSuperType(field.getGenericType(),
Map.class);
}
// Aqui genericFieldType contiene SIEMPRE un mapa parametrizado (ej: Map<String,String>)
ParameterizedType mapComponentType = (ParameterizedType)genericFieldType;
if (mapComponentType.getActualTypeArguments().length == 2) {
// El field es un mapa
// ej: private Map<String,String> _theMap;
outKeyAndValueTypes[0] = ReflectionUtils.classOfType(mapComponentType.getActualTypeArguments()[0]);
outKeyAndValueTypes[1] = ReflectionUtils.classOfType(mapComponentType.getActualTypeArguments()[1]);
} else {
// El field es una clase que extiende de un mapa
// ej: private MyTypeImplementingMap _theMap;
// siendo public class MyTypeImplementingMap extends HashMap<String,String> {...}
mapComponentType = (ParameterizedType)field.getType().getGenericSuperclass();
outKeyAndValueTypes[0] = ReflectionUtils.classOfType(mapComponentType.getActualTypeArguments()[0]);
outKeyAndValueTypes[1] = ReflectionUtils.classOfType(mapComponentType.getActualTypeArguments()[1]);
}
// Si alguno de los componentes es una variable generica hay que ver si se puede obtener el tipo concreto a trav�s de la parametrizaci�n
if (outKeyAndValueTypes[0] == null || outKeyAndValueTypes[1] == null) {
for (int i=0; i <= 1; i++) {
if (outKeyAndValueTypes[i] == null && mapComponentType.getActualTypeArguments()[i] instanceof TypeVariable) {
outKeyAndValueTypes[i] = _collectionComponentType(type,(TypeVariable<? extends Class<?>>)mapComponentType.getActualTypeArguments()[i]);
}
}
}
return outKeyAndValueTypes;
}
示例6: _collectionFieldComponentType
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
/**
* Devuelve el tipo de elementos de una colecci�n {@link java.util.Collection} o un array parametrizado (Collection<E>)
* NOTA: Debido al type erasure de los genericos en java el tipo de un List<tipo> SOLO se puede obtener
* si se trata de un field de una clase (miembro), pero NO si se trata de una variable dentro del flujo
* @param field el miembro de una clase
* @return el tipo
*/
@SuppressWarnings("unchecked")
public static Class<?> _collectionFieldComponentType(final Type type,final Field field) {
Class<?> outCollectionComponentClass = null;
if (field.getType().isArray()) {
Type compType = GenericTypeReflector.getArrayComponentType(field.getType()); // field.getType().getComponentType();
outCollectionComponentClass = (compType != null && compType instanceof Class) ? (Class<?>)compType
: Object.class;
} else {
Type genericFieldType = field.getGenericType();
if (genericFieldType instanceof Class) {
// Se trata de una clase que extiende de una coleccion parametrizada
// Ej: public class LanguageTexts extends Map<Language,String> {...}
// Hay que obtener un type = Map<Language,String>
genericFieldType = GenericTypeReflector.getExactSuperType(field.getGenericType(),
Collection.class);
}
// Aqui genericFieldType contiene SIEMPRE una colecci�n parametrizada (ej: Collection<String>)
ParameterizedType collectionComponentType = (ParameterizedType)genericFieldType;
outCollectionComponentClass = ReflectionUtils.classOfType(collectionComponentType.getActualTypeArguments()[0]);
// If the component type is an abstract type, Object is returned
if (outCollectionComponentClass != null
&& Modifier.isAbstract(outCollectionComponentClass.getModifiers())) outCollectionComponentClass = Object.class;
// Si alguno de los componentes es una variable generica hay que ver si se puede obtener el tipo concreto a trav�s de la parametrizaci�n
if (outCollectionComponentClass == null && collectionComponentType.getActualTypeArguments()[0] instanceof TypeVariable) {
TypeVariable<? extends Class<?>> typeVar = (TypeVariable<? extends Class<?>>)collectionComponentType.getActualTypeArguments()[0];
outCollectionComponentClass = _collectionComponentType(type,
typeVar);
}
}
return outCollectionComponentClass;
}
示例7: getTypeParameter
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public static Class<?> getTypeParameter(final Class<?> clazz, final Class<?> genericInterface,
final int parameterIndex) {
final Type baseType = GenericTypeReflector.getExactSuperType(clazz, genericInterface);
final ParameterizedType pBaseType = (ParameterizedType) baseType;
final Type typeParameterForBaseInterface = pBaseType.getActualTypeArguments()[parameterIndex];
return getSafeClassToUse(typeParameterForBaseInterface);
}
示例8: getSuperClass
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public GenericClass getSuperClass() {
return new GenericClass(
GenericTypeReflector.getExactSuperType(type, rawClass.getSuperclass()));
}
示例9: getTypeParameter
import com.googlecode.gentyref.GenericTypeReflector; //导入方法依赖的package包/类
public static Class<?> getTypeParameter(Class<?> clazz, Class<?> genericInterface, int parameterIndex) {
Type baseType = GenericTypeReflector.getExactSuperType(clazz, genericInterface);
ParameterizedType pBaseType = (ParameterizedType) baseType;
Type typeParameterForBaseInterface = pBaseType.getActualTypeArguments()[parameterIndex];
return getSafeClassToUse(typeParameterForBaseInterface);
}