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