}
private MethodDeclaration createGetConfiguration() {
List<Statement> statements = Lists.create();
List<Expression> arguments = Lists.create();
arguments.add(new TypeBuilder(f, context.resolve(Charset.class))
.method("forName", Models.toLiteral(f, conf.getCharsetName()))
.toExpression());
if (conf.isEnableHeader()) {
SimpleName headers = f.newSimpleName("headers");
statements.add(new TypeBuilder(f, context.resolve(ArrayList.class))
.parameterize(context.resolve(String.class))
.newObject()
.toLocalVariableDeclaration(
new TypeBuilder(f, context.resolve(List.class))
.parameterize(context.resolve(String.class))
.toType(),
headers));
for (PropertyDeclaration property : model.getDeclaredProperties()) {
if (isValueField(property)) {
String fieldName = CsvFieldTrait.getFieldName(property);
statements.add(new ExpressionBuilder(f, headers)
.method("add", Models.toLiteral(f, fieldName))
.toStatement());
}
}
arguments.add(headers);
} else {
arguments.add(new TypeBuilder(f, context.resolve(CsvConfiguration.class))
.field("DEFAULT_HEADER_CELLS")
.toExpression());
}
arguments.add(Models.toLiteral(f, conf.getTrueFormat()));
arguments.add(Models.toLiteral(f, conf.getFalseFormat()));
arguments.add(Models.toLiteral(f, conf.getDateFormat()));
arguments.add(Models.toLiteral(f, conf.getDateTimeFormat()));
statements.add(new TypeBuilder(f, context.resolve(CsvConfiguration.class))
.newObject(arguments)
.toReturnStatement());
return f.newMethodDeclaration(
new JavadocBuilder(f)
.text("Returns this CSV format configuration.")