use of org.terasology.persistence.typeHandling.coreTypes.ArrayTypeHandler in project Terasology by MovingBlocks.
the class ArrayTypeHandlerFactory method create.
@Override
public <T> Optional<TypeHandler<T>> create(TypeInfo<T> typeInfo, TypeHandlerContext context) {
Type type = typeInfo.getType();
if (!(type instanceof GenericArrayType || type instanceof Class && ((Class<?>) type).isArray())) {
return Optional.empty();
}
Type elementType = type instanceof GenericArrayType ? ((GenericArrayType) type).getGenericComponentType() : ((Class<?>) type).getComponentType();
TypeInfo<?> elementTypeInfo = TypeInfo.of(elementType);
Optional<TypeHandler<?>> declaredElementTypeHandler = context.getTypeHandlerLibrary().getTypeHandler(elementType);
@SuppressWarnings("unchecked") TypeHandler<?> elementTypeHandler = new RuntimeDelegatingTypeHandler(declaredElementTypeHandler.orElse(null), elementTypeInfo, context);
@SuppressWarnings("unchecked") TypeHandler<T> typeHandler = new ArrayTypeHandler(elementTypeHandler, elementTypeInfo);
return Optional.of(typeHandler);
}
Aggregations