*/
private void generateString(final TreeLogger logger, final GwtLocale locale,
final String template, final Parameters paramsAccessor, SourceWriter writer,
final boolean isSafeHtml, final int lastPluralArgNumber) throws UnableToCompleteException {
StringBuilder outputBuf = new StringBuilder();
final StringGenerator buf = StringGenerator.create(outputBuf, isSafeHtml);
final int n = paramsAccessor.getCount();
try {
for (TemplateChunk chunk : MessageFormatParser.parse(template)) {
chunk.accept(new DefaultTemplateChunkVisitor() {
@Override
public void visit(ArgumentChunk argChunk) throws UnableToCompleteException {
int argNumber = argChunk.getArgumentNumber();
if (argNumber >= n) {
throw error(logger, "Argument " + argNumber + " beyond range of arguments: " + template);
}
if (argNumber < 0) {
if (lastPluralArgNumber < 0) {
throw error(logger, "Inner-plural notation {#} used outside in non-plural message");
}
argNumber = lastPluralArgNumber;
}
JParameter param = paramsAccessor.getParameter(argNumber);
String arg = "arg" + argNumber;
if (argChunk.isList()) {
buf.appendExpression(arg + "_list", isSafeHtml, false, false);
} else {
JType paramType = param.getType();
formatArg(logger, locale, buf, argChunk,
paramsAccessor.getParameterExpression(argNumber), paramType,
paramsAccessor);
}
}
@Override
public void visit(StaticArgChunk staticArgChunk) {
buf.appendStringLiteral(staticArgChunk.getReplacement());
}
@Override
public void visit(StringChunk stringChunk) {
buf.appendStringLiteral(stringChunk.getString());
}
});
}
} catch (ParseException e) {
throw error(logger, e);
}
buf.completeString();
writer.print(outputBuf.toString());
}