use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class OldGenericReflectionCornerCases method testMultipleBoundedWildcard.
@SuppressWarnings("unchecked")
public void testMultipleBoundedWildcard() throws Exception {
Class<? extends MultipleBoundedWildcardEquality> clazz = MultipleBoundedWildcardEquality.class;
Method method = clazz.getDeclaredMethod("multipleBoundedWildcardEquality", Pair.class);
TypeVariable<?>[] typeParameters = clazz.getTypeParameters();
assertLenghtOne(typeParameters);
TypeVariable<?> typeParameter = typeParameters[0];
Type[] typeParameterBounds = typeParameter.getBounds();
assertEquals(2, typeParameterBounds.length);
assertEquals(Object.class, typeParameterBounds[0]);
assertInstanceOf(ParameterizedType.class, typeParameterBounds[1]);
ParameterizedType parameterizedType = (ParameterizedType) typeParameterBounds[1];
assertEquals(Comparable.class, parameterizedType.getRawType());
Type[] typeArguments = parameterizedType.getActualTypeArguments();
assertLenghtOne(typeArguments);
assertInstanceOf(ParameterizedType.class, typeArguments[0]);
ParameterizedType type = (ParameterizedType) typeArguments[0];
assertEquals(typeParameter, type.getActualTypeArguments()[0]);
assertEquals(MultipleBoundedWildcardEquality.class, type.getRawType());
Type[] parameterTypes = method.getGenericParameterTypes();
assertLenghtOne(parameterTypes);
Type parameter = parameterTypes[0];
assertInstanceOf(ParameterizedType.class, parameter);
ParameterizedType paramType = (ParameterizedType) parameter;
Type[] actualTypeArguments = paramType.getActualTypeArguments();
assertEquals(2, actualTypeArguments.length);
Type firstArgument = actualTypeArguments[0];
assertInstanceOf(WildcardType.class, firstArgument);
WildcardType firstWildcardArgument = (WildcardType) firstArgument;
Type secondArgument = actualTypeArguments[1];
assertInstanceOf(WildcardType.class, secondArgument);
WildcardType secondWildcardArgument = (WildcardType) secondArgument;
assertEquals(firstWildcardArgument, secondWildcardArgument);
Type[] firstWildcardArgumentUpperBounds = firstWildcardArgument.getUpperBounds();
assertLenghtOne(firstWildcardArgumentUpperBounds);
Type firstWildcardArgumentUpperBoundsType = firstWildcardArgumentUpperBounds[0];
Type[] secondWildcardArgumentUpperBounds = secondWildcardArgument.getUpperBounds();
assertLenghtOne(secondWildcardArgumentUpperBounds);
Type secondWildcardArgumentLoweroundsType = secondWildcardArgumentUpperBounds[0];
assertEquals(firstWildcardArgumentUpperBoundsType, secondWildcardArgumentLoweroundsType);
}
use of java.lang.reflect.TypeVariable in project robovm by robovm.
the class OldGenericTypesTest method testMultipleGenericTypes.
@SuppressWarnings("unchecked")
public void testMultipleGenericTypes() throws Exception {
//Type parameters
Class<? extends MultipleGenericTypes> clazz = MultipleGenericTypes.class;
TypeVariable<?>[] typeParameters = clazz.getTypeParameters();
assertEquals(2, typeParameters.length);
TypeVariable<?> typeVariableT = typeParameters[0];
assertEquals(clazz, typeVariableT.getGenericDeclaration());
assertEquals("T", typeVariableT.getName());
TypeVariable<?> typeVariableS = typeParameters[1];
assertEquals("S", typeVariableS.getName());
assertEquals(clazz, typeVariableS.getGenericDeclaration());
// multipleGenericTypesT
Method multipleGenericTypesT = clazz.getDeclaredMethod("multipleGenericTypesT", new Class[] { Object.class });
Type[] multipleGenericTypesTTypes = multipleGenericTypesT.getGenericParameterTypes();
assertLenghtOne(multipleGenericTypesTTypes);
Type multipleGenericTypesTType = multipleGenericTypesTTypes[0];
assertEquals(typeVariableT, multipleGenericTypesTType);
// multipleGenericTypesS
Method multipleGenericTypesS = clazz.getDeclaredMethod("multipleGenericTypesS", new Class[] { Object.class });
Type[] multipleGenericTypesSTypes = multipleGenericTypesS.getGenericParameterTypes();
assertLenghtOne(multipleGenericTypesSTypes);
Type multipleGenericTypesSType = multipleGenericTypesSTypes[0];
assertEquals(typeVariableS, multipleGenericTypesSType);
// multipleGenericTypesS
Method multipleGenericTypesTS = clazz.getDeclaredMethod("multipleGenericTypesTS", new Class[] { Object.class, Object.class });
Type[] multipleGenericTypesTSTypes = multipleGenericTypesTS.getGenericParameterTypes();
assertEquals(2, multipleGenericTypesTSTypes.length);
Type multipleGenericTypesTSTypeT = multipleGenericTypesTSTypes[0];
assertEquals(typeVariableT, multipleGenericTypesTSTypeT);
Type multipleGenericTypesTSTypeS = multipleGenericTypesTSTypes[1];
assertEquals(typeVariableS, multipleGenericTypesTSTypeS);
}
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()));
}
Aggregations