63 * This code and its internal interfaces are subject to change or |
63 * This code and its internal interfaces are subject to change or |
64 * deletion without notice.</b> |
64 * deletion without notice.</b> |
65 */ |
65 */ |
66 public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter { |
66 public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter { |
67 |
67 |
68 protected int currentIndentation = 0; |
|
69 |
|
70 /** |
68 /** |
71 * Create a basic formatter based on the supplied options. |
69 * Create a basic formatter based on the supplied options. |
72 * |
70 * |
73 * @param opts list of command-line options |
71 * @param opts list of command-line options |
74 * @param msgs JavacMessages object used for i18n |
72 * @param msgs JavacMessages object used for i18n |
105 else |
103 else |
106 return buf.toString(); |
104 return buf.toString(); |
107 } |
105 } |
108 |
106 |
109 public String formatMessage(JCDiagnostic d, Locale l) { |
107 public String formatMessage(JCDiagnostic d, Locale l) { |
110 int prevIndentation = currentIndentation; |
108 int currentIndentation = 0; |
111 try { |
109 StringBuilder buf = new StringBuilder(); |
112 StringBuilder buf = new StringBuilder(); |
110 Collection<String> args = formatArguments(d, l); |
113 Collection<String> args = formatArguments(d, l); |
111 String msg = localize(l, d.getCode(), args.toArray()); |
114 String msg = localize(l, d.getCode(), args.toArray()); |
112 String[] lines = msg.split("\n"); |
115 String[] lines = msg.split("\n"); |
113 if (getConfiguration().getVisible().contains(DiagnosticPart.SUMMARY)) { |
116 if (getConfiguration().getVisible().contains(DiagnosticPart.SUMMARY)) { |
114 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUMMARY); |
117 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUMMARY); |
115 buf.append(indent(lines[0], currentIndentation)); //summary |
118 buf.append(indent(lines[0], currentIndentation)); //summary |
116 } |
119 } |
117 if (lines.length > 1 && getConfiguration().getVisible().contains(DiagnosticPart.DETAILS)) { |
120 if (lines.length > 1 && getConfiguration().getVisible().contains(DiagnosticPart.DETAILS)) { |
118 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.DETAILS); |
121 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.DETAILS); |
119 for (int i = 1;i < lines.length; i++) { |
122 for (int i = 1;i < lines.length; i++) { |
120 buf.append("\n" + indent(lines[i], currentIndentation)); |
123 buf.append("\n" + indent(lines[i], currentIndentation)); |
121 } |
124 } |
122 } |
125 } |
123 if (d.isMultiline() && getConfiguration().getVisible().contains(DiagnosticPart.SUBDIAGNOSTICS)) { |
126 if (d.isMultiline() && getConfiguration().getVisible().contains(DiagnosticPart.SUBDIAGNOSTICS)) { |
124 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUBDIAGNOSTICS); |
127 currentIndentation += getConfiguration().getIndentation(DiagnosticPart.SUBDIAGNOSTICS); |
|
128 for (String sub : formatSubdiagnostics(d, l)) { |
125 for (String sub : formatSubdiagnostics(d, l)) { |
129 buf.append("\n" + sub); |
126 buf.append("\n" + indent(sub, currentIndentation)); |
130 } |
127 } |
131 } |
128 } |
132 return buf.toString(); |
129 return buf.toString(); |
133 } |
|
134 finally { |
|
135 currentIndentation = prevIndentation; |
|
136 } |
|
137 } |
130 } |
138 |
131 |
139 protected String addSourceLineIfNeeded(JCDiagnostic d, String msg) { |
132 protected String addSourceLineIfNeeded(JCDiagnostic d, String msg) { |
140 if (!displaySource(d)) |
133 if (!displaySource(d)) |
141 return msg; |
134 return msg; |