langtools/test/tools/javac/options/modes/Tester.java
author jjg
Fri, 22 Aug 2014 16:28:16 -0700
changeset 26264 a09fedde76be
child 34560 b6a567b677f7
permissions -rw-r--r--
8044859: javac duplicates option processing when using Compiler API Reviewed-by: mcimadamore, vromero, jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     1
/*
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     4
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     8
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    13
 * accompanied this code).
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    14
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    18
 *
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    21
 * questions.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    22
 */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    23
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    24
import com.sun.tools.javac.api.JavacTool;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    25
import com.sun.tools.javac.file.JavacFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    26
import com.sun.tools.javac.util.Context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    27
import java.io.ByteArrayOutputStream;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    28
import java.io.FileWriter;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    29
import java.io.IOException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    30
import java.io.PrintStream;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    31
import java.io.PrintWriter;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    32
import java.io.StringWriter;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    33
import java.lang.annotation.Annotation;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    34
import java.lang.annotation.Retention;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    35
import java.lang.annotation.RetentionPolicy;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    37
import java.lang.reflect.Method;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    38
import java.nio.file.Files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    39
import java.nio.file.Path;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    40
import java.nio.file.Paths;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    41
import java.util.ArrayList;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    42
import java.util.Arrays;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    43
import java.util.EnumMap;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    44
import java.util.Iterator;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    45
import java.util.List;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    46
import java.util.Map;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    47
import java.util.stream.Collectors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    48
import javax.tools.JavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    49
import javax.tools.JavaFileObject;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    50
import javax.tools.StandardJavaFileManager;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    51
import javax.tools.ToolProvider;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    52
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    53
public class Tester {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    54
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    55
    /** Marker annotation for test methods to be invoked by runTests. */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    56
    @Retention(RetentionPolicy.RUNTIME)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    57
    @interface Test { }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    58
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    59
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    60
     * Run all methods annotated with @Test, and throw an exception if any
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    61
     * errors are reported..
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    62
     * Typically called on a tester object in main()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    63
     * @throws Exception if any errors occurred
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    64
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    65
    void runTests() throws Exception {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    66
        for (Method m: getClass().getDeclaredMethods()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    67
            Annotation a = m.getAnnotation(Test.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    68
            if (a != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    69
                try {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    70
                    out.println("Running test " + m.getName());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    71
                    m.invoke(this);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    72
                } catch (InvocationTargetException e) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    73
                    Throwable cause = e.getCause();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    74
                    throw (cause instanceof Exception) ? ((Exception) cause) : e;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    75
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    76
                out.println();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    77
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    78
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    79
        if (errors > 0)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    80
            throw new Exception(errors + " errors occurred");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    81
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    82
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    83
    TestResult runMain(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    84
        out.println("Main " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    85
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    86
            com.sun.tools.javac.main.Main compiler =
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    87
                new com.sun.tools.javac.main.Main("javac", pw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    88
            int rc = compiler.compile(join(opts, files), c).exitCode;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    89
            tr.setResult(rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    90
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    91
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    92
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    93
    TestResult runCall(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    94
        out.println("Call " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    95
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    96
            boolean ok = JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    97
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    98
                    .call();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
    99
            tr.setResult(ok);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   100
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   101
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   102
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   103
    TestResult runParse(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   104
        out.println("Parse " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   105
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   106
            JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   107
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   108
                    .parse();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   109
            tr.setResult(true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   110
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   111
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   112
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   113
    TestResult runAnalyze(String[] opts, String[] files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   114
        out.println("Analyze " + Arrays.toString(opts) + " " + Arrays.toString(files));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   115
        return run(new TestResult(opts), (tr, c, pw) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   116
            JavacTool.create()
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   117
                    .getTask(pw, null, null, Arrays.asList(opts), null, getFiles(files), c)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   118
                    .analyze();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   119
            tr.setResult(true);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   120
        });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   121
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   122
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   123
    interface Runnable {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   124
        void run(TestResult tr, Context c, PrintWriter pw) throws IOException;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   125
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   126
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   127
    TestResult run(TestResult tr, Runnable r) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   128
        StringWriter sw = new StringWriter();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   129
        PrintWriter pw = new PrintWriter(sw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   130
        StreamOutput sysOut = new StreamOutput(System.out, System::setOut);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   131
        StreamOutput sysErr = new StreamOutput(System.err, System::setErr);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   132
        Context context = new Context();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   133
        JavacFileManager.preRegister(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   134
        try {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   135
            r.run(tr, context, pw);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   136
        } catch (IllegalArgumentException | IllegalStateException | IOException e) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   137
            tr.setThrown(e);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   138
        } finally {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   139
            ((JavacFileManager) context.get(JavaFileManager.class)).close();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   140
            tr.setLogs(sw.toString(), sysOut.close(), sysErr.close());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   141
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   142
        tr.setContext(context);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   143
        tr.show();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   144
        return tr;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   145
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   146
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   147
    enum Log { DIRECT, STDOUT, STDERR };
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   148
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   149
    class TestResult {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   150
        final List<String> args;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   151
        Throwable thrown;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   152
        Object rc; // Number or Boolean
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   153
        Map<Log, String> logs;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   154
        Context context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   155
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   156
        TestResult(String... args) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   157
            this.args = Arrays.asList(args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   158
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   159
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   160
        TestResult(List<String> args, Iterable<? extends JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   161
            this.args = new ArrayList<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   162
            this.args.addAll(args);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   163
            for (JavaFileObject f: files)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   164
                this.args.add(f.getName());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   165
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   166
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   167
        void setResult(int rc) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   168
            this.rc = rc;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   169
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   170
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   171
        void setResult(boolean ok) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   172
            this.rc = ok ? 0 : 1;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   173
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   174
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   175
        void setThrown(Throwable thrown) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   176
            this.thrown = thrown;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   177
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   178
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   179
        void setLogs(String direct, String stdOut, String stdErr) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   180
            logs = new EnumMap<>(Log.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   181
            logs.put(Log.DIRECT, direct);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   182
            logs.put(Log.STDOUT, stdOut);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   183
            logs.put(Log.STDERR, stdErr);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   184
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   185
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   186
        void setContext(Context context) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   187
            this.context = context;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   188
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   189
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   190
        final void show() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   191
            String NL = System.getProperty("line.separator");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   192
            boolean needSep = false;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   193
            if (rc != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   194
                out.print("rc:" + rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   195
                needSep = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   196
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   197
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   198
                if (needSep) out.print("; ");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   199
                out.print("thrown:" + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   200
                needSep = true;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   201
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   202
            if (needSep)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   203
                out.println();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   204
            logs.forEach((k, v) -> {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   205
                if (!v.isEmpty()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   206
                    out.println("javac/" + k + ":");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   207
                    if (v.endsWith(NL))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   208
                        out.print(v);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   209
                    else
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   210
                        out.println(v);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   211
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   212
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   213
            });
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   214
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   215
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   216
        TestResult checkOK() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   217
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   218
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   219
            } else if (rc == null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   220
                error("no result set");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   221
            } else if (rc != (Integer) 0 && rc != (Boolean) true) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   222
                error("compilation failed unexpectedly; rc=" + rc);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   223
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   224
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   225
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   226
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   227
        TestResult checkResult(int expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   228
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   229
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   230
            } else if (rc != (Integer) expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   231
                error("unexpected result: " + rc +", expected:" + expect);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   232
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   233
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   234
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   235
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   236
        TestResult checkResult(boolean expect) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   237
            if (thrown != null) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   238
                error("unexpected exception thrown: " + thrown);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   239
            } else if (rc != (Integer) (expect ? 0 : 1)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   240
                error("unexpected result: " + rc +", expected:" + expect);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   241
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   242
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   243
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   244
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   245
        TestResult checkLog(String... expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   246
            return checkLog(Log.DIRECT, expects);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   247
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   248
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   249
        TestResult checkLog(Log l, String... expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   250
            for (String e: expects) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   251
                if (!logs.get(l).contains(e))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   252
                    error("expected string not found: " + e);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   253
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   254
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   255
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   256
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   257
        TestResult checkIllegalArgumentException() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   258
            return checkThrown(IllegalArgumentException.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   259
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   260
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   261
        TestResult checkIllegalStateException() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   262
            return checkThrown(IllegalStateException.class);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   263
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   265
        TestResult checkThrown(Class<? extends Throwable> t) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   266
            if (thrown == null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   267
                error("expected exception not thrown: " + t);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   268
            else if (!t.isAssignableFrom(thrown.getClass()))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   269
                error("unexpected exception thrown: " + thrown + ";  expected: " + t);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   270
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   271
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   272
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   273
        TestResult checkClass(String name) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   274
            Path p = getOutDir().resolve(name.replace(".", "/") + ".class");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   275
            if (!Files.exists(p))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   276
                error("expected class not found: " + name + " (" + p + ")");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   277
            return this;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   278
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   279
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   280
        Path getOutDir() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   281
            Iterator<String> iter = args.iterator();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   282
            while (iter.hasNext()) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   283
                if (iter.next().equals("-d")) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   284
                    return Paths.get(iter.next());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   285
                }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   286
            }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   287
            return null;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   288
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   289
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   290
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   291
    /**
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   292
     * Utility class to simplify the handling of temporarily setting a
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   293
     * new stream for System.out or System.err.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   294
     */
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   295
    private static class StreamOutput {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   296
        // functional interface to set a stream.
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   297
        private interface Initializer {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   298
            void set(PrintStream s);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   299
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   300
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   301
        private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   302
        private final PrintStream ps = new PrintStream(baos);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   303
        private final PrintStream prev;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   304
        private final Initializer init;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   305
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   306
        StreamOutput(PrintStream s, Initializer init) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   307
            prev = s;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   308
            init.set(ps);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   309
            this.init = init;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   310
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   311
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   312
        String close() {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   313
            init.set(prev);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   314
            ps.close();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   315
            return baos.toString();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   316
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   317
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   318
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   319
    List<JavaFileObject> getFiles(String... paths) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   320
        List<JavaFileObject> files = new ArrayList<>();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   321
        for (JavaFileObject f : fm.getJavaFileObjects(paths))
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   322
            files.add(f);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   323
        return files;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   324
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   325
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   326
    String toString(List<JavaFileObject> files) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   327
        return files.stream().map(f -> f.getName()).collect(Collectors.toList()).toString();
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   328
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   329
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   330
    void mkdirs(String path) throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   331
        Files.createDirectories(Paths.get(path));
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   332
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   333
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   334
    void writeFile(String path, String body) throws IOException {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   335
        Path p = Paths.get(path);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   336
        if (p.getParent() != null)
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   337
            Files.createDirectories(p.getParent());
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   338
        try (FileWriter w = new FileWriter(path)) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   339
            w.write(body);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   340
        }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   341
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   342
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   343
    String[] join(String[] a, String[] b) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   344
        String[] result = new String[a.length + b.length];
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   345
        System.arraycopy(a, 0, result, 0, a.length);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   346
        System.arraycopy(b, 0, result, a.length, b.length);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   347
        return result;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   348
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   349
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   350
    void error(String message) {
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   351
        out.print(">>>>> ");
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   352
        out.println(message);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   353
        errors++;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   354
    }
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   355
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   356
    StandardJavaFileManager fm =
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   357
            ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   358
    PrintStream out = System.err;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   359
    int errors;
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   360
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents:
diff changeset
   361
}