本文整理汇总了Java中org.apache.commons.lang3.reflect.TypeUtils.getTypeArguments方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.getTypeArguments方法的具体用法?Java TypeUtils.getTypeArguments怎么用?Java TypeUtils.getTypeArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.TypeUtils
的用法示例。
在下文中一共展示了TypeUtils.getTypeArguments方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSignature
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
private static Signature createSignature(final Object input, final Type type, final Map<TypeVariable<?>, Type> typeArgs, final boolean isInput) {
final Class clazz = getTypeClass(type, typeArgs);
if (Tuple.class.isAssignableFrom(clazz)) {
final TypeVariable[] tupleTypes = getTypeClass(type, typeArgs).getTypeParameters();
final Map<TypeVariable<?>, Type> classTypeArgs = TypeUtils.getTypeArguments(type, clazz);
Collection<? extends Type> types = TypeUtils.getTypeArguments(type, clazz).values();
Class[] classes = new Class[types.size()];
int i = 0;
for (final TypeVariable tupleType : tupleTypes) {
classes[i++] = getTypeClass(classTypeArgs.get(tupleType), typeArgs);
}
return new TupleSignature(input, clazz, classes, isInput);
}
return new SingletonSignature(input, clazz, isInput);
}
示例2: getTypeFromExactReturnType
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的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 static Type getTypeFromExactReturnType(ParameterizedType returnType,
ParameterizedType type) {
Map<TypeVariable<?>, Type> typeMap = TypeUtils.getTypeArguments(returnType);
Type[] actualParameters = new Type[type.getActualTypeArguments().length];
int num = 0;
for (TypeVariable<?> parameterType : ((Class<?>) type.getRawType()).getTypeParameters()) {
//for(Type parameterType : type.getActualTypeArguments()) {
// if(parameterType instanceof TypeVariable<?>) {
boolean replaced = false;
for (TypeVariable<?> var : typeMap.keySet()) {
// D'oh! Why the heck do we need this??
if (var.getName().equals(parameterType.getName())) {
//if(typeMap.containsKey(parameterType)) {
actualParameters[num] = typeMap.get(var);
replaced = true;
break;
//} else {
}
}
if (!replaced) {
actualParameters[num] = parameterType;
}
//}
// } else {
// LoggingUtils.getEvoLogger().info("Not a type variable "+parameterType);
// actualParameters[num] = parameterType;
// }
num++;
}
return new ParameterizedTypeImpl((Class<?>) type.getRawType(), actualParameters,
null);
}
示例3: getParameterTypesForCollection
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
public static Collection<Type> getParameterTypesForCollection(Class<?> type) {
if (isCollectionOrSequence(type)) {
Map<TypeVariable<?>, Type> m
= TypeUtils.getTypeArguments((ParameterizedType) type.getGenericSuperclass());
return m.values();
}
return null;
}
示例4: getTypeParameter
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> Class<T> getTypeParameter(Type subType, Class<?> superType, int index) {
final Map<TypeVariable<?>, Type> arguments = TypeUtils.getTypeArguments(subType, superType);
final TypeVariable<? extends Class<?>> variable = superType.getTypeParameters()[index];
return (Class<T>) arguments.get(variable);
}
示例5: getType
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
private static Class getType(final Class<? extends Operation> operation, final Class<?> objectClass) {
final TypeVariable<?> tv = objectClass.getTypeParameters()[0];
final Map<TypeVariable<?>, Type> typeArgs = TypeUtils.getTypeArguments(operation, objectClass);
final Type type = typeArgs.get(tv);
return getType(type, typeArgs);
}
示例6: createSignatureFromTypeVariable
import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
* Create a <code>Signature</code> for the type variable at the given index.
*
* @param input Function to create signature for.
* @param functionClass The input class
* @param typeVariableIndex 0 for I or 1 for O.
* @param isInput if true then it is an input signature otherwise it is an output signature
* @return Signature of the type variable.
*/
private static Signature createSignatureFromTypeVariable(final Object input, final Class functionClass, final int typeVariableIndex, final boolean isInput) {
TypeVariable<?> tv = functionClass.getTypeParameters()[typeVariableIndex];
final Map<TypeVariable<?>, Type> typeArgs = TypeUtils.getTypeArguments(input.getClass(), functionClass);
Type type = typeArgs.get(tv);
return createSignature(input, type, typeArgs, isInput);
}