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;
}
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;
}
Aggregations