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