use of com.linkedin.pegasus.generator.spec.TyperefTemplateSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generateTyperef.
private TyperefTemplateSpec generateTyperef(TyperefDataSchema schema, TyperefDataSchema originalTyperefSchema) {
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);
return typerefClass;
}
use of com.linkedin.pegasus.generator.spec.TyperefTemplateSpec 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;
}
use of com.linkedin.pegasus.generator.spec.TyperefTemplateSpec in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generateUnion.
protected void generateUnion(JDefinedClass unionClass, UnionTemplateSpec unionSpec) throws JClassAlreadyExistsException {
extendUnionBaseClass(unionClass);
final JVar schemaField = generateSchemaField(unionClass, unionSpec.getSchema());
generateConstructorWithNoArg(unionClass, schemaField, _dataMapClass);
generateConstructorWithObjectArg(unionClass, schemaField);
for (UnionTemplateSpec.Member member : unionSpec.getMembers()) {
if (member.getClassTemplateSpec() != null) {
generateUnionMemberAccessors(unionClass, member, generate(member.getClassTemplateSpec()), generate(member.getDataClass()), schemaField);
}
}
unionSpec.getMembers().stream().map(UnionTemplateSpec.Member::getCustomInfo).distinct().forEach(customInfo -> generateCustomClassInitialization(unionClass, customInfo));
if (_pathSpecMethods) {
generatePathSpecMethodsForUnion(unionSpec, unionClass);
}
if (_copierMethods) {
generateCopierMethods(unionClass);
}
if (unionSpec.getTyperefClass() != null) {
final TyperefTemplateSpec typerefClassSpec = unionSpec.getTyperefClass();
final JDefinedClass typerefInfoClass = unionClass._class(getJModValue(typerefClassSpec.getModifiers()), escapeReserved(typerefClassSpec.getClassName()));
generateTyperef(typerefInfoClass, typerefClassSpec);
final JFieldVar typerefInfoField = unionClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, TyperefInfo.class, DataTemplateUtil.TYPEREFINFO_FIELD_NAME);
typerefInfoField.init(JExpr._new(typerefInfoClass));
unionClass._implements(HasTyperefInfo.class);
final JMethod typerefInfoMethod = unionClass.method(JMod.PUBLIC, TyperefInfo.class, "typerefInfo");
typerefInfoMethod.body()._return(typerefInfoField);
}
}
use of com.linkedin.pegasus.generator.spec.TyperefTemplateSpec 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;
}
Aggregations