test/tools/javac/diags/RunExamples.java

Tue, 07 Sep 2010 17:32:27 +0100

author
mcimadamore
date
Tue, 07 Sep 2010 17:32:27 +0100
changeset 674
584365f256a7
parent 610
3640b60bd0f6
child 795
7b99f98b3035
permissions
-rw-r--r--

6979327: method handle invocation should use casts instead of type parameters to specify return type
Summary: infer return type for polymorphic signature calls according to updated JSR 292 draft
Reviewed-by: jjg
Contributed-by: john.r.rose@oracle.com

jjg@610 1 /*
jjg@610 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
jjg@610 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@610 4 *
jjg@610 5 * This code is free software; you can redistribute it and/or modify it
jjg@610 6 * under the terms of the GNU General Public License version 2 only, as
jjg@610 7 * published by the Free Software Foundation.
jjg@610 8 *
jjg@610 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@610 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@610 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@610 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@610 13 * accompanied this code).
jjg@610 14 *
jjg@610 15 * You should have received a copy of the GNU General Public License version
jjg@610 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@610 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@610 18 *
jjg@610 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@610 20 * or visit www.oracle.com if you need additional information or have any
jjg@610 21 * questions.
jjg@610 22 */
jjg@610 23
jjg@610 24 /**
jjg@610 25 * @test
jjg@610 26 * @bug 6968063
jjg@610 27 * @summary provide examples of code that generate diagnostics
jjg@610 28 * @build Example HTMLWriter RunExamples
jjg@610 29 * @run main RunExamples
jjg@610 30 */
jjg@610 31
jjg@610 32 import java.io.*;
jjg@610 33 import java.text.SimpleDateFormat;
jjg@610 34 import java.util.*;
jjg@610 35 import java.util.regex.Matcher;
jjg@610 36 import java.util.regex.Pattern;
jjg@610 37
jjg@610 38 /**
jjg@610 39 * Utility to run selected or all examples, writing results to
jjg@610 40 * stdout, a plain text file or an HTML file. This program can be
jjg@610 41 * run standalone, or as a jtreg test.
jjg@610 42 *
jjg@610 43 * Options:
jjg@610 44 * -examples dir directory of examples. Defaults to ${test.src}/examples
jjg@610 45 * -raw run examples with -XDrawDiagnostics
jjg@610 46 * -showFiles include text of source files in the output
jjg@610 47 * -verbose verbose output
jjg@610 48 * -o file write output to file: format will be HTML if
jjg@610 49 * file has .html extension; otherwise it will be plain text.
jjg@610 50 * default is to stdout
jjg@610 51 * -title string specify a title, only applies to HTML output
jjg@610 52 */
jjg@610 53 public class RunExamples {
jjg@610 54 public static void main(String... args) throws Exception {
jjg@610 55 boolean jtreg = (System.getProperty("test.src") != null);
jjg@610 56 File tmpDir;
jjg@610 57 if (jtreg) {
jjg@610 58 // use standard jtreg scratch directory: the current directory
jjg@610 59 tmpDir = new File(System.getProperty("user.dir"));
jjg@610 60 } else {
jjg@610 61 tmpDir = new File(System.getProperty("java.io.tmpdir"),
jjg@610 62 RunExamples.class.getName()
jjg@610 63 + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date()));
jjg@610 64 }
jjg@610 65 Example.setTempDir(tmpDir);
jjg@610 66
jjg@610 67 RunExamples r = new RunExamples();
jjg@610 68
jjg@610 69 try {
jjg@610 70 if (r.run(args))
jjg@610 71 return;
jjg@610 72 } finally {
jjg@610 73 /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the
jjg@610 74 * jtreg scratch directory, which is the current directory.
jjg@610 75 * In case someone is faking jtreg mode, make sure to only
jjg@610 76 * clean tmpDir when it is reasonable to do so.
jjg@610 77 */
jjg@610 78 if (tmpDir.isDirectory() &&
jjg@610 79 tmpDir.getName().startsWith(RunExamples.class.getName())) {
jjg@610 80 if (clean(tmpDir))
jjg@610 81 tmpDir.delete();
jjg@610 82 }
jjg@610 83 }
jjg@610 84
jjg@610 85 if (jtreg)
jjg@610 86 throw new Exception(r.errors + " errors occurred");
jjg@610 87 else
jjg@610 88 System.exit(1);
jjg@610 89 }
jjg@610 90
jjg@610 91 boolean run(String... args) {
jjg@610 92 Set<String> selectedKeys = new TreeSet<String>();
jjg@610 93 Set<Example> selectedExamples = new TreeSet<Example>();
jjg@610 94 File testSrc = new File(System.getProperty("test.src", "."));
jjg@610 95 File examplesDir = new File(testSrc, "examples");
jjg@610 96 File outFile = null;
jjg@610 97 boolean raw = false;
jjg@610 98 boolean showFiles = false;
jjg@610 99 boolean verbose = false;
jjg@610 100 String title = null;
jjg@610 101
jjg@610 102 for (int i = 0; i < args.length; i++) {
jjg@610 103 String arg = args[i];
jjg@610 104 if (arg.equals("-k") && (i + 1) < args.length)
jjg@610 105 selectedKeys.add(args[++i]);
jjg@610 106 else if (arg.equals("-examples") && (i + 1) < args.length)
jjg@610 107 examplesDir = new File(args[++i]);
jjg@610 108 else if (arg.equals("-raw"))
jjg@610 109 raw = true;
jjg@610 110 else if (arg.equals("-showFiles"))
jjg@610 111 showFiles = true;
jjg@610 112 else if (arg.equals("-verbose"))
jjg@610 113 verbose = true;
jjg@610 114 else if (arg.equals("-o") && (i + 1) < args.length)
jjg@610 115 outFile = new File(args[++i]);
jjg@610 116 else if (arg.equals("-title") && (i + 1) < args.length)
jjg@610 117 title = args[++i];
jjg@610 118 else if (arg.startsWith("-")) {
jjg@610 119 error("unknown option: " + arg);
jjg@610 120 return false;
jjg@610 121 } else {
jjg@610 122 while (i < args.length) {
jjg@610 123 File f = new File(examplesDir, args[i]);
jjg@610 124 selectedExamples.add(new Example(f));
jjg@610 125 i++;
jjg@610 126 }
jjg@610 127 }
jjg@610 128 }
jjg@610 129
jjg@610 130 if (selectedKeys.size() > 0) {
jjg@610 131 Set<Example> examples = getExamples(examplesDir);
jjg@610 132 nextKey:
jjg@610 133 for (String k: selectedKeys) {
jjg@610 134 for (Example e: examples) {
jjg@610 135 if (e.getDeclaredKeys().contains(k))
jjg@610 136 continue nextKey;
jjg@610 137 }
jjg@610 138 error("Key " + k + ": no examples found");
jjg@610 139 }
jjg@610 140 } else {
jjg@610 141 if (selectedExamples.size() == 0)
jjg@610 142 selectedExamples = getExamples(examplesDir);
jjg@610 143 }
jjg@610 144
jjg@610 145 try {
jjg@610 146 Runner r;
jjg@610 147 if (outFile == null) {
jjg@610 148 PrintWriter out = new PrintWriter(System.out);
jjg@610 149 r = new TextRunner(out, showFiles, raw, verbose);
jjg@610 150 } else if (outFile.getName().endsWith(".html"))
jjg@610 151 r = new HTMLRunner(outFile, showFiles, raw, verbose, title);
jjg@610 152 else
jjg@610 153 r = new TextRunner(outFile, showFiles, raw, verbose);
jjg@610 154 r.run(selectedExamples);
jjg@610 155 r.close();
jjg@610 156 } catch (IOException e) {
jjg@610 157 error("Error writing output: " + e);
jjg@610 158 }
jjg@610 159
jjg@610 160 return (errors == 0);
jjg@610 161 }
jjg@610 162
jjg@610 163 /**
jjg@610 164 * Get the complete set of examples to be checked.
jjg@610 165 */
jjg@610 166 Set<Example> getExamples(File examplesDir) {
jjg@610 167 Set<Example> results = new TreeSet<Example>();
jjg@610 168 for (File f: examplesDir.listFiles()) {
jjg@610 169 if (f.isDirectory() || f.isFile() && f.getName().endsWith(".java"))
jjg@610 170 results.add(new Example(f));
jjg@610 171 }
jjg@610 172 return results;
jjg@610 173 }
jjg@610 174
jjg@610 175 /**
jjg@610 176 * Report an error.
jjg@610 177 */
jjg@610 178 void error(String msg) {
jjg@610 179 System.err.println("Error: " + msg);
jjg@610 180 errors++;
jjg@610 181 }
jjg@610 182
jjg@610 183 int errors;
jjg@610 184
jjg@610 185 /**
jjg@610 186 * Clean the contents of a directory.
jjg@610 187 */
jjg@610 188 static boolean clean(File dir) {
jjg@610 189 boolean ok = true;
jjg@610 190 for (File f: dir.listFiles()) {
jjg@610 191 if (f.isDirectory())
jjg@610 192 ok &= clean(f);
jjg@610 193 ok &= f.delete();
jjg@610 194 }
jjg@610 195 return ok;
jjg@610 196 }
jjg@610 197
jjg@610 198 static abstract class Runner {
jjg@610 199 Runner(boolean showFiles, boolean raw, boolean verbose) {
jjg@610 200 this.showFiles = showFiles;
jjg@610 201 this.raw = raw;
jjg@610 202 this.verbose = verbose;
jjg@610 203 }
jjg@610 204
jjg@610 205 void close() throws IOException { }
jjg@610 206
jjg@610 207 void run(Collection<Example> examples) throws IOException {
jjg@610 208 for (Example e: examples) {
jjg@610 209 startExample(e);
jjg@610 210 if (showFiles) {
jjg@610 211 showFile(e, e.infoFile);
jjg@610 212 Set<File> srcFiles = new TreeSet<File>(e.srcFiles);
jjg@610 213 srcFiles.remove(e.infoFile);
jjg@610 214 showFiles(e, srcFiles);
jjg@610 215 showFiles(e, e.srcPathFiles);
jjg@610 216 showFiles(e, e.procFiles);
jjg@610 217 showFiles(e, e.supportFiles);
jjg@610 218 }
jjg@610 219 run(e);
jjg@610 220 }
jjg@610 221 }
jjg@610 222
jjg@610 223 void showFiles(Example e, Collection<File> files) throws IOException {
jjg@610 224 for (File f: files)
jjg@610 225 showFile(e, f);
jjg@610 226 }
jjg@610 227
jjg@610 228 abstract void startExample(Example e) throws IOException;
jjg@610 229
jjg@610 230 abstract void showFile(Example e, File f) throws IOException;
jjg@610 231
jjg@610 232 abstract void run(Example e) throws IOException;
jjg@610 233
jjg@610 234 protected String read(File f) throws IOException {
jjg@610 235 byte[] bytes = new byte[(int) f.length()];
jjg@610 236 DataInputStream in = new DataInputStream(new FileInputStream(f));
jjg@610 237 try {
jjg@610 238 in.readFully(bytes);
jjg@610 239 } finally {
jjg@610 240 in.close();
jjg@610 241 }
jjg@610 242 return new String(bytes);
jjg@610 243 }
jjg@610 244
jjg@610 245 protected Pattern copyrightHeaderPat =
jjg@610 246 Pattern.compile("(?s)(/\\*.*?Copyright.*?\\*/\n)\\s*(.*)");
jjg@610 247 protected Pattern infoHeaderPat =
jjg@610 248 Pattern.compile("(?s)((?://\\s*[a-z]+:[^\n]*\n)+)\\s*(.*)");
jjg@610 249
jjg@610 250 protected boolean showFiles;
jjg@610 251 protected boolean raw;
jjg@610 252 protected boolean verbose;
jjg@610 253 }
jjg@610 254
jjg@610 255 static class TextRunner extends Runner {
jjg@610 256 TextRunner(File file, boolean showFiles, boolean raw, boolean verbose)
jjg@610 257 throws IOException {
jjg@610 258 super(showFiles, raw, verbose);
jjg@610 259 this.file = file;
jjg@610 260 out = new PrintWriter(new FileWriter(file));
jjg@610 261 }
jjg@610 262
jjg@610 263 TextRunner(PrintWriter out, boolean showFiles, boolean raw, boolean verbose)
jjg@610 264 throws IOException {
jjg@610 265 super(showFiles, raw, verbose);
jjg@610 266 this.out = out;
jjg@610 267 }
jjg@610 268
jjg@610 269 @Override
jjg@610 270 void close() {
jjg@610 271 if (file != null)
jjg@610 272 out.close();
jjg@610 273 }
jjg@610 274
jjg@610 275 @Override
jjg@610 276 void startExample(Example e) {
jjg@610 277 out.println("----- " + e.getName() + " --------------------");
jjg@610 278 out.println();
jjg@610 279 }
jjg@610 280
jjg@610 281 @Override
jjg@610 282 void showFile(Example e, File f) {
jjg@610 283 out.println("--- " + f);
jjg@610 284 String text;
jjg@610 285 try {
jjg@610 286 text = read(f);
jjg@610 287 } catch (IOException ex) {
jjg@610 288 text = "Error reading " + f + "; " + ex;
jjg@610 289 }
jjg@610 290 Matcher m = copyrightHeaderPat.matcher(text);
jjg@610 291 if (m.matches()) {
jjg@610 292 out.println("(Copyright)");
jjg@610 293 writeLines(m.group(2));
jjg@610 294 } else {
jjg@610 295 writeLines(text);
jjg@610 296 }
jjg@610 297 out.println();
jjg@610 298 }
jjg@610 299
jjg@610 300 @Override
jjg@610 301 void run(Example e) {
jjg@610 302 // only show Output: header if also showing files
jjg@610 303 if (showFiles)
jjg@610 304 out.println("--- Output:");
jjg@610 305 e.run(out, raw, verbose);
jjg@610 306 out.println();
jjg@610 307 }
jjg@610 308
jjg@610 309 void writeLines(String text) {
jjg@610 310 for (String line: text.split("\n"))
jjg@610 311 out.println(line);
jjg@610 312 }
jjg@610 313
jjg@610 314 File file;
jjg@610 315 PrintWriter out;
jjg@610 316 }
jjg@610 317
jjg@610 318 static class HTMLRunner extends Runner {
jjg@610 319 HTMLRunner(File file, boolean showFiles, boolean raw, boolean verbose, String title)
jjg@610 320 throws IOException {
jjg@610 321 super(showFiles, raw, verbose);
jjg@610 322 this.file = file;
jjg@610 323 PrintWriter out = new PrintWriter(new FileWriter(file));
jjg@610 324 html = new HTMLWriter(out);
jjg@610 325 html.startTag(HTMLWriter.HEAD);
jjg@610 326 if (title != null) {
jjg@610 327 html.startTag(HTMLWriter.TITLE);
jjg@610 328 html.write(title);
jjg@610 329 html.endTag(HTMLWriter.TITLE);
jjg@610 330 }
jjg@610 331 html.startTag(HTMLWriter.STYLE);
jjg@610 332 html.newLine();
jjg@610 333 html.writeLine("div.file { background-color:#e0ffe0; margin-left:30px; margin-right:30px;\n"
jjg@610 334 + " padding: 3px; border: thin solid silver; }");
jjg@610 335 html.writeLine("p.file { white-space: pre-wrap; font-family:monospace; margin: 0; }");
jjg@610 336 html.writeLine("div.output { background-color:#e0e0ff; margin-left:30px; margin-right:30px;\n"
jjg@610 337 + " padding: 3px; border: thin solid silver; }");
jjg@610 338 html.writeLine("p.output { white-space: pre-wrap; font-family:monospace; margin: 0; }");
jjg@610 339 html.writeLine("table.index { border: thin solid silver; }");
jjg@610 340 html.writeLine(".copyright { font-size: x-small }");
jjg@610 341 html.writeLine(".hidden { display:none }");
jjg@610 342 html.writeLine(".unhidden { display:block }");
jjg@610 343 html.writeLine(".odd { background-color: #e0e0e0 }");
jjg@610 344 html.writeLine(".even { background-color: white }");
jjg@610 345 html.endTag(HTMLWriter.STYLE);
jjg@610 346 html.startTag(HTMLWriter.SCRIPT);
jjg@610 347 html.writeAttr(HTMLWriter.TYPE, HTMLWriter.TEXT_JAVASCRIPT);
jjg@610 348 html.writeLine("\nfunction unhide(id) {\n"
jjg@610 349 + " var item = document.getElementById(id);\n"
jjg@610 350 + " if (item) {\n"
jjg@610 351 + " item.className=(item.className=='hidden')?'unhidden':'hidden';\n"
jjg@610 352 + " }\n"
jjg@610 353 + "}");
jjg@610 354 html.endTag(HTMLWriter.SCRIPT);
jjg@610 355 html.endTag(HTMLWriter.HEAD);
jjg@610 356 html.startTag(HTMLWriter.BODY);
jjg@610 357 if (title != null) {
jjg@610 358 html.startTag(TITLE_HEADER);
jjg@610 359 html.write(title);
jjg@610 360 html.endTag(TITLE_HEADER);
jjg@610 361 }
jjg@610 362 }
jjg@610 363
jjg@610 364 @Override
jjg@610 365 void close() throws IOException {
jjg@610 366 html.endTag(HTMLWriter.BODY);
jjg@610 367 html.newLine();
jjg@610 368 html.flush();
jjg@610 369 }
jjg@610 370
jjg@610 371 @Override
jjg@610 372 void run(Collection<Example> examples) throws IOException {
jjg@610 373 if (examples.size() > 1)
jjg@610 374 writeIndex(examples);
jjg@610 375 super.run(examples);
jjg@610 376 }
jjg@610 377
jjg@610 378 void writeIndex(Collection<Example> examples) throws IOException {
jjg@610 379 Map<String, Set<Example>> index = new TreeMap<String, Set<Example>>();
jjg@610 380 Set<String> initials = new HashSet<String>();
jjg@610 381 for (Example e: examples) {
jjg@610 382 for (String k: e.getDeclaredKeys()) {
jjg@610 383 Set<Example> s = index.get(k);
jjg@610 384 if (s == null)
jjg@610 385 index.put(k, s = new TreeSet<Example>());
jjg@610 386 s.add(e);
jjg@610 387 }
jjg@610 388 initials.add(e.getName().substring(0, 1).toUpperCase());
jjg@610 389 }
jjg@610 390
jjg@610 391
jjg@610 392 if (INDEX_HEADER != null) {
jjg@610 393 html.startTag(INDEX_HEADER);
jjg@610 394 html.write("Index");
jjg@610 395 html.endTag(INDEX_HEADER);
jjg@610 396 }
jjg@610 397
jjg@610 398 html.startTag(HTMLWriter.P);
jjg@610 399 html.writeLine("Examples: ");
jjg@610 400 for (char initial = 'A'; initial <= 'Z'; initial++) {
jjg@610 401 String s = String.valueOf(initial);
jjg@610 402 if (initials.contains(s)) {
jjg@610 403 html.writeLink("#" + s, s);
jjg@610 404 } else {
jjg@610 405 html.write(s);
jjg@610 406 }
jjg@610 407 html.newLine();
jjg@610 408 }
jjg@610 409 html.endTag(HTMLWriter.P);
jjg@610 410
jjg@610 411 html.startTag(HTMLWriter.TABLE);
jjg@610 412 html.writeAttr(HTMLWriter.CLASS, "index");
jjg@610 413 html.newLine();
jjg@610 414 int row = 0;
jjg@610 415 for (Map.Entry<String, Set<Example>> entry: index.entrySet()) {
jjg@610 416 html.startTag(HTMLWriter.TR);
jjg@610 417 html.writeAttr(HTMLWriter.CLASS,
jjg@610 418 (row++ % 2 == 0 ? "even" : "odd"));
jjg@610 419 html.startTag(HTMLWriter.TD);
jjg@610 420 html.writeAttr("valign", "top");
jjg@610 421 html.write(entry.getKey());
jjg@610 422 html.endTag(HTMLWriter.TD);
jjg@610 423 html.newLine();
jjg@610 424 html.startTag(HTMLWriter.TD);
jjg@610 425 html.writeAttr(HTMLWriter.ALIGN, "top");
jjg@610 426 String sep = "";
jjg@610 427 for (Example e: entry.getValue()) {
jjg@610 428 html.write(sep);
jjg@610 429 html.writeLink('#' + e.getName(), e.getName());
jjg@610 430 sep = ", ";
jjg@610 431 }
jjg@610 432 html.endTag(HTMLWriter.TD);
jjg@610 433 html.endTag(HTMLWriter.TR);
jjg@610 434 html.newLine();
jjg@610 435 }
jjg@610 436 html.endTag(HTMLWriter.TABLE);
jjg@610 437 }
jjg@610 438
jjg@610 439 @Override
jjg@610 440 void startExample(Example e) throws IOException {
jjg@610 441 String name = e.getName();
jjg@610 442 String initial = name.substring(0, 1).toUpperCase();
jjg@610 443 if (!initial.equals(currInitial)) {
jjg@610 444 html.writeLinkDestination(initial, "");
jjg@610 445 currInitial = initial;
jjg@610 446 }
jjg@610 447 html.writeLinkDestination(name, "");
jjg@610 448 html.startTag(EXAMPLE_HEADER);
jjg@610 449 html.write(e.getName());
jjg@610 450 html.endTag(EXAMPLE_HEADER);
jjg@610 451 }
jjg@610 452
jjg@610 453 @Override
jjg@610 454 void showFile(Example e, File f) throws IOException {
jjg@610 455 String text;
jjg@610 456 try {
jjg@610 457 text = read(f);
jjg@610 458 } catch (IOException ex) {
jjg@610 459 text = "Error reading " + f + ": " + ex;
jjg@610 460 }
jjg@610 461 if (!f.equals(e.file)) {
jjg@610 462 html.startTag(FILE_HEADER);
jjg@610 463 html.write(e.file.toURI().relativize(f.toURI()).toString());
jjg@610 464 html.endTag(FILE_HEADER);
jjg@610 465 }
jjg@610 466 html.startTag(HTMLWriter.DIV);
jjg@610 467 html.writeAttr(CLASS, FILE);
jjg@610 468
jjg@610 469 String legalHeader;
jjg@610 470 Matcher m1 = copyrightHeaderPat.matcher(text);
jjg@610 471 if (m1.matches()) {
jjg@610 472 legalHeader = m1.group(1);
jjg@610 473 text = m1.group(2);
jjg@610 474 } else
jjg@610 475 legalHeader = null;
jjg@610 476
jjg@610 477 String infoHeader;
jjg@610 478 Matcher m2 = infoHeaderPat.matcher(text);
jjg@610 479 if (m2.matches()) {
jjg@610 480 infoHeader = m2.group(1);
jjg@610 481 text = m2.group(2);
jjg@610 482 } else
jjg@610 483 infoHeader = null;
jjg@610 484
jjg@610 485 String legalId = null, infoId = null;
jjg@610 486 if (legalHeader != null || infoHeader != null) {
jjg@610 487 String sep = "";
jjg@610 488 html.startTag(HTMLWriter.SPAN);
jjg@610 489 html.writeStyleAttr("float: right");
jjg@610 490 if (legalHeader != null) {
jjg@610 491 legalId = nextId();
jjg@610 492 html.startTag(HTMLWriter.A);
jjg@610 493 html.writeAttr(HTMLWriter.HREF, "javascript:unhide('" + legalId + "');");
jjg@610 494 //html.writeEntity("&copy;");
jjg@610 495 html.write("Copyright");
jjg@610 496 html.endTag(HTMLWriter.A);
jjg@610 497 sep = ", ";
jjg@610 498 }
jjg@610 499 if (infoHeader != null) {
jjg@610 500 html.write(sep);
jjg@610 501 infoId = nextId();
jjg@610 502 html.startTag(HTMLWriter.A);
jjg@610 503 html.writeAttr(HTMLWriter.HREF, "javascript:unhide('" + infoId + "');");
jjg@610 504 html.write("Info");
jjg@610 505 html.endTag(HTMLWriter.A);
jjg@610 506 sep = ", ";
jjg@610 507 }
jjg@610 508 html.endTag(HTMLWriter.SPAN);
jjg@610 509 }
jjg@610 510
jjg@610 511 html.startTag(HTMLWriter.P);
jjg@610 512 html.writeAttr(CLASS, FILE);
jjg@610 513 if (legalHeader != null) {
jjg@610 514 html.startTag(HTMLWriter.SPAN);
jjg@610 515 html.writeAttr(HTMLWriter.CLASS, "hidden");
jjg@610 516 html.writeAttr(HTMLWriter.ID, legalId);
jjg@610 517 html.write(legalHeader);
jjg@610 518 html.newLine();
jjg@610 519 html.endTag(HTMLWriter.SPAN);
jjg@610 520 }
jjg@610 521 if (infoHeader != null) {
jjg@610 522 html.startTag(HTMLWriter.SPAN);
jjg@610 523 html.writeAttr(HTMLWriter.CLASS, "hidden");
jjg@610 524 html.writeAttr(HTMLWriter.ID, infoId);
jjg@610 525 html.write(infoHeader);
jjg@610 526 html.newLine();
jjg@610 527 html.endTag(HTMLWriter.SPAN);
jjg@610 528 }
jjg@610 529 html.write(text);
jjg@610 530 html.endTag(HTMLWriter.P);
jjg@610 531
jjg@610 532 html.endTag(HTMLWriter.DIV);
jjg@610 533 }
jjg@610 534
jjg@610 535 @Override
jjg@610 536 void run(Example e) throws IOException {
jjg@610 537 StringWriter sw = new StringWriter();
jjg@610 538 PrintWriter pw = new PrintWriter(sw);
jjg@610 539 e.run(pw, raw, verbose);
jjg@610 540 pw.flush();
jjg@610 541
jjg@610 542 // only show Output: header if also showing files
jjg@610 543 if (showFiles) {
jjg@610 544 html.startTag(OUTPUT_HEADER);
jjg@610 545 html.write("Output:");
jjg@610 546 html.endTag(OUTPUT_HEADER);
jjg@610 547 }
jjg@610 548
jjg@610 549 html.startTag(HTMLWriter.DIV);
jjg@610 550 html.writeAttr(CLASS, OUTPUT);
jjg@610 551 html.startTag(HTMLWriter.P);
jjg@610 552 html.writeAttr(CLASS, OUTPUT);
jjg@610 553 String[] lines = sw.toString().split("\n");
jjg@610 554 for (String line: lines) {
jjg@610 555 html.write(line);
jjg@610 556 html.newLine();
jjg@610 557 }
jjg@610 558 html.endTag(HTMLWriter.P);
jjg@610 559 html.endTag(HTMLWriter.DIV);
jjg@610 560 }
jjg@610 561
jjg@610 562 String nextId() {
jjg@610 563 return "id" + (nextId++);
jjg@610 564 }
jjg@610 565
jjg@610 566 File file;
jjg@610 567 HTMLWriter html;
jjg@610 568 int nextId;
jjg@610 569 String currInitial = "";
jjg@610 570
jjg@610 571 static final String TITLE_HEADER = HTMLWriter.H3;
jjg@610 572 static final String INDEX_HEADER = HTMLWriter.H4;
jjg@610 573 static final String EXAMPLE_HEADER = HTMLWriter.H4;
jjg@610 574 static final String FILE_HEADER = HTMLWriter.H5;
jjg@610 575 static final String OUTPUT_HEADER = HTMLWriter.H5;
jjg@610 576 static final String CLASS = "class";
jjg@610 577 static final String FILE = "file";
jjg@610 578 static final String OUTPUT = "output";
jjg@610 579 }
jjg@610 580 }
jjg@610 581
jjg@610 582

mercurial