Search in sources :

Example 1 with MapTemplateSpec

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

the class TemplateSpecGenerator method generateMap.

private MapTemplateSpec generateMap(MapDataSchema schema, ClassTemplateSpec enclosingClass, String memberName) {
    final DataSchema valueSchema = schema.getValues();
    final ClassInfo classInfo = classInfoForUnnamed(enclosingClass, memberName, schema);
    if (classInfo.existingClass != null) {
        /* When type refs are used as item types inside some unnamed complex schemas like map and array,
       * the type refs are de-referenced and the underlying real type is used in the generated class.
       * In those cases the type refs are not processed by the class generation logic, an explicit
       * schema processing is necessary in order to processSchema the data template classes for those type
       * refs.
       */
        processSchema(valueSchema, enclosingClass, memberName);
        return (MapTemplateSpec) classInfo.existingClass;
    }
    final MapTemplateSpec mapClass = (MapTemplateSpec) classInfo.definedClass;
    registerClassTemplateSpec(schema, mapClass);
    mapClass.setValueClass(processSchema(valueSchema, enclosingClass, memberName));
    mapClass.setValueDataClass(determineDataClass(valueSchema, enclosingClass, memberName));
    final CustomInfoSpec customInfo = getImmediateCustomInfo(valueSchema);
    mapClass.setCustomInfo(customInfo);
    return mapClass;
}
Also used : FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ComplexDataSchema(com.linkedin.data.schema.ComplexDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) CustomInfoSpec(com.linkedin.pegasus.generator.spec.CustomInfoSpec) MapTemplateSpec(com.linkedin.pegasus.generator.spec.MapTemplateSpec)

Example 2 with MapTemplateSpec

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

the class JavaDataTemplateGenerator method defineClass.

private JDefinedClass defineClass(ClassTemplateSpec classTemplateSpec) throws JClassAlreadyExistsException {
    JDefinedClass result = _definedClasses.get(classTemplateSpec);
    if (result == null) {
        final int jmodValue = getJModValue(classTemplateSpec.getModifiers());
        final JClassContainer container;
        if (classTemplateSpec.getEnclosingClass() == null) {
            container = getPackage(classTemplateSpec.getPackage());
        } else {
            container = defineClass(classTemplateSpec.getEnclosingClass());
        }
        if (classTemplateSpec instanceof ArrayTemplateSpec || classTemplateSpec instanceof FixedTemplateSpec || classTemplateSpec instanceof MapTemplateSpec || classTemplateSpec instanceof RecordTemplateSpec || classTemplateSpec instanceof TyperefTemplateSpec || classTemplateSpec instanceof UnionTemplateSpec) {
            result = container._class(jmodValue, escapeReserved(classTemplateSpec.getClassName()));
        } else if (classTemplateSpec instanceof EnumTemplateSpec) {
            result = container._class(jmodValue, escapeReserved(classTemplateSpec.getClassName()), ClassType.ENUM);
        } else {
            throw new RuntimeException();
        }
        _definedClasses.put(classTemplateSpec, result);
    }
    return result;
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) FixedTemplateSpec(com.linkedin.pegasus.generator.spec.FixedTemplateSpec) MapTemplateSpec(com.linkedin.pegasus.generator.spec.MapTemplateSpec) EnumTemplateSpec(com.linkedin.pegasus.generator.spec.EnumTemplateSpec) TyperefTemplateSpec(com.linkedin.pegasus.generator.spec.TyperefTemplateSpec) UnionTemplateSpec(com.linkedin.pegasus.generator.spec.UnionTemplateSpec) RecordTemplateSpec(com.linkedin.pegasus.generator.spec.RecordTemplateSpec) JClassContainer(com.sun.codemodel.JClassContainer) ArrayTemplateSpec(com.linkedin.pegasus.generator.spec.ArrayTemplateSpec)

Aggregations

MapTemplateSpec (com.linkedin.pegasus.generator.spec.MapTemplateSpec)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 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)1 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)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 RecordTemplateSpec (com.linkedin.pegasus.generator.spec.RecordTemplateSpec)1 TyperefTemplateSpec (com.linkedin.pegasus.generator.spec.TyperefTemplateSpec)1 UnionTemplateSpec (com.linkedin.pegasus.generator.spec.UnionTemplateSpec)1 JClassContainer (com.sun.codemodel.JClassContainer)1