ProgramRegistry implements TypeRegistry { @Nonnull @Override public PDescriptorProvider getProvider(String typeName, String programContext, Map<String, String> annotations) { return handle(typeName, programContext, false, r -> r.getProvider(typeName, programContext, annotations)); } ProgramRegistry(); @Nonnull ProgramTypeRegistry registryForPath(String path); @Nonnull Collection<ProgramTypeRegistry> getLoadedRegistries(); boolean containsProgramPath(String path); void putProgram(String path, CProgram program); void putProgramType(String path, ProgramType program); @Nonnull @Override T getDeclaredType(@Nonnull String typeName,
                                                                @Nonnull String programContext); @Nullable @Override T getConstantValue(@Nonnull String constReference, @Nonnull String programContext); @Nonnull @Override PService getService(String serviceName, String programContext); @Nonnull @Override PDescriptorProvider getProvider(String typeName, String programContext, Map<String, String> annotations); @Nonnull @Override PServiceProvider getServiceProvider(String serviceName, String programContext);  }
@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())); }
@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)); }
@Test public void testGetProvider_list() { PDescriptorProvider p1 = registry.getProvider("list<I>", "number", null); assertThat(p1.descriptor().getType(), is(PType.LIST)); PList list = (PList) p1.descriptor(); assertThat(list.itemDescriptor().getQualifiedName(), is(Imaginary.kDescriptor.getQualifiedName())); }
@Test public void testGetProvider_bad() { try { registry.getProvider("map<real>", "calculator", null); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid map generic part \"map<real>\": missing ',' kv separator")); } try { registry.getProvider("map<real,real,number.I>", "calculator", null); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid map generic part \"map<real,real,number.I>\": " + "Invalid atomic type name real,number.I")); } try { registry.getProvider("set<real,number.I>", "calculator", null); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid set generic part \"set<real,number.I>\": " + "Invalid atomic type name real,number.I")); } try { registry.getProvider("list<real,number.I>", "calculator", null); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid list generic part \"list<real,number.I>\": " + "Invalid atomic type name real,number.I")); } }