SourcePosition outputPosition = new SourcePosition(outputFileRef);
alertSink.add(new ProgressAlert(outputPosition, "Generating"));
CodeGenerator codeGenerator =
codeGeneratorFactory.getCodeGenerator(language, compilationUnit);
AlertCounter counter = new AlertCounter(alertSink, alertPolicy);
StringBuilder sb = new StringBuilder();
try {
codeGenerator.generateCode(sb, counter);
if (counter.getErrorCount() == 0) {
Writer writer = outputFileRef.openWriter(Charsets.US_ASCII);
try {
writer.write(sb.toString());
} finally {
writer.close();