use of org.terasology.reflection.copy.CopyStrategy in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveWildcardType.
@Test
public void testResolveWildcardType() {
class SomeClass<T, U> {
private CopyStrategy<? extends T> t;
private CopyStrategy<? super U> u;
}
TypeInfo<SomeClass<Float, Integer>> typeInfo = new TypeInfo<SomeClass<Float, Integer>>() {
};
ParameterizedType resolvedFieldType = (ParameterizedType) ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
WildcardType resolvedWildcardType = (WildcardType) resolvedFieldType.getActualTypeArguments()[0];
assertEquals(Float.class, resolvedWildcardType.getUpperBounds()[0]);
resolvedFieldType = (ParameterizedType) ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[1].getGenericType());
resolvedWildcardType = (WildcardType) resolvedFieldType.getActualTypeArguments()[0];
assertEquals(Integer.class, resolvedWildcardType.getLowerBounds()[0]);
}
use of org.terasology.reflection.copy.CopyStrategy in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveParameterizedType.
@Test
public void testResolveParameterizedType() {
class SomeClass<T> {
private CopyStrategy<T> t;
}
TypeInfo<SomeClass<Float>> typeInfo = new TypeInfo<SomeClass<Float>>() {
};
Type resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
assertEquals(new TypeInfo<CopyStrategy<Float>>() {
}.getType(), resolvedFieldType);
}
use of org.terasology.reflection.copy.CopyStrategy in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testGetTypeParameterForGenericSupertypeInGenericSubclass.
@Test
public void testGetTypeParameterForGenericSupertypeInGenericSubclass() {
class SubInterface<T> implements CopyStrategy<T> {
@Override
public T copy(T value) {
return null;
}
}
class SubClass extends SubInterface<String> {
}
Type subInterfaceType = new TypeInfo<SubInterface<Integer>>() {
}.getType();
assertEquals(Integer.class, ReflectionUtil.getTypeParameterForSuper(subInterfaceType, CopyStrategy.class, 0));
Type subClassType = new TypeInfo<SubClass>() {
}.getType();
assertEquals(String.class, ReflectionUtil.getTypeParameterForSuper(subClassType, CopyStrategy.class, 0));
}
use of org.terasology.reflection.copy.CopyStrategy in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveNothing.
@Test
public void testResolveNothing() {
class SomeClass {
private CopyStrategy<Integer> t;
private String o;
}
TypeInfo<SomeClass> typeInfo = new TypeInfo<SomeClass>() {
};
Type resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
assertEquals(new TypeInfo<CopyStrategy<Integer>>() {
}.getType(), resolvedFieldType);
resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[1].getGenericType());
assertEquals(TypeInfo.of(String.class).getType(), resolvedFieldType);
}
use of org.terasology.reflection.copy.CopyStrategy in project Terasology by MovingBlocks.
the class ReflectionUtilTest method testResolveRawParameterizedType.
@Test
public void testResolveRawParameterizedType() {
class SomeClass<T> {
private CopyStrategy<T> t;
private T o;
}
TypeInfo<SomeClass> typeInfo = new TypeInfo<SomeClass>() {
};
Type resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[0].getGenericType());
assertEquals(new TypeInfo<CopyStrategy<Object>>() {
}.getType(), resolvedFieldType);
resolvedFieldType = ReflectionUtil.resolveType(typeInfo.getType(), typeInfo.getRawType().getDeclaredFields()[1].getGenericType());
assertEquals(TypeInfo.of(Object.class).getType(), resolvedFieldType);
}
Aggregations