Search in sources :

Example 1 with UnionMemberDeclarationContext

use of com.linkedin.data.grammar.PdlParser.UnionMemberDeclarationContext in project rest.li by linkedin.

the class PdlSchemaParser method parseUnion.

private UnionDataSchema parseUnion(UnionDeclarationContext union, boolean withinTypref) throws ParseException {
    UnionDataSchema schema = new UnionDataSchema();
    List<UnionMemberDeclarationContext> members = union.typeParams.members;
    List<DataSchema> types = new ArrayList<>(members.size());
    Set<DataSchema> typesDeclaredInline = new HashSet<>();
    for (UnionMemberDeclarationContext memberDecl : members) {
        TypeAssignmentContext memberType = memberDecl.member;
        DataSchema dataSchema = toDataSchema(memberType);
        if (dataSchema != null) {
            types.add(dataSchema);
            if (isDeclaredInline(memberDecl.member)) {
                typesDeclaredInline.add(dataSchema);
            }
        }
    }
    schema.setTypes(types, errorMessageBuilder());
    schema.setTypesDeclaredInline(typesDeclaredInline);
    return schema;
}
Also used : UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) TypeAssignmentContext(com.linkedin.data.grammar.PdlParser.TypeAssignmentContext) ArrayList(java.util.ArrayList) UnionMemberDeclarationContext(com.linkedin.data.grammar.PdlParser.UnionMemberDeclarationContext) HashSet(java.util.HashSet)

Aggregations

TypeAssignmentContext (com.linkedin.data.grammar.PdlParser.TypeAssignmentContext)1 UnionMemberDeclarationContext (com.linkedin.data.grammar.PdlParser.UnionMemberDeclarationContext)1 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 DataSchema (com.linkedin.data.schema.DataSchema)1 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)1 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)1 MapDataSchema (com.linkedin.data.schema.MapDataSchema)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)1 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1