use of com.linkedin.pegasus.generator.spec.CustomInfoSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generateArray.
private ArrayTemplateSpec generateArray(ArrayDataSchema schema, ClassTemplateSpec enclosingClass, String memberName) {
final DataSchema itemSchema = schema.getItems();
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(itemSchema, enclosingClass, memberName);
return (ArrayTemplateSpec) classInfo.existingClass;
}
final ArrayTemplateSpec arrayClass = (ArrayTemplateSpec) classInfo.definedClass;
registerClassTemplateSpec(schema, arrayClass);
arrayClass.setItemClass(processSchema(itemSchema, enclosingClass, memberName));
arrayClass.setItemDataClass(determineDataClass(itemSchema, enclosingClass, memberName));
final CustomInfoSpec customInfo = getImmediateCustomInfo(itemSchema);
arrayClass.setCustomInfo(customInfo);
return arrayClass;
}
use of com.linkedin.pegasus.generator.spec.CustomInfoSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generateUnion.
private UnionTemplateSpec generateUnion(UnionDataSchema schema, UnionTemplateSpec unionClass) {
final Map<CustomInfoSpec, Object> customInfoMap = new IdentityHashMap<>(schema.getMembers().size() * 2);
for (UnionDataSchema.Member member : schema.getMembers()) {
DataSchema memberType = member.getType();
final UnionTemplateSpec.Member newMember = new UnionTemplateSpec.Member();
unionClass.getMembers().add(newMember);
newMember.setSchema(memberType);
newMember.setAlias(member.getAlias());
if (memberType.getDereferencedType() != DataSchema.Type.NULL) {
newMember.setClassTemplateSpec(processSchema(memberType, unionClass, memberType.getUnionMemberKey()));
newMember.setDataClass(determineDataClass(memberType, unionClass, memberType.getUnionMemberKey()));
final CustomInfoSpec customInfo = getImmediateCustomInfo(memberType);
if (customInfo != null) {
if (!customInfoMap.containsKey(customInfo)) {
customInfoMap.put(customInfo, null);
}
newMember.setCustomInfo(customInfo);
}
}
}
return unionClass;
}
use of com.linkedin.pegasus.generator.spec.CustomInfoSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method processSchema.
private ClassTemplateSpec processSchema(DataSchema schema, ClassTemplateSpec enclosingClass, String memberName) {
final CustomInfoSpec customInfo = getImmediateCustomInfo(schema);
ClassTemplateSpec result = null;
TyperefDataSchema originalTyperefSchema = null;
while (schema.getType() == DataSchema.Type.TYPEREF) {
final TyperefDataSchema typerefSchema = (TyperefDataSchema) schema;
if (originalTyperefSchema == null) {
originalTyperefSchema = typerefSchema;
}
final ClassTemplateSpec found = _schemaToClassMap.get(schema);
schema = typerefSchema.getRef();
if (schema.getType() == DataSchema.Type.UNION) {
result = (found != null) ? found : generateUnion((UnionDataSchema) schema, typerefSchema);
break;
} else if (found == null) {
generateTyperef(typerefSchema, originalTyperefSchema);
}
}
if (result == null) {
assert schema == schema.getDereferencedDataSchema();
if (schema instanceof ComplexDataSchema) {
final ClassTemplateSpec found = _schemaToClassMap.get(schema);
if (found == null) {
if (schema instanceof NamedDataSchema) {
result = generateNamedSchema((NamedDataSchema) schema);
} else {
result = generateUnnamedComplexSchema(schema, enclosingClass, memberName);
}
} else {
result = found;
}
if (customInfo != null) {
result = customInfo.getCustomClass();
}
} else if (schema instanceof PrimitiveDataSchema) {
result = (customInfo != null) ? customInfo.getCustomClass() : getPrimitiveClassForSchema((PrimitiveDataSchema) schema, enclosingClass, memberName);
}
}
if (result == null) {
throw unrecognizedSchemaType(enclosingClass, memberName, schema);
}
result.setOriginalTyperefSchema(originalTyperefSchema);
return result;
}
use of com.linkedin.pegasus.generator.spec.CustomInfoSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method getImmediateCustomInfo.
private CustomInfoSpec getImmediateCustomInfo(DataSchema schema) {
if (_immediateCustomMap.containsKey(schema)) {
return _immediateCustomMap.get(schema);
}
CustomInfoSpec immediate = null;
for (DataSchema current = schema; current != null; current = dereferenceIfTyperef(current)) {
final CustomClasses customClasses = getCustomClasses(current);
if (customClasses != null) {
immediate = new CustomInfoSpec((NamedDataSchema) schema, (NamedDataSchema) current, customClasses.customClass, customClasses.customCoercerClass);
break;
}
}
// immediate may be null
_immediateCustomMap.put(schema, immediate);
return immediate;
}
use of com.linkedin.pegasus.generator.spec.CustomInfoSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generateTyperef.
private TyperefTemplateSpec generateTyperef(TyperefDataSchema schema, TyperefDataSchema originalTyperefSchema) {
pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(schema.getFullName()));
final TyperefTemplateSpec typerefClass = new TyperefTemplateSpec(schema);
typerefClass.setOriginalTyperefSchema(originalTyperefSchema);
typerefClass.setNamespace(schema.getNamespace());
typerefClass.setPackage(schema.getPackage());
typerefClass.setClassName(schema.getName());
typerefClass.setModifiers(ModifierSpec.PUBLIC);
registerClassTemplateSpec(schema, typerefClass);
final CustomInfoSpec customInfo = getImmediateCustomInfo(schema);
typerefClass.setCustomInfo(customInfo);
popCurrentLocation();
return typerefClass;
}
Aggregations