use of org.terasology.persistence.typeHandling.TypeHandlerFactory in project Terasology by MovingBlocks.
the class AssetTypeHandlerFactoryTest method testCreate.
@Test
public void testCreate() {
TypeHandlerFactory factory = new AssetTypeHandlerFactory();
List<TypeInfo<? extends Asset>> typesToTest = Lists.newArrayList(TypeInfo.of(Texture.class), TypeInfo.of(UIElement.class), TypeInfo.of(StaticSound.class), TypeInfo.of(StreamingSound.class));
for (TypeInfo<? extends Asset> typeInfo : typesToTest) {
Optional<? extends TypeHandler<? extends Asset>> typeHandler = factory.create(typeInfo, null);
assertTrue(typeHandler.isPresent());
assertTrue(typeHandler.get() instanceof AssetTypeHandler);
}
}
use of org.terasology.persistence.typeHandling.TypeHandlerFactory in project Terasology by MovingBlocks.
the class EnvironmentSwitchHandler method registerTypeHandlers.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void registerTypeHandlers(Context context, TypeHandlerLibrary library, ModuleEnvironment environment) {
for (Class<? extends TypeHandler> handler : environment.getSubtypesOf(TypeHandler.class)) {
RegisterTypeHandler register = handler.getAnnotation(RegisterTypeHandler.class);
if (register != null) {
Optional<Type> opt = GenericsUtil.getTypeParameterBindingForInheritedClass(handler, TypeHandler.class, 0);
if (opt.isPresent()) {
TypeHandler instance = InjectionHelper.createWithConstructorInjection(handler, context);
InjectionHelper.inject(instance, context);
library.addTypeHandler(TypeInfo.of(opt.get()), instance);
}
}
}
for (Class<? extends TypeHandlerFactory> clazz : environment.getSubtypesOf(TypeHandlerFactory.class)) {
if (!clazz.isAnnotationPresent(RegisterTypeHandlerFactory.class)) {
continue;
}
TypeHandlerFactory instance = InjectionHelper.createWithConstructorInjection(clazz, context);
InjectionHelper.inject(instance, context);
library.addTypeHandlerFactory(instance);
}
}
Aggregations