@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)); }
@Nonnull @Override @SuppressWarnings("unchecked") public PDescriptorProvider getProvider(@Nonnull String name, @Nonnull final String context, @Nullable Map<String, String> annotations) { name = finalTypename(name, context); PPrimitive primitive = PPrimitive.findByName(name); if (primitive != null) { return primitive.provider(); } if (annotations == null) { annotations = Collections.EMPTY_MAP; } if (name.startsWith("map<") && name.endsWith(">")) { String[] parts = name.substring(4, name.length() - 1) .split(",", 2); String keyType = parts[0]; String valueType = parts[1]; switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PMap.sortedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case ORDERED: return PMap.orderedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case DEFAULT: return PMap.provider(getProvider(keyType, context, null), getProvider(valueType, context, null)); } } if (name.startsWith("set<") && name.endsWith(">")) { String itemType = name.substring(4, name.length() - 1); switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PSet.sortedProvider(getProvider(itemType, context, null)); case ORDERED: return PSet.orderedProvider(getProvider(itemType, context, null)); case DEFAULT: return PSet.provider(getProvider(itemType, context, null)); } } if (name.startsWith("list<") && name.endsWith(">")) { String itemType = name.substring(5, name.length() - 1); return PList.provider(getProvider(itemType, context, null)); } final String finalName = name; return () -> getDeclaredType(finalName, context); }
BaseTypeRegistry implements WritableTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public PDescriptorProvider getProvider(@Nonnull String name, @Nonnull final String context, @Nullable Map<String, String> annotations) { name = finalTypename(name, context); PPrimitive primitive = PPrimitive.findByName(name); if (primitive != null) { return primitive.provider(); } if (annotations == null) { annotations = Collections.EMPTY_MAP; } if (name.startsWith("map<") && name.endsWith(">")) { String[] parts = name.substring(4, name.length() - 1) .split(",", 2); String keyType = parts[0]; String valueType = parts[1]; switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PMap.sortedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case ORDERED: return PMap.orderedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case DEFAULT: return PMap.provider(getProvider(keyType, context, null), getProvider(valueType, context, null)); } } if (name.startsWith("set<") && name.endsWith(">")) { String itemType = name.substring(4, name.length() - 1); switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PSet.sortedProvider(getProvider(itemType, context, null)); case ORDERED: return PSet.orderedProvider(getProvider(itemType, context, null)); case DEFAULT: return PSet.provider(getProvider(itemType, context, null)); } } if (name.startsWith("list<") && name.endsWith(">")) { String itemType = name.substring(5, name.length() - 1); return PList.provider(getProvider(itemType, context, null)); } final String finalName = name; return () -> getDeclaredType(finalName, context); } }
BaseTypeRegistry implements WritableTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public PDescriptorProvider getProvider(@Nonnull String name, @Nonnull final String context, @Nullable Map<String, String> annotations) { name = finalTypename(name, context); PPrimitive primitive = PPrimitive.findByName(name); if (primitive != null) { return primitive.provider(); } if (annotations == null) { annotations = Collections.EMPTY_MAP; } if (name.startsWith("map<") && name.endsWith(">")) { String[] parts = name.substring(4, name.length() - 1) .split(",", 2); String keyType = parts[0]; String valueType = parts[1]; switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PMap.sortedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case ORDERED: return PMap.orderedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case DEFAULT: return PMap.provider(getProvider(keyType, context, null), getProvider(valueType, context, null)); } } if (name.startsWith("set<") && name.endsWith(">")) { String itemType = name.substring(4, name.length() - 1); switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PSet.sortedProvider(getProvider(itemType, context, null)); case ORDERED: return PSet.orderedProvider(getProvider(itemType, context, null)); case DEFAULT: return PSet.provider(getProvider(itemType, context, null)); } } if (name.startsWith("list<") && name.endsWith(">")) { String itemType = name.substring(5, name.length() - 1); return PList.provider(getProvider(itemType, context, null)); } final String finalName = name; return () -> getDeclaredType(finalName, context); } protected  BaseTypeRegistry(); }
BaseTypeRegistry implements WritableTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public PDescriptorProvider getProvider(@Nonnull String name, @Nonnull final String context, @Nullable Map<String, String> annotations) { name = finalTypename(name, context); PPrimitive primitive = PPrimitive.findByName(name); if (primitive != null) { return primitive.provider(); } if (annotations == null) { annotations = Collections.EMPTY_MAP; } if (name.startsWith("map<") && name.endsWith(">")) { String[] parts = name.substring(4, name.length() - 1) .split(",", 2); String keyType = parts[0]; String valueType = parts[1]; switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PMap.sortedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case ORDERED: return PMap.orderedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case DEFAULT: return PMap.provider(getProvider(keyType, context, null), getProvider(valueType, context, null)); } } if (name.startsWith("set<") && name.endsWith(">")) { String itemType = name.substring(4, name.length() - 1); switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PSet.sortedProvider(getProvider(itemType, context, null)); case ORDERED: return PSet.orderedProvider(getProvider(itemType, context, null)); case DEFAULT: return PSet.provider(getProvider(itemType, context, null)); } } if (name.startsWith("list<") && name.endsWith(">")) { String itemType = name.substring(5, name.length() - 1); return PList.provider(getProvider(itemType, context, null)); } final String finalName = name; return () -> getDeclaredType(finalName, context); } protected  BaseTypeRegistry(); @Override void registerTypedef(@Nonnull String identifier,
                                @Nonnull String program,
                                @Nonnull String target); @Nonnull @Override @SuppressWarnings("unchecked") PDescriptorProvider getProvider(@Nonnull String name,
                                           @Nonnull final String context,
                                           @Nullable Map<String, String> annotations); @Nonnull @Override PServiceProvider getServiceProvider(final String serviceName, final String programContext); @Override void registerRecursively(@Nonnull PService service); @Override void registerRecursively(PDeclaredDescriptor<T> declaredType); }
