Search in sources :

Example 1 with EnumSymbolDeclarationContext

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;
}
Also used : EnumSymbolDeclarationContext(com.linkedin.data.grammar.PdlParser.EnumSymbolDeclarationContext) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) PropDeclarationContext(com.linkedin.data.grammar.PdlParser.PropDeclarationContext) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Name(com.linkedin.data.schema.Name) DataMap(com.linkedin.data.DataMap)

Aggregations

DataMap (com.linkedin.data.DataMap)1 EnumSymbolDeclarationContext (com.linkedin.data.grammar.PdlParser.EnumSymbolDeclarationContext)1 PropDeclarationContext (com.linkedin.data.grammar.PdlParser.PropDeclarationContext)1 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)1 Name (com.linkedin.data.schema.Name)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1