use of org.spongepowered.api.CatalogType in project SpongeCommon by SpongePowered.
the class SpongeArgumentType method getConverter.
@SuppressWarnings("unchecked")
static <T> Function<String, T> getConverter(final Class<T> type, String converterKey) {
if (!converters.containsKey(converterKey)) {
try {
final Method valueOf = type.getMethod("valueOf", String.class);
converters.put(converterKey, SpongeSelectorFactory.<String, T>methodAsFunction(valueOf, true));
} catch (NoSuchMethodException ignored) {
if (CatalogType.class.isAssignableFrom(type)) {
final Class<? extends CatalogType> type2 = type.asSubclass(CatalogType.class);
converters.put(converterKey, (Function<String, T>) input -> {
return (T) SpongeImpl.getGame().getRegistry().getType(type2, input).get();
});
} else {
throw new IllegalStateException("can't convert " + type);
}
} catch (SecurityException e) {
SpongeImpl.getLogger().catching(e);
}
}
return (Function<String, T>) converters.get(converterKey);
}
use of org.spongepowered.api.CatalogType in project SpongeCommon by SpongePowered.
the class CatalogTypeClassesTest method testCatalogCanBeRetrieved.
@Test
public void testCatalogCanBeRetrieved() throws Exception {
assumeFalse(this.isDummy);
final CatalogType o = (CatalogType) this.targetedField.get(null);
this.registryModule.getById(o.getId()).orElseThrow(() -> new RegistryException("Could not locate " + this.fieldName + " in the registry: " + this.registryModule));
}
use of org.spongepowered.api.CatalogType in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateCatalogContainerTestObjects.
static Iterable<Object[]> generateCatalogContainerTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> objects = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
final Class<? extends CatalogType> key = entry.getKey();
final CatalogedBy catalogedBy = key.getAnnotation(CatalogedBy.class);
if (catalogedBy != null) {
for (Class<?> containerClass : catalogedBy.value()) {
for (Field field : containerClass.getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
objects.add(new Object[] { field.getName(), entry.getKey(), containerClass, entry.getValue(), field });
}
}
}
}
}
return objects;
}
use of org.spongepowered.api.CatalogType in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateRegistryTestObjects.
static Iterable<Object[]> generateRegistryTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> array = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
for (CatalogType catalogType : entry.getValue().getAll()) {
array.add(new Object[] { entry.getKey().getSimpleName(), entry.getKey(), entry.getValue(), catalogType, catalogType.getId() });
}
}
return array;
}
use of org.spongepowered.api.CatalogType in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateCatalogTypeMethodTestObjects.
static Iterable<Object[]> generateCatalogTypeMethodTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> array = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
for (CatalogType catalogType : entry.getValue().getAll()) {
for (Method method : getTestableApiMethods(getApplicableApiCatalogTypeInterfaces(catalogType))) {
array.add(new Object[] { entry.getKey().getSimpleName(), entry.getKey(), catalogType, catalogType.getId(), method, method.getDeclaringClass().getSimpleName() + "#" + method.getName() + "()", catalogType.getClass().getName() });
}
}
}
return array;
}
Aggregations