use of net.morimekta.providence.descriptor.PDescriptorProvider in project providence by morimekta.
the class BaseTypeRegistryTest method testGetProvider_map.
@Test
public void testGetProvider_map() {
PDescriptorProvider p1 = registry.getProvider("map<real,I>", "number", ImmutableMap.of("container", "sorted"));
assertThat(p1.descriptor().getType(), is(PType.MAP));
PMap map = (PMap) p1.descriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.DOUBLE));
assertThat(map.itemDescriptor(), is(Imaginary.kDescriptor));
p1 = registry.getProvider("map<real,map<i32,I>>", "number", ImmutableMap.of("container", "ordered"));
assertThat(p1.descriptor().getType(), is(PType.MAP));
map = (PMap) p1.descriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.DOUBLE));
assertThat(map.itemDescriptor().getType(), is(PType.MAP));
map = (PMap) map.itemDescriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.I32));
assertThat(map.itemDescriptor(), is(Imaginary.kDescriptor));
}
use of net.morimekta.providence.descriptor.PDescriptorProvider in project providence by morimekta.
the class ProgramRegistryTest method testGetProvider_set.
@Test
public void testGetProvider_set() {
PDescriptorProvider p1 = registry.getProvider("set<I>", "number", ImmutableMap.of("container", "sorted"));
assertThat(p1.descriptor().getType(), is(PType.SET));
PSet set = (PSet) p1.descriptor();
assertThat(set.itemDescriptor().getQualifiedName(), is(Imaginary.kDescriptor.getQualifiedName()));
p1 = registry.getProvider("set<set<i32>>", "number", ImmutableMap.of("container", "ordered"));
assertThat(p1.descriptor().getType(), is(PType.SET));
set = (PSet) p1.descriptor();
assertThat(set.itemDescriptor().getType(), is(PType.SET));
PSet list = (PSet) set.itemDescriptor();
assertThat(list.itemDescriptor(), is(PPrimitive.I32));
}
use of net.morimekta.providence.descriptor.PDescriptorProvider in project providence by morimekta.
the class ProgramRegistryTest method testGetProvider_map.
@Test
public void testGetProvider_map() {
PDescriptorProvider p1 = registry.getProvider("map<real,I>", "number", ImmutableMap.of("container", "sorted"));
assertThat(p1.descriptor().getType(), is(PType.MAP));
PMap map = (PMap) p1.descriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.DOUBLE));
assertThat(map.itemDescriptor().getQualifiedName(), is(Imaginary.kDescriptor.getQualifiedName()));
p1 = registry.getProvider("map<real,map<i32,I>>", "number", ImmutableMap.of("container", "ordered"));
assertThat(p1.descriptor().getType(), is(PType.MAP));
map = (PMap) p1.descriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.DOUBLE));
assertThat(map.itemDescriptor().getType(), is(PType.MAP));
map = (PMap) map.itemDescriptor();
assertThat(map.keyDescriptor(), is(PPrimitive.I32));
assertThat(map.itemDescriptor().getQualifiedName(), is(Imaginary.kDescriptor.getQualifiedName()));
}
use of net.morimekta.providence.descriptor.PDescriptorProvider in project providence by morimekta.
the class ProgramConverter method makeConst.
private CConst makeConst(TypeRegistry registry, String pkg, ConstType field) {
PDescriptorProvider type = registry.getProvider(field.getType(), pkg, field.getAnnotations());
if (!field.hasValue()) {
throw new IllegalArgumentException("Const " + pkg + "." + field.getName() + " does not have a value.");
}
ConstProvider defaultValue = new ConstProvider(registry, field.getType(), pkg, field.getValue(), field.getStartLineNo(), field.getStartLinePos());
@SuppressWarnings("unchecked") CConst made = new CConst(field.getDocumentation(), field.getName(), type, defaultValue, field.getAnnotations());
return made;
}
use of net.morimekta.providence.descriptor.PDescriptorProvider in project providence by morimekta.
the class ProgramConverter method makeField.
private CField makeField(TypeRegistry registry, String pkg, FieldType field, MessageVariant variant) {
PDescriptorProvider type = registry.getProvider(field.getType(), pkg, field.getAnnotations());
ConstProvider defaultValue = null;
if (field.hasDefaultValue()) {
defaultValue = new ConstProvider(registry, field.getType(), pkg, field.getDefaultValue(), field.getStartLineNo(), field.getStartLinePos());
}
PRequirement requirement = PRequirement.valueOf(field.getRequirement().asString());
if (variant == MessageVariant.UNION) {
if (requirement == PRequirement.REQUIRED) {
throw new IllegalArgumentException("Required field in union");
}
requirement = PRequirement.OPTIONAL;
}
@SuppressWarnings("unchecked") CField made = new CField(field.getDocumentation(), field.getId(), requirement, field.getName(), type, defaultValue, field.getAnnotations());
return made;
}
Aggregations