Mon, 14 Feb 2011 14:27:47 -0800
7008433: Minor copyright changes
Reviewed-by: jjg
Contributed-by: kelly.ohair@oracle.com
mcimadamore@221 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@221 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@221 | 4 | * |
mcimadamore@221 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@221 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@221 | 7 | * published by the Free Software Foundation. |
mcimadamore@221 | 8 | * |
mcimadamore@221 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@221 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@221 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@221 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@221 | 13 | * accompanied this code). |
mcimadamore@221 | 14 | * |
mcimadamore@221 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@221 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@221 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@221 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
mcimadamore@221 | 22 | */ |
mcimadamore@221 | 23 | |
mcimadamore@221 | 24 | /** |
mcimadamore@221 | 25 | * @test |
mcimadamore@221 | 26 | * @bug 6769027 |
mcimadamore@221 | 27 | * @summary Source line should be displayed immediately after the first diagnostic line |
mcimadamore@221 | 28 | * @author Maurizio Cimadamore |
mcimadamore@221 | 29 | * @run main/othervm T6769027 |
mcimadamore@221 | 30 | */ |
mcimadamore@221 | 31 | import java.net.URI; |
mcimadamore@221 | 32 | import java.util.regex.Matcher; |
mcimadamore@221 | 33 | import javax.tools.*; |
mcimadamore@221 | 34 | import com.sun.tools.javac.util.*; |
mcimadamore@221 | 35 | |
mcimadamore@221 | 36 | public class T6769027 { |
mcimadamore@221 | 37 | |
mcimadamore@221 | 38 | enum OutputKind { |
mcimadamore@221 | 39 | RAW("rawDiagnostics","rawDiagnostics"), |
mcimadamore@221 | 40 | BASIC("",""); |
mcimadamore@221 | 41 | |
mcimadamore@221 | 42 | String key; |
mcimadamore@221 | 43 | String value; |
mcimadamore@221 | 44 | |
mcimadamore@221 | 45 | void init(Options opts) { |
mcimadamore@221 | 46 | opts.put(key, value); |
mcimadamore@221 | 47 | } |
mcimadamore@221 | 48 | |
mcimadamore@221 | 49 | OutputKind(String key, String value) { |
mcimadamore@221 | 50 | this.key = key; |
mcimadamore@221 | 51 | this.value = value; |
mcimadamore@221 | 52 | } |
mcimadamore@221 | 53 | } |
mcimadamore@221 | 54 | |
mcimadamore@221 | 55 | enum CaretKind { |
mcimadamore@221 | 56 | DEFAULT("", ""), |
mcimadamore@221 | 57 | SHOW("showCaret","true"), |
mcimadamore@221 | 58 | HIDE("showCaret","false"); |
mcimadamore@221 | 59 | |
mcimadamore@221 | 60 | String key; |
mcimadamore@221 | 61 | String value; |
mcimadamore@221 | 62 | |
mcimadamore@221 | 63 | void init(Options opts) { |
mcimadamore@221 | 64 | opts.put(key, value); |
mcimadamore@221 | 65 | } |
mcimadamore@221 | 66 | |
mcimadamore@221 | 67 | CaretKind(String key, String value) { |
mcimadamore@221 | 68 | this.key = key; |
mcimadamore@221 | 69 | this.value = value; |
mcimadamore@221 | 70 | } |
mcimadamore@221 | 71 | |
mcimadamore@221 | 72 | boolean isEnabled() { |
mcimadamore@221 | 73 | return this == DEFAULT || this == SHOW; |
mcimadamore@221 | 74 | } |
mcimadamore@221 | 75 | } |
mcimadamore@221 | 76 | |
mcimadamore@221 | 77 | enum SourceLineKind { |
mcimadamore@221 | 78 | DEFAULT("", ""), |
mcimadamore@221 | 79 | AFTER_SUMMARY("sourcePosition", "top"), |
mcimadamore@221 | 80 | BOTTOM("sourcePosition", "bottom"); |
mcimadamore@221 | 81 | |
mcimadamore@221 | 82 | String key; |
mcimadamore@221 | 83 | String value; |
mcimadamore@221 | 84 | |
mcimadamore@221 | 85 | void init(Options opts) { |
mcimadamore@221 | 86 | opts.put(key, value); |
mcimadamore@221 | 87 | } |
mcimadamore@221 | 88 | |
mcimadamore@221 | 89 | SourceLineKind(String key, String value) { |
mcimadamore@221 | 90 | this.key = key; |
mcimadamore@221 | 91 | this.value = value; |
mcimadamore@221 | 92 | } |
mcimadamore@221 | 93 | |
mcimadamore@221 | 94 | boolean isAfterSummary() { |
mcimadamore@221 | 95 | return this == DEFAULT || this == AFTER_SUMMARY; |
mcimadamore@221 | 96 | } |
mcimadamore@221 | 97 | } |
mcimadamore@221 | 98 | |
mcimadamore@221 | 99 | enum XDiagsSource { |
mcimadamore@221 | 100 | DEFAULT(""), |
mcimadamore@221 | 101 | SOURCE("source"), |
mcimadamore@221 | 102 | NO_SOURCE("-source"); |
mcimadamore@221 | 103 | |
mcimadamore@221 | 104 | String flag; |
mcimadamore@221 | 105 | |
mcimadamore@221 | 106 | void init(Options opts) { |
mcimadamore@221 | 107 | if (this != DEFAULT) { |
mcimadamore@221 | 108 | String flags = opts.get("diags"); |
mcimadamore@221 | 109 | flags = flags == null ? flag : flags + "," + flag; |
mcimadamore@221 | 110 | opts.put("diags", flags); |
mcimadamore@221 | 111 | } |
mcimadamore@221 | 112 | } |
mcimadamore@221 | 113 | |
mcimadamore@221 | 114 | XDiagsSource(String flag) { |
mcimadamore@221 | 115 | this.flag = flag; |
mcimadamore@221 | 116 | } |
mcimadamore@221 | 117 | |
mcimadamore@221 | 118 | String getOutput(CaretKind caretKind, IndentKind indent, OutputKind outKind) { |
mcimadamore@221 | 119 | String spaces = (outKind == OutputKind.BASIC) ? indent.string : ""; |
mcimadamore@221 | 120 | return "\n" + spaces + "This is a source line" + |
mcimadamore@221 | 121 | (caretKind.isEnabled() ? "\n" + spaces + " ^" : ""); |
mcimadamore@221 | 122 | } |
mcimadamore@221 | 123 | } |
mcimadamore@221 | 124 | |
mcimadamore@221 | 125 | enum XDiagsCompact { |
mcimadamore@221 | 126 | DEFAULT(""), |
mcimadamore@221 | 127 | COMPACT("short"), |
mcimadamore@221 | 128 | NO_COMPACT("-short"); |
mcimadamore@221 | 129 | |
mcimadamore@221 | 130 | String flag; |
mcimadamore@221 | 131 | |
mcimadamore@221 | 132 | void init(Options opts) { |
mcimadamore@221 | 133 | if (this != DEFAULT) { |
mcimadamore@221 | 134 | String flags = opts.get("diags"); |
mcimadamore@221 | 135 | flags = flags == null ? flag : flags + "," + flag; |
mcimadamore@221 | 136 | opts.put("diags", flags); |
mcimadamore@221 | 137 | } |
mcimadamore@221 | 138 | } |
mcimadamore@221 | 139 | |
mcimadamore@221 | 140 | XDiagsCompact(String flag) { |
mcimadamore@221 | 141 | this.flag = flag; |
mcimadamore@221 | 142 | } |
mcimadamore@221 | 143 | } |
mcimadamore@221 | 144 | |
mcimadamore@221 | 145 | enum ErrorKind { |
mcimadamore@221 | 146 | SINGLE("single", |
mcimadamore@221 | 147 | "compiler.err.single: Hello!", |
mcimadamore@221 | 148 | "KXThis is a test error message Hello!"), |
mcimadamore@221 | 149 | DOUBLE("double", |
mcimadamore@221 | 150 | "compiler.err.double: Hello!", |
mcimadamore@221 | 151 | "KXThis is a test error message.\n" + |
mcimadamore@221 | 152 | "KXYThis is another line of the above error message Hello!"); |
mcimadamore@221 | 153 | |
mcimadamore@221 | 154 | String key; |
mcimadamore@221 | 155 | String rawOutput; |
mcimadamore@221 | 156 | String nonRawOutput; |
mcimadamore@221 | 157 | |
mcimadamore@221 | 158 | String key() { |
mcimadamore@221 | 159 | return key; |
mcimadamore@221 | 160 | } |
mcimadamore@221 | 161 | |
mcimadamore@221 | 162 | ErrorKind(String key, String rawOutput, String nonRawOutput) { |
mcimadamore@221 | 163 | this.key = key; |
mcimadamore@221 | 164 | this.rawOutput = rawOutput; |
mcimadamore@221 | 165 | this.nonRawOutput = nonRawOutput; |
mcimadamore@221 | 166 | } |
mcimadamore@221 | 167 | |
mcimadamore@221 | 168 | String getOutput(OutputKind outKind, IndentKind summaryIndent, IndentKind detailsIndent) { |
mcimadamore@221 | 169 | return outKind == OutputKind.RAW ? |
mcimadamore@221 | 170 | rawOutput : |
mcimadamore@221 | 171 | nonRawOutput.replace("X", summaryIndent.string).replace("Y", detailsIndent.string).replace("K", ""); |
mcimadamore@221 | 172 | } |
mcimadamore@221 | 173 | |
mcimadamore@221 | 174 | String getOutput(OutputKind outKind, IndentKind summaryIndent, IndentKind detailsIndent, String indent) { |
mcimadamore@221 | 175 | return outKind == OutputKind.RAW ? |
mcimadamore@221 | 176 | rawOutput : |
mcimadamore@221 | 177 | nonRawOutput.replace("X", summaryIndent.string).replace("Y", detailsIndent.string).replace("K", indent); |
mcimadamore@221 | 178 | } |
mcimadamore@221 | 179 | } |
mcimadamore@221 | 180 | |
mcimadamore@221 | 181 | enum MultilineKind { |
mcimadamore@221 | 182 | NONE(0), |
mcimadamore@221 | 183 | DOUBLE(1), |
mcimadamore@221 | 184 | NESTED(2), |
mcimadamore@221 | 185 | DOUBLE_NESTED(3); |
mcimadamore@221 | 186 | |
mcimadamore@221 | 187 | static String[][] rawTemplates = { |
mcimadamore@221 | 188 | {"", ",{(E),(E)}", ",{(E,{(E)})}", ",{(E,{(E)}),(E,{(E)})}"}, //ENABLED |
mcimadamore@221 | 189 | {"", "", "", "",""}, //DISABLED |
mcimadamore@221 | 190 | {"", ",{(E)}", ",{(E,{(E)})}", ",{(E,{(E)})}"}, //LIMIT_LENGTH |
mcimadamore@221 | 191 | {"", ",{(E),(E)}", ",{(E)}", ",{(E),(E)}"}, //LIMIT_DEPTH |
mcimadamore@221 | 192 | {"", ",{(E)}", ",{(E)}", ",{(E)}"}}; //LIMIT_BOTH |
mcimadamore@221 | 193 | |
mcimadamore@221 | 194 | static String[][] basicTemplates = { |
mcimadamore@221 | 195 | {"", "\nE\nE", "\nE\nQ", "\nE\nQ\nE\nQ"}, //ENABLED |
mcimadamore@221 | 196 | {"", "", "", "",""}, //DISABLED |
mcimadamore@221 | 197 | {"", "\nE", "\nE\nQ", "\nE\nQ"}, //LIMIT_LENGTH |
mcimadamore@221 | 198 | {"", "\nE\nE", "\nE", "\nE\nE"}, //LIMIT_DEPTH |
mcimadamore@221 | 199 | {"", "\nE", "\nE", "\nE"}}; //LIMIT_BOTH |
mcimadamore@221 | 200 | |
mcimadamore@221 | 201 | |
mcimadamore@221 | 202 | int index; |
mcimadamore@221 | 203 | |
mcimadamore@221 | 204 | MultilineKind (int index) { |
mcimadamore@221 | 205 | this.index = index; |
mcimadamore@221 | 206 | } |
mcimadamore@221 | 207 | |
mcimadamore@221 | 208 | boolean isDouble() { |
mcimadamore@221 | 209 | return this == DOUBLE || this == DOUBLE_NESTED; |
mcimadamore@221 | 210 | } |
mcimadamore@221 | 211 | |
mcimadamore@221 | 212 | boolean isNested() { |
mcimadamore@221 | 213 | return this == NESTED || this == DOUBLE_NESTED; |
mcimadamore@221 | 214 | } |
mcimadamore@221 | 215 | |
mcimadamore@221 | 216 | String getOutput(OutputKind outKind, ErrorKind errKind, MultilinePolicy policy, |
mcimadamore@221 | 217 | IndentKind summaryIndent, IndentKind detailsIndent, IndentKind multiIndent) { |
mcimadamore@221 | 218 | String constIndent = (errKind == ErrorKind.DOUBLE) ? |
mcimadamore@221 | 219 | summaryIndent.string + detailsIndent.string : |
mcimadamore@221 | 220 | summaryIndent.string; |
mcimadamore@221 | 221 | constIndent += multiIndent.string; |
mcimadamore@221 | 222 | |
mcimadamore@221 | 223 | String errMsg1 = errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent); |
mcimadamore@221 | 224 | String errMsg2 = errKind.getOutput(outKind, summaryIndent, detailsIndent, constIndent + constIndent); |
mcimadamore@221 | 225 | |
mcimadamore@221 | 226 | errMsg1 = errMsg1.replaceAll("compiler.err", "compiler.misc"); |
mcimadamore@221 | 227 | errMsg1 = errMsg1.replaceAll("error message", "subdiagnostic"); |
mcimadamore@221 | 228 | errMsg2 = errMsg2.replaceAll("compiler.err", "compiler.misc"); |
mcimadamore@221 | 229 | errMsg2 = errMsg2.replaceAll("error message", "subdiagnostic"); |
mcimadamore@221 | 230 | |
mcimadamore@221 | 231 | String template = outKind == OutputKind.RAW ? |
mcimadamore@221 | 232 | rawTemplates[policy.index][index] : |
mcimadamore@221 | 233 | basicTemplates[policy.index][index]; |
mcimadamore@221 | 234 | |
mcimadamore@221 | 235 | template = template.replaceAll("E", errMsg1); |
mcimadamore@221 | 236 | return template.replaceAll("Q", errMsg2); |
mcimadamore@221 | 237 | } |
mcimadamore@221 | 238 | } |
mcimadamore@221 | 239 | |
mcimadamore@221 | 240 | enum MultilinePolicy { |
mcimadamore@221 | 241 | ENABLED(0, "multilinePolicy", "enabled"), |
mcimadamore@221 | 242 | DISABLED(1, "multilinePolicy", "disabled"), |
mcimadamore@221 | 243 | LIMIT_LENGTH(2, "multilinePolicy", "limit:1:*"), |
mcimadamore@221 | 244 | LIMIT_DEPTH(3, "multilinePolicy", "limit:*:1"), |
mcimadamore@221 | 245 | LIMIT_BOTH(4, "multilinePolicy", "limit:1:1"); |
mcimadamore@221 | 246 | |
mcimadamore@221 | 247 | String name; |
mcimadamore@221 | 248 | String value; |
mcimadamore@221 | 249 | int index; |
mcimadamore@221 | 250 | |
mcimadamore@221 | 251 | MultilinePolicy(int index, String name, String value) { |
mcimadamore@221 | 252 | this.name = name; |
mcimadamore@221 | 253 | this.value = value; |
mcimadamore@221 | 254 | this.index = index; |
mcimadamore@221 | 255 | } |
mcimadamore@221 | 256 | |
mcimadamore@221 | 257 | void init(Options options) { |
mcimadamore@221 | 258 | options.put(name, value); |
mcimadamore@221 | 259 | } |
mcimadamore@221 | 260 | } |
mcimadamore@221 | 261 | |
mcimadamore@221 | 262 | enum PositionKind { |
mcimadamore@221 | 263 | NOPOS(Position.NOPOS, "- ", "error: "), |
jjg@415 | 264 | POS(5, "Test.java:1:6: ", "/Test.java:1: "); |
mcimadamore@221 | 265 | |
mcimadamore@221 | 266 | int pos; |
mcimadamore@221 | 267 | String rawOutput; |
mcimadamore@221 | 268 | String nonRawOutput; |
mcimadamore@221 | 269 | |
mcimadamore@221 | 270 | PositionKind(int pos, String rawOutput, String nonRawOutput) { |
mcimadamore@221 | 271 | this.pos = pos; |
mcimadamore@221 | 272 | this.rawOutput = rawOutput; |
mcimadamore@221 | 273 | this.nonRawOutput = nonRawOutput; |
mcimadamore@221 | 274 | } |
mcimadamore@221 | 275 | |
mcimadamore@221 | 276 | JCDiagnostic.DiagnosticPosition pos() { |
mcimadamore@221 | 277 | return new JCDiagnostic.SimpleDiagnosticPosition(pos); |
mcimadamore@221 | 278 | } |
mcimadamore@221 | 279 | |
mcimadamore@221 | 280 | String getOutput(OutputKind outputKind) { |
mcimadamore@221 | 281 | return outputKind == OutputKind.RAW ? |
mcimadamore@221 | 282 | rawOutput : |
mcimadamore@221 | 283 | nonRawOutput; |
mcimadamore@221 | 284 | } |
mcimadamore@221 | 285 | } |
mcimadamore@221 | 286 | |
mcimadamore@221 | 287 | static class MyFileObject extends SimpleJavaFileObject { |
mcimadamore@221 | 288 | private String text; |
mcimadamore@221 | 289 | public MyFileObject(String text) { |
mcimadamore@221 | 290 | super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
mcimadamore@221 | 291 | this.text = text; |
mcimadamore@221 | 292 | } |
mcimadamore@221 | 293 | @Override |
mcimadamore@221 | 294 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
mcimadamore@221 | 295 | return text; |
mcimadamore@221 | 296 | } |
mcimadamore@221 | 297 | } |
mcimadamore@221 | 298 | |
mcimadamore@221 | 299 | enum IndentKind { |
mcimadamore@221 | 300 | NONE(""), |
mcimadamore@221 | 301 | CUSTOM(" "); |
mcimadamore@221 | 302 | |
mcimadamore@221 | 303 | String string; |
mcimadamore@221 | 304 | |
mcimadamore@221 | 305 | IndentKind(String indent) { |
mcimadamore@221 | 306 | string = indent; |
mcimadamore@221 | 307 | } |
mcimadamore@221 | 308 | } |
mcimadamore@221 | 309 | |
mcimadamore@221 | 310 | class MyLog extends Log { |
mcimadamore@221 | 311 | MyLog(Context ctx) { |
mcimadamore@221 | 312 | super(ctx); |
mcimadamore@221 | 313 | } |
mcimadamore@221 | 314 | |
mcimadamore@221 | 315 | @Override |
mcimadamore@221 | 316 | protected java.io.PrintWriter getWriterForDiagnosticType(JCDiagnostic.DiagnosticType dt) { |
mcimadamore@221 | 317 | return new java.io.PrintWriter(System.out); |
mcimadamore@221 | 318 | } |
mcimadamore@221 | 319 | |
mcimadamore@221 | 320 | @Override |
mcimadamore@221 | 321 | protected boolean shouldReport(JavaFileObject jfo, int pos) { |
mcimadamore@221 | 322 | return true; |
mcimadamore@221 | 323 | } |
mcimadamore@221 | 324 | } |
mcimadamore@221 | 325 | |
mcimadamore@221 | 326 | int nerrors = 0; |
mcimadamore@221 | 327 | |
mcimadamore@221 | 328 | void exec(OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind, |
mcimadamore@221 | 329 | MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource, |
mcimadamore@221 | 330 | XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind, |
mcimadamore@221 | 331 | IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent, |
mcimadamore@221 | 332 | IndentKind subdiagsIndent) { |
mcimadamore@221 | 333 | Context ctx = new Context(); |
mcimadamore@221 | 334 | Options options = Options.instance(ctx); |
mcimadamore@221 | 335 | outputKind.init(options); |
mcimadamore@221 | 336 | multiPolicy.init(options); |
mcimadamore@221 | 337 | xdiagsSource.init(options); |
mcimadamore@221 | 338 | xdiagsCompact.init(options); |
mcimadamore@221 | 339 | caretKind.init(options); |
mcimadamore@221 | 340 | sourceLineKind.init(options); |
mcimadamore@221 | 341 | String indentString = ""; |
mcimadamore@221 | 342 | indentString = (summaryIndent == IndentKind.CUSTOM) ? "3" : "0"; |
mcimadamore@221 | 343 | indentString += (detailsIndent == IndentKind.CUSTOM) ? "|3" : "|0"; |
mcimadamore@221 | 344 | indentString += (sourceIndent == IndentKind.CUSTOM) ? "|3" : "|0"; |
mcimadamore@221 | 345 | indentString += (subdiagsIndent == IndentKind.CUSTOM) ? "|3" : "|0"; |
mcimadamore@221 | 346 | options.put("diagsIndentation", indentString); |
mcimadamore@221 | 347 | MyLog log = new MyLog(ctx); |
mcimadamore@221 | 348 | JavacMessages messages = JavacMessages.instance(ctx); |
mcimadamore@221 | 349 | messages.add("tester"); |
mcimadamore@221 | 350 | JCDiagnostic.Factory diags = JCDiagnostic.Factory.instance(ctx); |
mcimadamore@221 | 351 | log.useSource(new MyFileObject("This is a source line")); |
mcimadamore@221 | 352 | JCDiagnostic d = diags.error(log.currentSource(), |
mcimadamore@221 | 353 | posKind.pos(), |
mcimadamore@221 | 354 | errorKind.key(), "Hello!"); |
mcimadamore@221 | 355 | if (multiKind != MultilineKind.NONE) { |
mcimadamore@221 | 356 | JCDiagnostic sub = diags.fragment(errorKind.key(), "Hello!"); |
mcimadamore@221 | 357 | if (multiKind.isNested()) |
mcimadamore@221 | 358 | sub = new JCDiagnostic.MultilineDiagnostic(sub, List.of(sub)); |
mcimadamore@221 | 359 | List<JCDiagnostic> subdiags = multiKind.isDouble() ? |
mcimadamore@221 | 360 | List.of(sub, sub) : |
mcimadamore@221 | 361 | List.of(sub); |
mcimadamore@221 | 362 | d = new JCDiagnostic.MultilineDiagnostic(d, subdiags); |
mcimadamore@221 | 363 | } |
mcimadamore@221 | 364 | String diag = log.getDiagnosticFormatter().format(d, messages.getCurrentLocale()); |
mcimadamore@221 | 365 | checkOutput(diag, |
mcimadamore@221 | 366 | outputKind, |
mcimadamore@221 | 367 | errorKind, |
mcimadamore@221 | 368 | multiKind, |
mcimadamore@221 | 369 | multiPolicy, |
mcimadamore@221 | 370 | posKind, |
mcimadamore@221 | 371 | xdiagsSource, |
mcimadamore@221 | 372 | xdiagsCompact, |
mcimadamore@221 | 373 | caretKind, |
mcimadamore@221 | 374 | sourceLineKind, |
mcimadamore@221 | 375 | summaryIndent, |
mcimadamore@221 | 376 | detailsIndent, |
mcimadamore@221 | 377 | sourceIndent, |
mcimadamore@221 | 378 | subdiagsIndent); |
mcimadamore@221 | 379 | } |
mcimadamore@221 | 380 | |
mcimadamore@221 | 381 | void test() { |
mcimadamore@221 | 382 | for (OutputKind outputKind : OutputKind.values()) { |
mcimadamore@221 | 383 | for (ErrorKind errKind : ErrorKind.values()) { |
mcimadamore@221 | 384 | for (MultilineKind multiKind : MultilineKind.values()) { |
mcimadamore@221 | 385 | for (MultilinePolicy multiPolicy : MultilinePolicy.values()) { |
mcimadamore@221 | 386 | for (PositionKind posKind : PositionKind.values()) { |
mcimadamore@221 | 387 | for (XDiagsSource xdiagsSource : XDiagsSource.values()) { |
mcimadamore@221 | 388 | for (XDiagsCompact xdiagsCompact : XDiagsCompact.values()) { |
mcimadamore@221 | 389 | for (CaretKind caretKind : CaretKind.values()) { |
mcimadamore@221 | 390 | for (SourceLineKind sourceLineKind : SourceLineKind.values()) { |
mcimadamore@221 | 391 | for (IndentKind summaryIndent : IndentKind.values()) { |
mcimadamore@221 | 392 | for (IndentKind detailsIndent : IndentKind.values()) { |
mcimadamore@221 | 393 | for (IndentKind sourceIndent : IndentKind.values()) { |
mcimadamore@221 | 394 | for (IndentKind subdiagsIndent : IndentKind.values()) { |
mcimadamore@221 | 395 | exec(outputKind, |
mcimadamore@221 | 396 | errKind, |
mcimadamore@221 | 397 | multiKind, |
mcimadamore@221 | 398 | multiPolicy, |
mcimadamore@221 | 399 | posKind, |
mcimadamore@221 | 400 | xdiagsSource, |
mcimadamore@221 | 401 | xdiagsCompact, |
mcimadamore@221 | 402 | caretKind, |
mcimadamore@221 | 403 | sourceLineKind, |
mcimadamore@221 | 404 | summaryIndent, |
mcimadamore@221 | 405 | detailsIndent, |
mcimadamore@221 | 406 | sourceIndent, |
mcimadamore@221 | 407 | subdiagsIndent); |
mcimadamore@221 | 408 | } |
mcimadamore@221 | 409 | } |
mcimadamore@221 | 410 | } |
mcimadamore@221 | 411 | } |
mcimadamore@221 | 412 | } |
mcimadamore@221 | 413 | } |
mcimadamore@221 | 414 | } |
mcimadamore@221 | 415 | } |
mcimadamore@221 | 416 | } |
mcimadamore@221 | 417 | } |
mcimadamore@221 | 418 | } |
mcimadamore@221 | 419 | } |
mcimadamore@221 | 420 | } |
mcimadamore@221 | 421 | if (nerrors != 0) |
mcimadamore@221 | 422 | throw new AssertionError(nerrors + " errors found"); |
mcimadamore@221 | 423 | } |
mcimadamore@221 | 424 | |
mcimadamore@221 | 425 | void printInfo(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind, |
mcimadamore@221 | 426 | MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource, |
mcimadamore@221 | 427 | XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind, |
mcimadamore@221 | 428 | IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent, |
mcimadamore@221 | 429 | IndentKind subdiagsIndent, String errorLine) { |
mcimadamore@221 | 430 | String sep = "*********************************************************"; |
mcimadamore@221 | 431 | String desc = "raw=" + outputKind + " pos=" + posKind + " key=" + errorKind.key() + |
mcimadamore@221 | 432 | " multiline=" + multiKind +" multiPolicy=" + multiPolicy.value + |
mcimadamore@221 | 433 | " diags= " + java.util.Arrays.asList(xdiagsSource.flag, xdiagsCompact.flag) + |
mcimadamore@221 | 434 | " caret=" + caretKind + " sourcePosition=" + sourceLineKind + |
mcimadamore@221 | 435 | " summaryIndent=" + summaryIndent + " detailsIndent=" + detailsIndent + |
mcimadamore@221 | 436 | " sourceIndent=" + sourceIndent + " subdiagsIndent=" + subdiagsIndent; |
mcimadamore@221 | 437 | System.out.println(sep); |
mcimadamore@221 | 438 | System.out.println(desc); |
mcimadamore@221 | 439 | System.out.println(sep); |
mcimadamore@221 | 440 | System.out.println(msg); |
mcimadamore@221 | 441 | System.out.println("Diagnostic formatting problem - expected diagnostic...\n" + errorLine); |
mcimadamore@221 | 442 | } |
mcimadamore@221 | 443 | |
mcimadamore@221 | 444 | void checkOutput(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind, |
mcimadamore@221 | 445 | MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource, |
mcimadamore@221 | 446 | XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind, |
mcimadamore@221 | 447 | IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent, |
mcimadamore@221 | 448 | IndentKind subdiagsIndent) { |
mcimadamore@221 | 449 | boolean shouldPrintSource = posKind == PositionKind.POS && |
mcimadamore@221 | 450 | xdiagsSource != XDiagsSource.NO_SOURCE && |
mcimadamore@221 | 451 | (xdiagsSource == XDiagsSource.SOURCE || |
mcimadamore@221 | 452 | outputKind == OutputKind.BASIC); |
mcimadamore@221 | 453 | String errorLine = posKind.getOutput(outputKind) + |
mcimadamore@221 | 454 | errorKind.getOutput(outputKind, summaryIndent, detailsIndent); |
mcimadamore@221 | 455 | if (xdiagsCompact != XDiagsCompact.COMPACT) |
mcimadamore@221 | 456 | errorLine += multiKind.getOutput(outputKind, errorKind, multiPolicy, summaryIndent, detailsIndent, subdiagsIndent); |
mcimadamore@221 | 457 | String[] lines = errorLine.split("\n"); |
mcimadamore@221 | 458 | if (xdiagsCompact == XDiagsCompact.COMPACT) { |
mcimadamore@221 | 459 | errorLine = lines[0]; |
mcimadamore@221 | 460 | lines = new String[] {errorLine}; |
mcimadamore@221 | 461 | } |
mcimadamore@221 | 462 | if (shouldPrintSource) { |
mcimadamore@221 | 463 | if (sourceLineKind.isAfterSummary()) { |
mcimadamore@221 | 464 | String sep = "\n"; |
mcimadamore@221 | 465 | if (lines.length == 1) { |
mcimadamore@221 | 466 | errorLine += "\n"; |
mcimadamore@221 | 467 | sep = ""; |
mcimadamore@221 | 468 | } |
mcimadamore@221 | 469 | errorLine = errorLine.replaceFirst("\n", |
mcimadamore@221 | 470 | Matcher.quoteReplacement(xdiagsSource.getOutput(caretKind, sourceIndent, outputKind) + sep)); |
mcimadamore@221 | 471 | } |
mcimadamore@221 | 472 | else |
mcimadamore@221 | 473 | errorLine += xdiagsSource.getOutput(caretKind, sourceIndent, outputKind); |
mcimadamore@221 | 474 | } |
mcimadamore@221 | 475 | |
mcimadamore@221 | 476 | if (!msg.equals(errorLine)) { |
mcimadamore@221 | 477 | printInfo(msg, |
mcimadamore@221 | 478 | outputKind, |
mcimadamore@221 | 479 | errorKind, |
mcimadamore@221 | 480 | multiKind, |
mcimadamore@221 | 481 | multiPolicy, |
mcimadamore@221 | 482 | posKind, |
mcimadamore@221 | 483 | xdiagsSource, |
mcimadamore@221 | 484 | xdiagsCompact, |
mcimadamore@221 | 485 | caretKind, |
mcimadamore@221 | 486 | sourceLineKind, |
mcimadamore@221 | 487 | summaryIndent, |
mcimadamore@221 | 488 | detailsIndent, |
mcimadamore@221 | 489 | sourceIndent, |
mcimadamore@221 | 490 | subdiagsIndent, |
mcimadamore@221 | 491 | errorLine); |
mcimadamore@221 | 492 | nerrors++; |
mcimadamore@221 | 493 | } |
mcimadamore@221 | 494 | } |
mcimadamore@221 | 495 | |
mcimadamore@221 | 496 | public static void main(String... args) throws Exception { |
mcimadamore@221 | 497 | new T6769027().test(); |
mcimadamore@221 | 498 | } |
mcimadamore@221 | 499 | } |