author | jlahoda |
Fri, 15 Feb 2019 12:09:53 +0100 | |
changeset 53773 | 454d54d8af1c |
parent 49822 | 53aae0c219e6 |
child 54332 | 9a8fe0bc38c3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
49822
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.util; |
|
27 |
||
28 |
import java.io.*; |
|
1866 | 29 |
import java.util.Arrays; |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
30 |
import java.util.EnumMap; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
31 |
import java.util.EnumSet; |
10 | 32 |
import java.util.HashSet; |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
33 |
import java.util.Map; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
34 |
import java.util.Queue; |
10 | 35 |
import java.util.Set; |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
49822
diff
changeset
|
36 |
import java.util.function.Predicate; |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
37 |
|
10 | 38 |
import javax.tools.DiagnosticListener; |
39 |
import javax.tools.JavaFileObject; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
167
diff
changeset
|
40 |
|
6721 | 41 |
import com.sun.tools.javac.api.DiagnosticFormatter; |
11314 | 42 |
import com.sun.tools.javac.main.Main; |
43 |
import com.sun.tools.javac.main.Option; |
|
13077 | 44 |
import com.sun.tools.javac.tree.EndPosTable; |
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
45 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
49822
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
46 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticInfo; |
10 | 47 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
48 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
|
49 |
||
11314 | 50 |
import static com.sun.tools.javac.main.Option.*; |
6721 | 51 |
|
10 | 52 |
/** A class for error logs. Reports errors and warnings, and |
53 |
* keeps track of error numbers and positions. |
|
54 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
55 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
56 |
* If you write code that depends on this, you do so at your own risk. |
10 | 57 |
* This code and its internal interfaces are subject to change or |
58 |
* deletion without notice.</b> |
|
59 |
*/ |
|
867 | 60 |
public class Log extends AbstractLog { |
10 | 61 |
/** The context key for the log. */ |
22163 | 62 |
public static final Context.Key<Log> logKey = new Context.Key<>(); |
10 | 63 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
64 |
/** The context key for the standard output PrintWriter. */ |
22163 | 65 |
public static final Context.Key<PrintWriter> outKey = new Context.Key<>(); |
10 | 66 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
67 |
/** The context key for the diagnostic PrintWriter. */ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
68 |
public static final Context.Key<PrintWriter> errKey = new Context.Key<>(); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
69 |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
70 |
/* TODO: Should unify this with prefix handling in JCDiagnostic.Factory. */ |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
71 |
public enum PrefixKind { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
72 |
JAVAC("javac."), |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
73 |
COMPILER_MISC("compiler.misc."); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
74 |
PrefixKind(String v) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
75 |
value = v; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
76 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
77 |
public String key(String k) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
78 |
return value + k; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
79 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
80 |
final String value; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
81 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
82 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
83 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
84 |
* DiagnosticHandler's provide the initial handling for diagnostics. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
85 |
* When a diagnostic handler is created and has been initialized, it |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
86 |
* should install itself as the current diagnostic handler. When a |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
87 |
* client has finished using a handler, the client should call |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
88 |
* {@code log.removeDiagnosticHandler();} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
89 |
* |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
90 |
* Note that javax.tools.DiagnosticListener (if set) is called later in the |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
91 |
* diagnostic pipeline. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
92 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
93 |
public static abstract class DiagnosticHandler { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
94 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
95 |
* The previously installed diagnostic handler. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
96 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
97 |
protected DiagnosticHandler prev; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
98 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
99 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
100 |
* Install this diagnostic handler as the current one, |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
101 |
* recording the previous one. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
102 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
103 |
protected void install(Log log) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
104 |
prev = log.diagnosticHandler; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
105 |
log.diagnosticHandler = this; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
106 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
107 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
108 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
109 |
* Handle a diagnostic. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
110 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
111 |
public abstract void report(JCDiagnostic diag); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
112 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
113 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
114 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
115 |
* A DiagnosticHandler that discards all diagnostics. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
116 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
117 |
public static class DiscardDiagnosticHandler extends DiagnosticHandler { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
118 |
public DiscardDiagnosticHandler(Log log) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
119 |
install(log); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
120 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
121 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
122 |
@Override |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
123 |
public void report(JCDiagnostic diag) { } |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
124 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
125 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
126 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
127 |
* A DiagnosticHandler that can defer some or all diagnostics, |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
128 |
* by buffering them for later examination and/or reporting. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
129 |
* If a diagnostic is not deferred, or is subsequently reported |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
130 |
* with reportAllDiagnostics(), it will be reported to the previously |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
131 |
* active diagnostic handler. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
132 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
133 |
public static class DeferredDiagnosticHandler extends DiagnosticHandler { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
17582
diff
changeset
|
134 |
private Queue<JCDiagnostic> deferred = new ListBuffer<>(); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
135 |
private final Filter<JCDiagnostic> filter; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
136 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
137 |
public DeferredDiagnosticHandler(Log log) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
138 |
this(log, null); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
139 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
140 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
141 |
public DeferredDiagnosticHandler(Log log, Filter<JCDiagnostic> filter) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
142 |
this.filter = filter; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
143 |
install(log); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
144 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
145 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
146 |
@Override |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
147 |
public void report(JCDiagnostic diag) { |
16326
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
15385
diff
changeset
|
148 |
if (!diag.isFlagSet(JCDiagnostic.DiagnosticFlag.NON_DEFERRABLE) && |
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
15385
diff
changeset
|
149 |
(filter == null || filter.accepts(diag))) { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
150 |
deferred.add(diag); |
16326
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
15385
diff
changeset
|
151 |
} else { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
152 |
prev.report(diag); |
16326
9b94bafef533
8009227: Certain diagnostics should not be deferred
mcimadamore
parents:
15385
diff
changeset
|
153 |
} |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
154 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
155 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
156 |
public Queue<JCDiagnostic> getDiagnostics() { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
157 |
return deferred; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
158 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
159 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
160 |
/** Report all deferred diagnostics. */ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
161 |
public void reportDeferredDiagnostics() { |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
49822
diff
changeset
|
162 |
reportDeferredDiagnostics(d -> true); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
163 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
164 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
165 |
/** Report selected deferred diagnostics. */ |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
49822
diff
changeset
|
166 |
public void reportDeferredDiagnostics(Predicate<JCDiagnostic> accepter) { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
167 |
JCDiagnostic d; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
168 |
while ((d = deferred.poll()) != null) { |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
49822
diff
changeset
|
169 |
if (accepter.test(d)) |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
170 |
prev.report(d); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
171 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
172 |
deferred = null; // prevent accidental ongoing use |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
173 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
174 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
175 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
176 |
public enum WriterKind { NOTICE, WARNING, ERROR, STDOUT, STDERR } |
10 | 177 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
178 |
private final Map<WriterKind, PrintWriter> writers; |
10 | 179 |
|
180 |
/** The maximum number of errors/warnings that are reported. |
|
181 |
*/ |
|
11052 | 182 |
protected int MaxErrors; |
183 |
protected int MaxWarnings; |
|
10 | 184 |
|
185 |
/** Switch: prompt user on each error. |
|
186 |
*/ |
|
187 |
public boolean promptOnError; |
|
188 |
||
189 |
/** Switch: emit warning messages. |
|
190 |
*/ |
|
191 |
public boolean emitWarnings; |
|
192 |
||
3660 | 193 |
/** Switch: suppress note messages. |
194 |
*/ |
|
195 |
public boolean suppressNotes; |
|
196 |
||
10 | 197 |
/** Print stack trace on errors? |
198 |
*/ |
|
199 |
public boolean dumpOnError; |
|
200 |
||
201 |
/** |
|
202 |
* Diagnostic listener, if provided through programmatic |
|
203 |
* interface to javac (JSR 199). |
|
204 |
*/ |
|
205 |
protected DiagnosticListener<? super JavaFileObject> diagListener; |
|
867 | 206 |
|
10 | 207 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
208 |
* Formatter for diagnostics. |
10 | 209 |
*/ |
942 | 210 |
private DiagnosticFormatter<JCDiagnostic> diagFormatter; |
10 | 211 |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
212 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
213 |
* Keys for expected diagnostics. |
1866 | 214 |
*/ |
215 |
public Set<String> expectDiagKeys; |
|
216 |
||
217 |
/** |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
218 |
* Set to true if a compressed diagnostic is reported |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
219 |
*/ |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
220 |
public boolean compressedOutput; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
221 |
|
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
222 |
/** |
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
223 |
* JavacMessages object used for localization. |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
224 |
*/ |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
225 |
private JavacMessages messages; |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1109
diff
changeset
|
226 |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
227 |
/** |
15385 | 228 |
* Handler for initial dispatch of diagnostics. |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
229 |
*/ |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
230 |
private DiagnosticHandler diagnosticHandler; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
231 |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
232 |
/** Get the Log instance for this context. */ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
233 |
public static Log instance(Context context) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
234 |
Log instance = context.get(logKey); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
235 |
if (instance == null) |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
236 |
instance = new Log(context); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
237 |
return instance; |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
238 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
239 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
240 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
241 |
* Register a Context.Factory to create a Log. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
242 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
243 |
public static void preRegister(Context context, PrintWriter w) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
244 |
context.put(Log.class, (Context.Factory<Log>) (c -> new Log(c, w))); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
245 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
246 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
247 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
248 |
* Construct a log with default settings. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
249 |
* If no streams are set in the context, the log will be initialized to use |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
250 |
* System.out for normal output, and System.err for all diagnostic output. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
251 |
* If one stream is set in the context, with either Log.outKey or Log.errKey, |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
252 |
* it will be used for all output. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
253 |
* Otherwise, the log will be initialized to use both streams found in the context. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
254 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
255 |
protected Log(Context context) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
256 |
this(context, initWriters(context)); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
257 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
258 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
259 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
260 |
* Initialize a map of writers based on values found in the context |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
261 |
* @param context the context in which to find writers to use |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
262 |
* @return a map of writers |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
263 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
264 |
private static Map<WriterKind, PrintWriter> initWriters(Context context) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
265 |
PrintWriter out = context.get(outKey); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
266 |
PrintWriter err = context.get(errKey); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
267 |
if (out == null && err == null) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
268 |
out = new PrintWriter(System.out, true); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
269 |
err = new PrintWriter(System.err, true); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
270 |
return initWriters(out, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
271 |
} else if (out == null || err == null) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
272 |
PrintWriter pw = (out != null) ? out : err; |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
273 |
return initWriters(pw, pw); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
274 |
} else { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
275 |
return initWriters(out, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
276 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
277 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
278 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
279 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
280 |
* Construct a log with all output sent to a single output stream. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
281 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
282 |
protected Log(Context context, PrintWriter writer) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
283 |
this(context, initWriters(writer, writer)); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
284 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
285 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
286 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
287 |
* Construct a log. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
288 |
* The log will be initialized to use stdOut for normal output, and stdErr |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
289 |
* for all diagnostic output. |
10 | 290 |
*/ |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
291 |
protected Log(Context context, PrintWriter out, PrintWriter err) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
292 |
this(context, initWriters(out, err)); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
293 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
294 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
295 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
296 |
* Initialize a writer map for a stream for normal output, and a stream for diagnostics. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
297 |
* @param out a stream to be used for normal output |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
298 |
* @param err a stream to be used for diagnostic messages, such as errors, warnings, etc |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
299 |
* @return a map of writers |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
300 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
301 |
private static Map<WriterKind, PrintWriter> initWriters(PrintWriter out, PrintWriter err) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
302 |
Map<WriterKind, PrintWriter> writers = new EnumMap<>(WriterKind.class); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
303 |
writers.put(WriterKind.ERROR, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
304 |
writers.put(WriterKind.WARNING, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
305 |
writers.put(WriterKind.NOTICE, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
306 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
307 |
writers.put(WriterKind.STDOUT, out); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
308 |
writers.put(WriterKind.STDERR, err); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
309 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
310 |
return writers; |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
311 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
312 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
313 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
314 |
* Construct a log with given I/O redirections. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
315 |
* @deprecated |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
316 |
* This constructor is provided to support the supported but now-deprecated javadoc entry point |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
317 |
* com.sun.tools.javadoc.Main.execute(String programName, |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
318 |
* PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter, |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
319 |
* String defaultDocletClassName, String... args) |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
320 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
321 |
@Deprecated |
10 | 322 |
protected Log(Context context, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
323 |
this(context, initWriters(errWriter, warnWriter, noticeWriter)); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
324 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
325 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
326 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
327 |
* Initialize a writer map with different streams for different types of diagnostics. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
328 |
* @param errWriter a stream for writing error messages |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
329 |
* @param warnWriter a stream for writing warning messages |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
330 |
* @param noticeWriter a stream for writing notice messages |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
331 |
* @return a map of writers |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
332 |
* @deprecated This method exists to support a supported but now deprecated javadoc entry point. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
333 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
334 |
@Deprecated |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
335 |
private static Map<WriterKind, PrintWriter> initWriters(PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
336 |
Map<WriterKind, PrintWriter> writers = new EnumMap<>(WriterKind.class); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
337 |
writers.put(WriterKind.ERROR, errWriter); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
338 |
writers.put(WriterKind.WARNING, warnWriter); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
339 |
writers.put(WriterKind.NOTICE, noticeWriter); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
340 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
341 |
writers.put(WriterKind.STDOUT, noticeWriter); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
342 |
writers.put(WriterKind.STDERR, errWriter); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
343 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
344 |
return writers; |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
345 |
} |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
346 |
|
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
347 |
/** |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
348 |
* Creates a log. |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
349 |
* @param context the context in which the log should be registered |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
350 |
* @param writers a map of writers that can be accessed by the kind of writer required |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
351 |
*/ |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
352 |
private Log(Context context, Map<WriterKind, PrintWriter> writers) { |
867 | 353 |
super(JCDiagnostic.Factory.instance(context)); |
10 | 354 |
context.put(logKey, this); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
355 |
this.writers = writers; |
10 | 356 |
|
357 |
@SuppressWarnings("unchecked") // FIXME |
|
1866 | 358 |
DiagnosticListener<? super JavaFileObject> dl = |
10 | 359 |
context.get(DiagnosticListener.class); |
1866 | 360 |
this.diagListener = dl; |
361 |
||
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
362 |
diagnosticHandler = new DefaultDiagnosticHandler(); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
363 |
|
11052 | 364 |
messages = JavacMessages.instance(context); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
365 |
messages.add(Main.javacBundleName); |
11052 | 366 |
|
367 |
final Options options = Options.instance(context); |
|
368 |
initOptions(options); |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
40504
diff
changeset
|
369 |
options.addListener(() -> initOptions(options)); |
10 | 370 |
} |
371 |
// where |
|
11052 | 372 |
private void initOptions(Options options) { |
373 |
this.dumpOnError = options.isSet(DOE); |
|
374 |
this.promptOnError = options.isSet(PROMPT); |
|
375 |
this.emitWarnings = options.isUnset(XLINT_CUSTOM, "none"); |
|
376 |
this.suppressNotes = options.isSet("suppressNotes"); |
|
377 |
this.MaxErrors = getIntOption(options, XMAXERRS, getDefaultMaxErrors()); |
|
378 |
this.MaxWarnings = getIntOption(options, XMAXWARNS, getDefaultMaxWarnings()); |
|
379 |
||
380 |
boolean rawDiagnostics = options.isSet("rawDiagnostics"); |
|
381 |
this.diagFormatter = rawDiagnostics ? new RawDiagnosticFormatter(options) : |
|
382 |
new BasicDiagnosticFormatter(options, messages); |
|
383 |
||
384 |
String ek = options.get("expectKeys"); |
|
385 |
if (ek != null) |
|
22163 | 386 |
expectDiagKeys = new HashSet<>(Arrays.asList(ek.split(", *"))); |
11052 | 387 |
} |
388 |
||
11314 | 389 |
private int getIntOption(Options options, Option option, int defaultValue) { |
390 |
String s = options.get(option); |
|
10 | 391 |
try { |
4699
e58edf3542b3
6326754: Compiler will fail to handle -Xmaxerrs with -ve numbers
jjg
parents:
3995
diff
changeset
|
392 |
if (s != null) { |
e58edf3542b3
6326754: Compiler will fail to handle -Xmaxerrs with -ve numbers
jjg
parents:
3995
diff
changeset
|
393 |
int n = Integer.parseInt(s); |
e58edf3542b3
6326754: Compiler will fail to handle -Xmaxerrs with -ve numbers
jjg
parents:
3995
diff
changeset
|
394 |
return (n <= 0 ? Integer.MAX_VALUE : n); |
e58edf3542b3
6326754: Compiler will fail to handle -Xmaxerrs with -ve numbers
jjg
parents:
3995
diff
changeset
|
395 |
} |
10 | 396 |
} catch (NumberFormatException e) { |
397 |
// silently ignore ill-formed numbers |
|
398 |
} |
|
399 |
return defaultValue; |
|
400 |
} |
|
401 |
||
5850
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
402 |
/** Default value for -Xmaxerrs. |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
403 |
*/ |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
404 |
protected int getDefaultMaxErrors() { |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
405 |
return 100; |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
406 |
} |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
407 |
|
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
408 |
/** Default value for -Xmaxwarns. |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
409 |
*/ |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
410 |
protected int getDefaultMaxWarnings() { |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
411 |
return 100; |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
412 |
} |
6f095ff5b469
6958836: javadoc should support -Xmaxerrs and -Xmaxwarns
jjg
parents:
5847
diff
changeset
|
413 |
|
10 | 414 |
/** The number of errors encountered so far. |
415 |
*/ |
|
416 |
public int nerrors = 0; |
|
417 |
||
418 |
/** The number of warnings encountered so far. |
|
419 |
*/ |
|
420 |
public int nwarnings = 0; |
|
421 |
||
422 |
/** A set of all errors generated so far. This is used to avoid printing an |
|
423 |
* error message more than once. For each error, a pair consisting of the |
|
424 |
* source file name and source code position of the error is added to the set. |
|
425 |
*/ |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
29291
diff
changeset
|
426 |
protected Set<Pair<JavaFileObject, Integer>> recorded = new HashSet<>(); |
10 | 427 |
|
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
428 |
/** A set of "not-supported-in-source-X" errors produced so far. This is used to only generate |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
429 |
* one such error per file. |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
430 |
*/ |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
431 |
protected Set<Pair<JavaFileObject, List<String>>> recordedSourceLevelErrors = new HashSet<>(); |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
432 |
|
10 | 433 |
public boolean hasDiagnosticListener() { |
434 |
return diagListener != null; |
|
435 |
} |
|
436 |
||
11055 | 437 |
public void setEndPosTable(JavaFileObject name, EndPosTable endPosTable) { |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28455
diff
changeset
|
438 |
Assert.checkNonNull(name); |
11055 | 439 |
getSource(name).setEndPosTable(endPosTable); |
10 | 440 |
} |
441 |
||
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
442 |
/** Return current sourcefile. |
10 | 443 |
*/ |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
444 |
public JavaFileObject currentSourceFile() { |
10 | 445 |
return source == null ? null : source.getFile(); |
446 |
} |
|
447 |
||
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
448 |
/** Get the current diagnostic formatter. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
449 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
450 |
public DiagnosticFormatter<JCDiagnostic> getDiagnosticFormatter() { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
451 |
return diagFormatter; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
452 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
453 |
|
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
454 |
/** Set the current diagnostic formatter. |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
455 |
*/ |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
456 |
public void setDiagnosticFormatter(DiagnosticFormatter<JCDiagnostic> diagFormatter) { |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
457 |
this.diagFormatter = diagFormatter; |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
458 |
} |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
1866
diff
changeset
|
459 |
|
11052 | 460 |
public PrintWriter getWriter(WriterKind kind) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
461 |
return writers.get(kind); |
11052 | 462 |
} |
463 |
||
464 |
public void setWriter(WriterKind kind, PrintWriter pw) { |
|
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
28455
diff
changeset
|
465 |
Assert.checkNonNull(pw); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
466 |
writers.put(kind, pw); |
11052 | 467 |
} |
468 |
||
469 |
public void setWriters(PrintWriter pw) { |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
470 |
Assert.checkNonNull(pw); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
471 |
for (WriterKind k: WriterKind.values()) |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
472 |
writers.put(k, pw); |
11052 | 473 |
} |
474 |
||
15385 | 475 |
/** |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
476 |
* Replace the specified diagnostic handler with the |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
477 |
* handler that was current at the time this handler was created. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
478 |
* The given handler must be the currently installed handler; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
479 |
* it must be specified explicitly for clarity and consistency checking. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
480 |
*/ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
481 |
public void popDiagnosticHandler(DiagnosticHandler h) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
482 |
Assert.check(diagnosticHandler == h); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
483 |
diagnosticHandler = h.prev; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
484 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
485 |
|
10 | 486 |
/** Flush the logs |
487 |
*/ |
|
488 |
public void flush() { |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
489 |
for (PrintWriter pw: writers.values()) { |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
490 |
pw.flush(); |
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
491 |
} |
10 | 492 |
} |
493 |
||
11052 | 494 |
public void flush(WriterKind kind) { |
495 |
getWriter(kind).flush(); |
|
496 |
} |
|
497 |
||
10 | 498 |
/** Returns true if an error needs to be reported for a given |
499 |
* source name and pos. |
|
500 |
*/ |
|
501 |
protected boolean shouldReport(JavaFileObject file, int pos) { |
|
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
502 |
if (file == null) |
10 | 503 |
return true; |
504 |
||
22163 | 505 |
Pair<JavaFileObject,Integer> coords = new Pair<>(file, pos); |
10 | 506 |
boolean shouldReport = !recorded.contains(coords); |
507 |
if (shouldReport) |
|
508 |
recorded.add(coords); |
|
509 |
return shouldReport; |
|
510 |
} |
|
511 |
||
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
512 |
/** Returns true if a diagnostics needs to be reported. |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
513 |
*/ |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
514 |
private boolean shouldReport(JCDiagnostic d) { |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
515 |
JavaFileObject file = d.getSource(); |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
516 |
|
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
517 |
if (file == null) |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
518 |
return true; |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
519 |
|
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
520 |
if (!shouldReport(file, d.getIntPosition())) |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
521 |
return false; |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
522 |
|
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
523 |
if (!d.isFlagSet(DiagnosticFlag.SOURCE_LEVEL)) |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
524 |
return true; |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
525 |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
526 |
Pair<JavaFileObject, List<String>> coords = new Pair<>(file, getCode(d)); |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
527 |
boolean shouldReport = !recordedSourceLevelErrors.contains(coords); |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
528 |
if (shouldReport) |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
529 |
recordedSourceLevelErrors.add(coords); |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
530 |
return shouldReport; |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
531 |
} |
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
532 |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
533 |
//where |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
534 |
private List<String> getCode(JCDiagnostic d) { |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
535 |
ListBuffer<String> buf = new ListBuffer<>(); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
536 |
getCodeRecursive(buf, d); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
537 |
return buf.toList(); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
538 |
} |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
539 |
|
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
540 |
private void getCodeRecursive(ListBuffer<String> buf, JCDiagnostic d) { |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
541 |
buf.add(d.getCode()); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
542 |
for (Object o : d.getArgs()) { |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
543 |
if (o instanceof JCDiagnostic) { |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
544 |
getCodeRecursive(buf, (JCDiagnostic)o); |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
545 |
} |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
546 |
} |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
547 |
} |
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47216
diff
changeset
|
548 |
|
10 | 549 |
/** Prompt user after an error. |
550 |
*/ |
|
551 |
public void prompt() { |
|
552 |
if (promptOnError) { |
|
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
553 |
System.err.println(localize("resume.abort")); |
10 | 554 |
try { |
555 |
while (true) { |
|
556 |
switch (System.in.read()) { |
|
557 |
case 'a': case 'A': |
|
558 |
System.exit(-1); |
|
559 |
return; |
|
560 |
case 'r': case 'R': |
|
561 |
return; |
|
562 |
case 'x': case 'X': |
|
563 |
throw new AssertionError("user abort"); |
|
564 |
default: |
|
565 |
} |
|
566 |
} |
|
567 |
} catch (IOException e) {} |
|
568 |
} |
|
569 |
} |
|
570 |
||
571 |
/** Print the faulty source code line and point to the error. |
|
572 |
* @param pos Buffer index of the error position, must be on current line |
|
573 |
*/ |
|
574 |
private void printErrLine(int pos, PrintWriter writer) { |
|
867 | 575 |
String line = (source == null ? null : source.getLine(pos)); |
576 |
if (line == null) |
|
10 | 577 |
return; |
1109
853d8c191eac
6733837: Recent work on javac diagnostic affected javac output
mcimadamore
parents:
942
diff
changeset
|
578 |
int col = source.getColumnNumber(pos, false); |
10 | 579 |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
580 |
printRawLines(writer, line); |
867 | 581 |
for (int i = 0; i < col - 1; i++) { |
582 |
writer.print((line.charAt(i) == '\t') ? "\t" : " "); |
|
10 | 583 |
} |
584 |
writer.println("^"); |
|
585 |
writer.flush(); |
|
586 |
} |
|
587 |
||
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
588 |
public void printNewline() { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
589 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
590 |
noticeWriter.println(); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
591 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
592 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
593 |
public void printNewline(WriterKind wk) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
594 |
getWriter(wk).println(); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
595 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
596 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
597 |
public void printLines(String key, Object... args) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
598 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
599 |
printRawLines(noticeWriter, localize(key, args)); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
600 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
601 |
|
49822
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
602 |
public void printLines(DiagnosticInfo diag) { |
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
603 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
604 |
printRawLines(noticeWriter, localize(diag)); |
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
605 |
} |
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
606 |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
607 |
public void printLines(PrefixKind pk, String key, Object... args) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
608 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
609 |
printRawLines(noticeWriter, localize(pk, key, args)); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
610 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
611 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
612 |
public void printLines(WriterKind wk, String key, Object... args) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
613 |
printRawLines(getWriter(wk), localize(key, args)); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
614 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
615 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
616 |
public void printLines(WriterKind wk, PrefixKind pk, String key, Object... args) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
617 |
printRawLines(getWriter(wk), localize(pk, key, args)); |
11052 | 618 |
} |
619 |
||
620 |
/** Print the text of a message, translating newlines appropriately |
|
621 |
* for the platform. |
|
622 |
*/ |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
623 |
public void printRawLines(String msg) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
624 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
625 |
printRawLines(noticeWriter, msg); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
626 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
627 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
628 |
/** Print the text of a message, translating newlines appropriately |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
629 |
* for the platform. |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
630 |
*/ |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
631 |
public void printRawLines(WriterKind kind, String msg) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
632 |
printRawLines(getWriter(kind), msg); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
633 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
634 |
|
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
635 |
/** Print the text of a message, translating newlines appropriately |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
636 |
* for the platform. |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
637 |
*/ |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
638 |
public static void printRawLines(PrintWriter writer, String msg) { |
10 | 639 |
int nl; |
640 |
while ((nl = msg.indexOf('\n')) != -1) { |
|
641 |
writer.println(msg.substring(0, nl)); |
|
642 |
msg = msg.substring(nl+1); |
|
643 |
} |
|
644 |
if (msg.length() != 0) writer.println(msg); |
|
645 |
} |
|
646 |
||
8630 | 647 |
/** |
648 |
* Print the localized text of a "verbose" message to the |
|
649 |
* noticeWriter stream. |
|
650 |
*/ |
|
651 |
public void printVerbose(String key, Object... args) { |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
652 |
PrintWriter noticeWriter = writers.get(WriterKind.NOTICE); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
653 |
printRawLines(noticeWriter, localize("verbose." + key, args)); |
8630 | 654 |
} |
655 |
||
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
656 |
@Override |
867 | 657 |
protected void directError(String key, Object... args) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
658 |
PrintWriter errWriter = writers.get(WriterKind.ERROR); |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
659 |
printRawLines(errWriter, localize(key, args)); |
867 | 660 |
errWriter.flush(); |
10 | 661 |
} |
662 |
||
663 |
/** Report a warning that cannot be suppressed. |
|
664 |
* @param pos The source position at which to report the warning. |
|
665 |
* @param key The key for the localized warning message. |
|
666 |
* @param args Fields of the warning message. |
|
667 |
*/ |
|
668 |
public void strictWarning(DiagnosticPosition pos, String key, Object ... args) { |
|
28334
1633de6070ae
8058542: Devise scheme for better diagnostic creation
mcimadamore
parents:
25874
diff
changeset
|
669 |
writeDiagnostic(diags.warning(null, source, pos, key, args)); |
10 | 670 |
nwarnings++; |
671 |
} |
|
672 |
||
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
673 |
/** |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
674 |
* Primary method to report a diagnostic. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
675 |
* @param diagnostic |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
676 |
*/ |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
677 |
@Override |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
678 |
public void report(JCDiagnostic diagnostic) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
679 |
diagnosticHandler.report(diagnostic); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
680 |
} |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
681 |
|
10 | 682 |
/** |
683 |
* Common diagnostic handling. |
|
684 |
* The diagnostic is counted, and depending on the options and how many diagnostics have been |
|
685 |
* reported so far, the diagnostic may be handed off to writeDiagnostic. |
|
686 |
*/ |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
687 |
private class DefaultDiagnosticHandler extends DiagnosticHandler { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
688 |
@Override |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
689 |
public void report(JCDiagnostic diagnostic) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
690 |
if (expectDiagKeys != null) |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
691 |
expectDiagKeys.remove(diagnostic.getCode()); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
692 |
|
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
693 |
switch (diagnostic.getType()) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
694 |
case FRAGMENT: |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
695 |
throw new IllegalArgumentException(); |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6143
diff
changeset
|
696 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
697 |
case NOTE: |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
698 |
// Print out notes only when we are permitted to report warnings |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
699 |
// Notes are only generated at the end of a compilation, so should be small |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
700 |
// in number. |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
701 |
if ((emitWarnings || diagnostic.isMandatory()) && !suppressNotes) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
702 |
writeDiagnostic(diagnostic); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
703 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
704 |
break; |
10 | 705 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
706 |
case WARNING: |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
707 |
if (emitWarnings || diagnostic.isMandatory()) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
708 |
if (nwarnings < MaxWarnings) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
709 |
writeDiagnostic(diagnostic); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
710 |
nwarnings++; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
711 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
712 |
} |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
713 |
break; |
10 | 714 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
715 |
case ERROR: |
28455
41245007c074
8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents:
28334
diff
changeset
|
716 |
if (nerrors < MaxErrors && |
53773
454d54d8af1c
8217381: Incovenient errors reported when annotation processor generates source file and errors in the same round
jlahoda
parents:
49822
diff
changeset
|
717 |
(diagnostic.isFlagSet(DiagnosticFlag.API) || |
40504
0a01f6710c84
8078561: Error message should be generated once when -source 6 is specified
jlahoda
parents:
40308
diff
changeset
|
718 |
shouldReport(diagnostic))) { |
10 | 719 |
writeDiagnostic(diagnostic); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
720 |
nerrors++; |
10 | 721 |
} |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
722 |
break; |
10 | 723 |
} |
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
724 |
if (diagnostic.isFlagSet(JCDiagnostic.DiagnosticFlag.COMPRESSED)) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
725 |
compressedOutput = true; |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
16326
diff
changeset
|
726 |
} |
10 | 727 |
} |
728 |
} |
|
729 |
||
730 |
/** |
|
731 |
* Write out a diagnostic. |
|
732 |
*/ |
|
733 |
protected void writeDiagnostic(JCDiagnostic diag) { |
|
734 |
if (diagListener != null) { |
|
9071
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
8630
diff
changeset
|
735 |
diagListener.report(diag); |
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
8630
diff
changeset
|
736 |
return; |
10 | 737 |
} |
738 |
||
739 |
PrintWriter writer = getWriterForDiagnosticType(diag.getType()); |
|
740 |
||
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
741 |
printRawLines(writer, diagFormatter.format(diag, messages.getCurrentLocale())); |
10 | 742 |
|
743 |
if (promptOnError) { |
|
744 |
switch (diag.getType()) { |
|
745 |
case ERROR: |
|
746 |
case WARNING: |
|
747 |
prompt(); |
|
748 |
} |
|
749 |
} |
|
750 |
||
751 |
if (dumpOnError) |
|
752 |
new RuntimeException().printStackTrace(writer); |
|
753 |
||
754 |
writer.flush(); |
|
755 |
} |
|
756 |
||
757 |
@Deprecated |
|
758 |
protected PrintWriter getWriterForDiagnosticType(DiagnosticType dt) { |
|
759 |
switch (dt) { |
|
760 |
case FRAGMENT: |
|
761 |
throw new IllegalArgumentException(); |
|
762 |
||
763 |
case NOTE: |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
764 |
return writers.get(WriterKind.NOTICE); |
10 | 765 |
|
766 |
case WARNING: |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
767 |
return writers.get(WriterKind.WARNING); |
10 | 768 |
|
769 |
case ERROR: |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
770 |
return writers.get(WriterKind.ERROR); |
10 | 771 |
|
772 |
default: |
|
773 |
throw new Error(); |
|
774 |
} |
|
775 |
} |
|
776 |
||
777 |
/** Find a localized string in the resource bundle. |
|
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
778 |
* Because this method is static, it ignores the locale. |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
779 |
* Use localize(key, args) when possible. |
10 | 780 |
* @param key The key for the localized string. |
781 |
* @param args Fields to substitute into the string. |
|
782 |
*/ |
|
783 |
public static String getLocalizedString(String key, Object ... args) { |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
784 |
return JavacMessages.getDefaultLocalizedString(PrefixKind.COMPILER_MISC.key(key), args); |
10 | 785 |
} |
786 |
||
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
787 |
/** Find a localized string in the resource bundle. |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
788 |
* @param key The key for the localized string. |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
789 |
* @param args Fields to substitute into the string. |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
790 |
*/ |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
791 |
public String localize(String key, Object... args) { |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
792 |
return localize(PrefixKind.COMPILER_MISC, key, args); |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
793 |
} |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5850
diff
changeset
|
794 |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
795 |
public String localize(JCDiagnostic.DiagnosticInfo diagInfo) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
796 |
if (useRawMessages) { |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
797 |
return diagInfo.key(); |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
798 |
} else { |
49822
53aae0c219e6
8196433: use the new error diagnostic approach at javac.Main
vromero
parents:
48054
diff
changeset
|
799 |
return messages.getLocalizedString(diagInfo); |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
800 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
801 |
} |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
40232
diff
changeset
|
802 |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
803 |
/** Find a localized string in the resource bundle. |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
804 |
* @param key The key for the localized string. |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
805 |
* @param args Fields to substitute into the string. |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
806 |
*/ |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
807 |
public String localize(PrefixKind pk, String key, Object... args) { |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
808 |
if (useRawMessages) |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
809 |
return pk.key(key); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
810 |
else |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
811 |
return messages.getLocalizedString(pk.key(key), args); |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
812 |
} |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
813 |
// where |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
814 |
// backdoor hook for testing, should transition to use -XDrawDiagnostics |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
815 |
private static boolean useRawMessages = false; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
816 |
|
10 | 817 |
/*************************************************************************** |
818 |
* raw error messages without internationalization; used for experimentation |
|
819 |
* and quick prototyping |
|
820 |
***************************************************************************/ |
|
821 |
||
867 | 822 |
/** print an error or warning message: |
823 |
*/ |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
824 |
private void printRawDiag(PrintWriter pw, String prefix, int pos, String msg) { |
867 | 825 |
if (source == null || pos == Position.NOPOS) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
826 |
printRawLines(pw, prefix + msg); |
10 | 827 |
} else { |
867 | 828 |
int line = source.getLineNumber(pos); |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
829 |
JavaFileObject file = source.getFile(); |
10 | 830 |
if (file != null) |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
831 |
printRawLines(pw, |
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
3660
diff
changeset
|
832 |
file.getName() + ":" + |
10 | 833 |
line + ": " + msg); |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
834 |
printErrLine(pos, pw); |
10 | 835 |
} |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
836 |
pw.flush(); |
10 | 837 |
} |
838 |
||
867 | 839 |
/** report an error: |
840 |
*/ |
|
10 | 841 |
public void rawError(int pos, String msg) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
842 |
PrintWriter errWriter = writers.get(WriterKind.ERROR); |
1591
e5a618442f5f
6768932: Add support for multiline diagnostics
mcimadamore
parents:
1472
diff
changeset
|
843 |
if (nerrors < MaxErrors && shouldReport(currentSourceFile(), pos)) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
844 |
printRawDiag(errWriter, "error: ", pos, msg); |
10 | 845 |
prompt(); |
846 |
nerrors++; |
|
847 |
} |
|
848 |
errWriter.flush(); |
|
849 |
} |
|
850 |
||
867 | 851 |
/** report a warning: |
852 |
*/ |
|
10 | 853 |
public void rawWarning(int pos, String msg) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
854 |
PrintWriter warnWriter = writers.get(WriterKind.ERROR); |
10 | 855 |
if (nwarnings < MaxWarnings && emitWarnings) { |
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
856 |
printRawDiag(warnWriter, "warning: ", pos, msg); |
10 | 857 |
} |
858 |
prompt(); |
|
859 |
nwarnings++; |
|
40232
4995ab1a4558
8162359: javac should use stdout for --help and --version
jjg
parents:
32799
diff
changeset
|
860 |
warnWriter.flush(); |
10 | 861 |
} |
862 |
||
863 |
public static String format(String fmt, Object... args) { |
|
864 |
return String.format((java.util.Locale)null, fmt, args); |
|
865 |
} |
|
866 |
||
867 |
} |