use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class OldGenericTypesTest method testInnerClassTest.
@SuppressWarnings("unchecked")
public void testInnerClassTest() throws Exception {
Class<? extends InnerClassTest> clazz = InnerClassTest.class;
TypeVariable<Class> typeVariable = getTypeParameter(clazz);
Class<?>[] declaredClasses = clazz.getDeclaredClasses();
assertLenghtOne(declaredClasses);
Class<?> innerClazz = declaredClasses[0];
assertEquals(InnerClassTest.InnerClass.class, innerClazz);
//constructor
Constructor<?>[] declaredConstructors = innerClazz.getDeclaredConstructors();
assertLenghtOne(declaredConstructors);
Constructor<?> declaredConstructor = declaredConstructors[0];
Type[] genericParameterTypes = declaredConstructor.getGenericParameterTypes();
assertLenghtOne(genericParameterTypes);
assertEquals(typeVariable, genericParameterTypes[0]);
assertInstanceOf(TypeVariable.class, genericParameterTypes[0]);
TypeVariable<?> constructorTypeVariable = (TypeVariable<?>) genericParameterTypes[0];
assertEquals(clazz, constructorTypeVariable.getGenericDeclaration());
//method
Method declaredMethods = innerClazz.getDeclaredMethod("innerMethod", Object.class);
Type[] methodParameterTypes = declaredMethods.getGenericParameterTypes();
assertLenghtOne(methodParameterTypes);
assertEquals(typeVariable, methodParameterTypes[0]);
assertInstanceOf(TypeVariable.class, methodParameterTypes[0]);
TypeVariable<?> methodTypeVariable = (TypeVariable<?>) methodParameterTypes[0];
assertEquals(clazz, methodTypeVariable.getGenericDeclaration());
}
use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class OldGenericTypesTest method testSimpleInheritance.
@SuppressWarnings("unchecked")
public void testSimpleInheritance() throws Exception {
Class<? extends SimpleInheritance> clazz = SimpleInheritance.class;
TypeVariable<Class> subTypeVariable = getTypeParameter(clazz);
assertInstanceOf(ParameterizedType.class, clazz.getGenericSuperclass());
ParameterizedType parameterizedSuperType = (ParameterizedType) clazz.getGenericSuperclass();
assertInstanceOf(Class.class, parameterizedSuperType.getRawType());
TypeVariable<Class> superTypeParameter = getTypeParameter((Class<?>) parameterizedSuperType.getRawType());
TypeVariable<Class> typeParameter = getTypeParameter(GenericType.class);
assertEquals(superTypeParameter, typeParameter);
assertNotEquals(subTypeVariable, superTypeParameter);
Type[] actualTypeArguments = parameterizedSuperType.getActualTypeArguments();
assertLenghtOne(actualTypeArguments);
assertInstanceOf(TypeVariable.class, actualTypeArguments[0]);
TypeVariable actualSuperTypeVariable = (TypeVariable) actualTypeArguments[0];
assertEquals(subTypeVariable, actualSuperTypeVariable);
}
use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class GenericExceptionsTest method testThrowingMethodThrowsEverything.
public void testThrowingMethodThrowsEverything() throws Exception {
Method method = ThrowerT.class.getMethod("throwsEverything");
Type[] exceptions = method.getGenericExceptionTypes();
TypeVariable t = (TypeVariable) exceptions[0];
assertEquals(3, exceptions.length);
assertEquals("T", t.getName());
assertEquals(Arrays.<Type>asList(Throwable.class), Arrays.asList(t.getBounds()));
assertEquals(Exception.class, exceptions[1]);
TypeVariable x = (TypeVariable) exceptions[2];
assertEquals("X", x.getName());
assertEquals(Arrays.<Type>asList(Exception.class), Arrays.asList(x.getBounds()));
}
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()));
}
Aggregations