use of com.linkedin.data.grammar.PdlParser.EnumSymbolDeclarationContext in project rest.li by linkedin.
the class PdlSchemaParser method parseEnum.
private EnumDataSchema parseEnum(NamedTypeDeclarationContext context, EnumDeclarationContext enumDecl) throws ParseException {
Name name = toName(enumDecl.name);
EnumDataSchema schema = new EnumDataSchema(name);
// This is useful to set the doc and the aliases, but the properties are overwritten later (see below)
Map<String, Object> props = setDocAndProperties(context, schema);
bindNameToSchema(name, schema.getAliases(), schema);
List<EnumSymbolDeclarationContext> symbolDecls = enumDecl.enumDecl.symbolDecls;
List<String> symbols = new ArrayList<>(symbolDecls.size());
Map<String, Object> symbolDocs = new HashMap<>();
DataMap deprecatedSymbols = new DataMap();
DataMap symbolProperties = new DataMap();
for (EnumSymbolDeclarationContext symbolDecl : symbolDecls) {
symbols.add(symbolDecl.symbol.value);
recordLocation(symbolDecl.symbol.value, symbolDecl);
if (symbolDecl.doc != null) {
symbolDocs.put(symbolDecl.symbol.value, symbolDecl.doc.value);
}
for (PropDeclarationContext prop : symbolDecl.props) {
String symbol = symbolDecl.symbol.value;
Object value = parsePropValue(prop);
if (equalsSingleSegmentProperty(prop, DataSchemaConstants.DEPRECATED_KEY)) {
deprecatedSymbols.put(symbol, value);
} else {
List<String> path = new ArrayList<>(prop.path.size() + 1);
path.add(symbol);
path.addAll(prop.path);
addPropertiesAtPath(prop, symbolProperties, path, value);
}
}
}
schema.setSymbols(symbols, errorMessageBuilder());
if (!symbolDocs.isEmpty()) {
schema.setSymbolDocs(symbolDocs, errorMessageBuilder());
}
if (!deprecatedSymbols.isEmpty()) {
props.put(DataSchemaConstants.DEPRECATED_SYMBOLS_KEY, deprecatedSymbols);
}
if (!symbolProperties.isEmpty()) {
props.put(DataSchemaConstants.SYMBOL_PROPERTIES_KEY, symbolProperties);
}
// Overwrite the properties now that we've computed the special symbol properties
schema.setProperties(props);
return schema;
}
Aggregations