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