use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class GenericExceptionsTest method testThrowingMethodTypeParameter.
public void testThrowingMethodTypeParameter() throws Exception {
Method method = ThrowerT.class.getMethod("throwsMethodTypeParameter");
TypeVariable typeVariable = getOnlyValue(method.getGenericExceptionTypes(), TypeVariable.class);
assertEquals("X", typeVariable.getName());
assertEquals(Arrays.<Type>asList(Exception.class), Arrays.asList(typeVariable.getBounds()));
}
use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class GenericExceptionsTest method testConstructorThrowingTypeVariable.
public void testConstructorThrowingTypeVariable() throws Exception {
Constructor constructor = ThrowerT.class.getConstructor();
TypeVariable typeVariable = getOnlyValue(constructor.getGenericExceptionTypes(), TypeVariable.class);
assertEquals("T", typeVariable.getName());
assertEquals(Arrays.<Type>asList(Throwable.class), Arrays.asList(typeVariable.getBounds()));
}
use of java.lang.reflect.TypeVariable in project spring-framework by spring-projects.
the class ResolvableType method forClassWithGenerics.
/**
* Return a {@link ResolvableType} for the specified {@link Class} with pre-declared generics.
* @param clazz the class (or interface) to introspect
* @param generics the generics of the class
* @return a {@link ResolvableType} for the specific class and generics
* @see #forClassWithGenerics(Class, Class...)
*/
public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType... generics) {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(generics, "Generics array must not be null");
TypeVariable<?>[] variables = clazz.getTypeParameters();
Assert.isTrue(variables.length == generics.length, "Mismatched number of generics specified");
Type[] arguments = new Type[generics.length];
for (int i = 0; i < generics.length; i++) {
ResolvableType generic = generics[i];
Type argument = (generic != null ? generic.getType() : null);
arguments[i] = (argument != null ? argument : variables[i]);
}
ParameterizedType syntheticType = new SyntheticParameterizedType(clazz, arguments);
return forType(syntheticType, new TypeVariablesVariableResolver(variables, generics));
}
use of java.lang.reflect.TypeVariable in project spring-framework by spring-projects.
the class ResolvableType method resolveVariable.
private ResolvableType resolveVariable(TypeVariable<?> variable) {
if (this.type instanceof TypeVariable) {
return resolveType().resolveVariable(variable);
}
if (this.type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) this.type;
TypeVariable<?>[] variables = resolve().getTypeParameters();
for (int i = 0; i < variables.length; i++) {
if (ObjectUtils.nullSafeEquals(variables[i].getName(), variable.getName())) {
Type actualType = parameterizedType.getActualTypeArguments()[i];
return forType(actualType, this.variableResolver);
}
}
if (parameterizedType.getOwnerType() != null) {
return forType(parameterizedType.getOwnerType(), this.variableResolver).resolveVariable(variable);
}
}
if (this.variableResolver != null) {
return this.variableResolver.resolveVariable(variable);
}
return null;
}
use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class WildcardTypeTest method checkReturnType.
@SuppressWarnings("unchecked")
private void checkReturnType(Method method) {
Type genericReturnType = method.getGenericReturnType();
assertEquals(getTypeParameter(method), genericReturnType);
assertTrue(genericReturnType instanceof TypeVariable);
TypeVariable<Method> returnTypeVariable = (TypeVariable<Method>) genericReturnType;
assertEquals(method, returnTypeVariable.getGenericDeclaration());
Type[] bounds = returnTypeVariable.getBounds();
assertLenghtOne(bounds);
Type bound = bounds[0];
assertEquals(BoundedWildcardsGenericMethods.class, bound);
}
Aggregations