Search in sources :

Example 1 with PDescriptorProvider

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));
}
Also used : PMap(net.morimekta.providence.descriptor.PMap) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider) Test(org.junit.Test)

Example 2 with PDescriptorProvider

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));
}
Also used : PSet(net.morimekta.providence.descriptor.PSet) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider) Test(org.junit.Test)

Example 3 with PDescriptorProvider

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()));
}
Also used : PMap(net.morimekta.providence.descriptor.PMap) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider) Test(org.junit.Test)

Example 4 with PDescriptorProvider

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;
}
Also used : CConst(net.morimekta.providence.reflect.contained.CConst) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider)

Example 5 with PDescriptorProvider

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;
}
Also used : PRequirement(net.morimekta.providence.descriptor.PRequirement) CField(net.morimekta.providence.reflect.contained.CField) PDescriptorProvider(net.morimekta.providence.descriptor.PDescriptorProvider)

Aggregations

PDescriptorProvider (net.morimekta.providence.descriptor.PDescriptorProvider)9 Test (org.junit.Test)6 PList (net.morimekta.providence.descriptor.PList)2 PMap (net.morimekta.providence.descriptor.PMap)2 PRequirement (net.morimekta.providence.descriptor.PRequirement)2 PSet (net.morimekta.providence.descriptor.PSet)2 CConst (net.morimekta.providence.reflect.contained.CConst)2 CField (net.morimekta.providence.reflect.contained.CField)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 PDeclaredDescriptor (net.morimekta.providence.descriptor.PDeclaredDescriptor)1 PEnumDescriptor (net.morimekta.providence.descriptor.PEnumDescriptor)1 PMessageDescriptor (net.morimekta.providence.descriptor.PMessageDescriptor)1 PPrimitive (net.morimekta.providence.descriptor.PPrimitive)1