Search in sources :

Example 6 with UnionTemplateSpec

use of com.linkedin.pegasus.generator.spec.UnionTemplateSpec in project rest.li by linkedin.

the class TestTemplateSpecGenerator method testCustomInfoForUnionMembers.

@Test(dataProvider = "customTypeDataForUnion")
public void testCustomInfoForUnionMembers(final List<DataSchema> customTypedSchemas) {
    final UnionDataSchema union = new UnionDataSchema();
    union.setTypes(customTypedSchemas, null);
    final TyperefDataSchema typeref = new TyperefDataSchema(new Name(INPUT_SCHEMA_NAME));
    typeref.setReferencedType(union);
    final TemplateSpecGenerator generator = new TemplateSpecGenerator(_resolver);
    final UnionTemplateSpec spec = (UnionTemplateSpec) generator.generate(typeref, _location);
    for (int i = 0; i < customTypedSchemas.size(); ++i) {
        Assert.assertNotNull(spec.getMembers().get(i).getCustomInfo());
        Assert.assertEquals(spec.getMembers().get(i).getCustomInfo().getCustomClass().getClassName(), CustomTypeUtil.getJavaCustomTypeClassNameFromSchema((TyperefDataSchema) customTypedSchemas.get(i)));
    }
}
Also used : UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) UnionTemplateSpec(com.linkedin.pegasus.generator.spec.UnionTemplateSpec) Name(com.linkedin.data.schema.Name) Test(org.testng.annotations.Test)

Example 7 with UnionTemplateSpec

use of com.linkedin.pegasus.generator.spec.UnionTemplateSpec in project rest.li by linkedin.

the class TemplateSpecGenerator method generateUnion.

private ClassTemplateSpec generateUnion(UnionDataSchema schema, TyperefDataSchema typerefDataSchema) {
    assert typerefDataSchema.getRef() == schema;
    pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(typerefDataSchema.getFullName()));
    final UnionTemplateSpec unionClass = new UnionTemplateSpec(schema);
    unionClass.setNamespace(typerefDataSchema.getNamespace());
    unionClass.setPackage(typerefDataSchema.getPackage());
    unionClass.setClassName(typerefDataSchema.getName());
    unionClass.setModifiers(ModifierSpec.PUBLIC);
    registerClassTemplateSpec(typerefDataSchema, unionClass);
    final TyperefTemplateSpec typerefInfoClass = new TyperefTemplateSpec(typerefDataSchema);
    typerefInfoClass.setEnclosingClass(unionClass);
    typerefInfoClass.setClassName("UnionTyperefInfo");
    typerefInfoClass.setModifiers(ModifierSpec.PRIVATE, ModifierSpec.STATIC, ModifierSpec.FINAL);
    final UnionTemplateSpec result = generateUnion(schema, unionClass);
    result.setTyperefClass(typerefInfoClass);
    popCurrentLocation();
    return result;
}
Also used : UnionTemplateSpec(com.linkedin.pegasus.generator.spec.UnionTemplateSpec) TyperefTemplateSpec(com.linkedin.pegasus.generator.spec.TyperefTemplateSpec)

Aggregations

UnionTemplateSpec (com.linkedin.pegasus.generator.spec.UnionTemplateSpec)7 TyperefTemplateSpec (com.linkedin.pegasus.generator.spec.TyperefTemplateSpec)3 JDefinedClass (com.sun.codemodel.JDefinedClass)3 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)2 JMethod (com.sun.codemodel.JMethod)2 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)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 Name (com.linkedin.data.schema.Name)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 ArrayTemplateSpec (com.linkedin.pegasus.generator.spec.ArrayTemplateSpec)1 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)1 EnumTemplateSpec (com.linkedin.pegasus.generator.spec.EnumTemplateSpec)1 FixedTemplateSpec (com.linkedin.pegasus.generator.spec.FixedTemplateSpec)1