List<Statement> statements = Lists.create();
statements.add(new TypeBuilder(f, context.resolve(OrcFormatConfiguration.class))
.newObject()
.toLocalVariableDeclaration(context.resolve(OrcFormatConfiguration.class), result));
OrcFormatConfiguration conf = model.getTrait(OrcFileTrait.class).configuration();
if (conf.getFieldMappingStrategy() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withFieldMappingStrategy", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(FieldMappingStrategy.class))
.field(conf.getFieldMappingStrategy().name())
.toExpression())
.toStatement());
}
if (conf.getOnMissingSource() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withOnMissingSource", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(ExceptionHandlingStrategy.class))
.field(conf.getOnMissingSource().name())
.toExpression())
.toStatement());
}
if (conf.getOnMissingTarget() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withOnMissingTarget", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(ExceptionHandlingStrategy.class))
.field(conf.getOnMissingTarget().name())
.toExpression())
.toStatement());
}
if (conf.getOnIncompatibleType() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withOnIncompatibleType", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(ExceptionHandlingStrategy.class))
.field(conf.getOnIncompatibleType().name())
.toExpression())
.toStatement());
}
if (conf.getFormatVersion() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withFormatVersion", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(OrcFile.Version.class))
.field(conf.getFormatVersion().name())
.toExpression())
.toStatement());
}
if (conf.getCompressionKind() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withCompressionKind", //$NON-NLS-1$
new TypeBuilder(f, context.resolve(CompressionKind.class))
.field(conf.getCompressionKind().name())
.toExpression())
.toStatement());
}
if (conf.getStripeSize() != null) {
statements.add(new ExpressionBuilder(f, result)
.method("withStripeSize", Models.toLiteral(f, (long) conf.getStripeSize())) //$NON-NLS-1$
.toStatement());
}
statements.add(new ExpressionBuilder(f, result).toReturnStatement());
return f.newMethodDeclaration(
null,