PropertyListM properties, BuildMethodM buildMethod, FactoryMethodM factoryMethod,
CopyMethodM copyMethodM, ValidatorM validator, TypeM optionalType) throws IOException {
properties = new PropertyListM(properties);
properties.filterOutNonWritableProperties(builderType);
ImportTypesM importTypes = pojoType.addToImportTypes(new ImportTypesM());
if (factoryMethod != null) {
factoryMethod.getDeclaringClass().addToImportTypes(importTypes);
}
properties.getTypes().addToImportTypes(importTypes);
importTypes.add(Generated.class);
if (optionalType != null) {
optionalType.addToImportTypes(importTypes);
}
String baseclass;
if (baseType == null || baseType.getName().equals("java.lang.Object")) {
baseclass = null;
} else {
// baseclass = baseType.getName();
baseclass = baseType.getGenericTypeDeclaration();
baseType.addToImportTypes(importTypes);
}
EnumSet<Modifier> builderTypeModifier;
if (isAbstract) {
builderTypeModifier = EnumSet.of(PUBLIC, ABSTRACT);
} else {
builderTypeModifier = EnumSet.of(PUBLIC);
}
// @formatter:off
String[] interfaces;
if ( interfaceType == null) {
interfaces = new String[] {"Cloneable"};
} else {
interfaces = new String[] {interfaceType.getGenericTypeDeclaration(), "Cloneable"};
interfaceType.addToImportTypes(importTypes);
}
if ( validator != null) {
validator.getType().addToImportTypes(importTypes);
}
importTypes.removePackage(builderType.getPackageName());
importTypes.removePackage("java.lang");
writer
.emitPackage(builderType.getPackageName())
.emitImports(importTypes.getSortedDistinctClassnames())
.emitEmptyLine()
.emitAnnotation(Generated.class, JavaWriter.stringLiteral("PojoBuilder"))
.beginType(builderType.getGenericType(), "class", builderTypeModifier, baseclass, interfaces)
.emitField(selfType.getGenericTypeDeclaration(), "self", EnumSet.of(PROTECTED));