}
private void writeFluentElement(VariableElement field, String builderName, OutputStreamWriter out,
final Set<? extends Element> buildables) throws Exception{
final BuiltWith annotation = field.getAnnotation(BuiltWith.class);
// determine the default value
// write the field declaration
if (field.asType().getKind().isPrimitive()) {
// it's primitive, so let's not assign a default value...
line(format("\tprivate %s %s;",
field.asType(),
field.getSimpleName().toString()),
out);
} else {
String defaultValue = determineDefaultValue(field, annotation);
if (defaultValue.isEmpty()) {
line(format("\tprivate %s %s;",
field.asType(),
field.getSimpleName().toString()),
out);
} else {
line(format("\tprivate %s %s = %s;",
field.asType(),
field.getSimpleName().toString(),
defaultValue),
out);
}
}
String methodName = determineFluentMethodName(annotation, field);
if (BuiltWith.USE_SENSIBLE_DEFAULT.equals(annotation.overrideArgType())){
// write the fluent built-with method that takes in the instance of the field
line(format("\tpublic %s %s(%s %s) {",
builderName, methodName,
field.asType(),
field.getSimpleName()),
out);
} else {
line(format("\tpublic %s %s(%s %s) {",
builderName, methodName,
annotation.overrideArgType(),
field.getSimpleName())
,out);
}
if (annotation.overrideMethod() != BuiltWith.OverrideMethod.NULL) {
switch (annotation.overrideMethod()) {
case AddToList:
line(format("\t\tthis.%s = new %s;", field.getSimpleName(), annotation.overrideClassifer()),
out);
line(format("\t\tjava.util.Collections.addAll(this.%s, %s);", field.getSimpleName(),
field.getSimpleName()),
out);
}