BaseTypeRegistry implements WritableTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public PDescriptorProvider getProvider(@Nonnull String name, @Nonnull final String context, @Nullable Map<String, String> annotations) { name = finalTypename(name, context); PPrimitive primitive = PPrimitive.findByName(name); if (primitive != null) { return primitive.provider(); } if (annotations == null) { annotations = Collections.EMPTY_MAP; } if (name.startsWith("map<") && name.endsWith(">")) { String[] parts = name.substring(4, name.length() - 1) .split(",", 2); String keyType = parts[0]; String valueType = parts[1]; switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PMap.sortedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case ORDERED: return PMap.orderedProvider(getProvider(keyType, context, null), getProvider(valueType, context, null)); case DEFAULT: return PMap.provider(getProvider(keyType, context, null), getProvider(valueType, context, null)); } } if (name.startsWith("set<") && name.endsWith(">")) { String itemType = name.substring(4, name.length() - 1); switch (ThriftContainer.forName(annotations.get(ThriftAnnotation.CONTAINER.tag))) { case SORTED: return PSet.sortedProvider(getProvider(itemType, context, null)); case ORDERED: return PSet.orderedProvider(getProvider(itemType, context, null)); case DEFAULT: return PSet.provider(getProvider(itemType, context, null)); } } if (name.startsWith("list<") && name.endsWith(">")) { String itemType = name.substring(5, name.length() - 1); return PList.provider(getProvider(itemType, context, null)); } final String finalName = name; return () -> getDeclaredType(finalName, context); } protected  BaseTypeRegistry(); @Override void registerTypedef(@Nonnull String identifier,
                                @Nonnull String program,
                                @Nonnull String target); @Nonnull @Override @SuppressWarnings("unchecked") PDescriptorProvider getProvider(@Nonnull String name,
                                           @Nonnull final String context,
                                           @Nullable Map<String, String> annotations); @Nonnull @Override PServiceProvider getServiceProvider(final String serviceName, final String programContext); @Override void registerRecursively(@Nonnull PService service); @Override void registerRecursively(PDeclaredDescriptor<T> declaredType);  }