private void formatResult(final StringBuilder out, final ErrorHandler.HandledResult result) {
final int linum = result.line();
final int maxLinumWidth = ("" + linum + CONTEXT_LINES).length();
final List<PrefixedLine> preambleLines = preambleLines(linum, maxLinumWidth);
final List<PrefixedLine> postambleLines = postambleLines(linum, maxLinumWidth);
final List<PrefixedLine> allLines = new ArrayList<>();
allLines.addAll(preambleLines);
allLines.addAll(postambleLines);
final int removeSpaces = smallestPrefixWhitespace(allLines);
out.append('\n')
.append(Util.withPrefix(" ", ambleString(preambleLines, removeSpaces)))
.append(alignPointerMessage(maxLinumWidth + result.column() + 2 - removeSpaces, result.primaryMessages()))
.append("\n")
.append(Util.withPrefix(" ", ambleString(postambleLines, removeSpaces)));
if (!result.secondaryMessages().isEmpty()) {
result.secondaryMessages().forEach(m -> out.append("\n").append(Util.withPrefix(" ", m.toString())).append("\n"));
}
if (!result.secondaryResults().isEmpty()) {
result.secondaryResults().forEach(r -> formatResult(out, r));
} else {
out.append("\n");
}
if (result.originalMessage() != null) {
out.append(Util.withPrefix(" ", I18N.lookup(I18N.Key.ORIGINAL_ERROR))).append("\n")
.append(Util.withPrefix(" > ", Util.indentLinesAfterNth(2, WRAPPED_LINE_INDENT, Util.wrapString(WRAPPED_LINE_WIDTH,
result.originalMessage()))))
.append("\n\n");
}
}