use of com.github.davidmoten.odata.client.generator.model.ComplexType in project odata-client by davidmoten.
the class Generator method writeComplexType.
private void writeComplexType(Schema schema, TComplexType complexType) {
ComplexType t = new ComplexType(complexType, names);
t.getDirectoryComplexType().mkdirs();
String simpleClassName = t.getSimpleClassName();
Imports imports = new Imports(t.getFullClassName());
Indent indent = new Indent();
StringWriter w = new StringWriter();
try (PrintWriter p = new PrintWriter(w)) {
p.format("package %s;\n\n", t.getPackage());
p.format(IMPORTSHERE);
t.printJavadoc(p, indent);
printPropertyOrder(imports, p, t.getProperties());
printJsonIncludesNonNull(indent, imports, p);
p.format("public class %s%s implements %s {\n", simpleClassName, t.getExtendsClause(imports), imports.add(ODataType.class));
indent.right();
if (!t.hasBaseType()) {
addContextPathInjectableField(imports, indent, p);
}
if (!t.hasBaseType()) {
addUnmappedFieldsField(imports, indent, p);
}
// write fields from properties
printPropertyFields(imports, indent, p, t.getProperties(), t.hasBaseType());
// write constructor
writeNoArgsConstructor(simpleClassName, indent, p, t.hasBaseType());
p.format("\n%s@%s\n", indent, imports.add(Override.class));
p.format("%spublic String odataTypeName() {\n", indent);
p.format("%sreturn \"%s\";\n", indent.right(), t.getFullType());
p.format("%s}\n", indent.left());
Set<String> methodNames = new HashSet<>();
printPropertyGetterAndSetters(t, imports, indent, p, simpleClassName, t.getFullType(), t.getProperties(), false, methodNames);
addUnmappedFieldsSetterAndGetter(imports, indent, p, methodNames);
p.format("\n%s@%s\n", indent, imports.add(Override.class));
p.format("%spublic void postInject(boolean addKeysToContextPath) {\n", indent);
p.format("%s// do nothing;\n", indent.right());
p.format("%s}\n", indent.left());
writeBuilder(t, simpleClassName, imports, indent, p);
// write copy method
writeCopyMethod(t, simpleClassName, imports, indent, p, false);
// write toString
writeToString(t, simpleClassName, imports, indent, p);
p.format("\n}\n");
writeToFile(imports, w, t.getClassFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations