"return " + expressionSnippets[expressionSnippets.length - 1];
}
String snippet = Joiner.on(";\n").join(expressionSnippets) + ";\n";
final JProgram program = compileSnippet(returnType, snippet);
JMethod method = findMethod(program, MAIN_METHOD_NAME);
JMethodBody body = (JMethodBody) method.getBody();
JMultiExpression multi = new JMultiExpression(body.getSourceInfo());
// Transform statement sequence into a JMultiExpression
for (JStatement stmt : body.getStatements()) {
if (stmt instanceof JExpressionStatement) {
JExpressionStatement exprStmt = (JExpressionStatement) stmt;
JExpression expr = exprStmt.getExpr();
multi.addExpressions(expr);
} else if (stmt instanceof JReturnStatement) {
JReturnStatement returnStatement = (JReturnStatement) stmt;
JExpression expr = returnStatement.getExpr();
if (expr != null) {
multi.addExpressions(expr);
}
} else {
assert false : "Not a valid multiexpression";
}
}
// Take care of the return type
JStatement multiStm;
if (!returnType.equals("void")) {
multiStm = new JReturnStatement(multi.getSourceInfo(), multi);
} else {
multiStm = multi.makeStatement();
}
// Replace the method body
JMethodBody newBody = new JMethodBody(method.getBody().getSourceInfo());
newBody.getBlock().addStmt(multiStm);
method.setBody(newBody);
newBody.setMethod(method);
if (addClinitCalls) {
insertImplicitClinitCalls(method);
}