Returns the generated code as a string, optionally appending a final newline per FormatConfig.insertFinalNewline.