private MethodDeclaration createStageInputsMethod() {
SimpleName list = factory.newSimpleName("results");
SimpleName attributes = factory.newSimpleName("attributes");
List<Statement> statements = Lists.create();
statements.add(new TypeBuilder(factory, t(ArrayList.class, t(StageInput.class)))
.newObject()
.toLocalVariableDeclaration(t(List.class, t(StageInput.class)), list));
statements.add(new ExpressionBuilder(factory, Models.toNullLiteral(factory))
.toLocalVariableDeclaration(t(Map.class, t(String.class), t(String.class)), attributes));
for (Process process : stage.getProcesses()) {
Expression mapperType = dotClass(process.getMapperTypeName());
for (Source source : process.getResolvedSources()) {
SourceInfo info = source.getInputInfo();
Class<?> inputFormatType = info.getFormat();
statements.add(new ExpressionBuilder(factory, attributes)
.assignFrom(new TypeBuilder(factory, t(HashMap.class, t(String.class), t(String.class)))
.newObject()
.toExpression())
.toStatement());
for (Map.Entry<String, String> entry : info.getAttributes().entrySet()) {
statements.add(new ExpressionBuilder(factory, attributes)
.method("put",
Models.toLiteral(factory, entry.getKey()),
Models.toLiteral(factory, entry.getValue()))
.toStatement());
}
for (Location location : info.getLocations()) {
statements.add(new ExpressionBuilder(factory, list)
.method("add", new TypeBuilder(factory, t(StageInput.class))
.newObject(
Models.toLiteral(factory, location.toPath('/')),
factory.newClassLiteral(t(inputFormatType)),
mapperType,
attributes)