author | ntoda |
Thu, 10 Jul 2014 13:57:27 -0700 | |
changeset 25445 | 603f0c93d5c9 |
parent 24898 | 88fa65d2ac87 |
child 25453 | be80cf0463b3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
23115
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, 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.main; |
|
27 |
||
28 |
import java.io.*; |
|
6721 | 29 |
import java.util.HashMap; |
10 | 30 |
import java.util.HashSet; |
12016 | 31 |
import java.util.LinkedHashMap; |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
32 |
import java.util.LinkedHashSet; |
10 | 33 |
import java.util.Map; |
34 |
import java.util.MissingResourceException; |
|
6721 | 35 |
import java.util.Queue; |
10 | 36 |
import java.util.ResourceBundle; |
37 |
import java.util.Set; |
|
38 |
||
6721 | 39 |
import javax.annotation.processing.Processor; |
40 |
import javax.lang.model.SourceVersion; |
|
12016 | 41 |
import javax.tools.DiagnosticListener; |
10 | 42 |
import javax.tools.JavaFileManager; |
43 |
import javax.tools.JavaFileObject; |
|
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
44 |
import javax.tools.StandardLocation; |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
45 |
|
12016 | 46 |
import static javax.tools.StandardLocation.CLASS_OUTPUT; |
10 | 47 |
|
48 |
import com.sun.source.util.TaskEvent; |
|
12016 | 49 |
import com.sun.tools.javac.api.MultiTaskListener; |
10 | 50 |
import com.sun.tools.javac.code.*; |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
51 |
import com.sun.tools.javac.code.Lint.LintCategory; |
6721 | 52 |
import com.sun.tools.javac.code.Symbol.*; |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
53 |
import com.sun.tools.javac.comp.*; |
17578 | 54 |
import com.sun.tools.javac.comp.CompileStates.CompileState; |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
55 |
import com.sun.tools.javac.file.JavacFileManager; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
56 |
import com.sun.tools.javac.jvm.*; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
57 |
import com.sun.tools.javac.parser.*; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
58 |
import com.sun.tools.javac.processing.*; |
10 | 59 |
import com.sun.tools.javac.tree.*; |
6721 | 60 |
import com.sun.tools.javac.tree.JCTree.*; |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
61 |
import com.sun.tools.javac.util.*; |
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
62 |
import com.sun.tools.javac.util.Log.WriterKind; |
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
63 |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
64 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
11314 | 65 |
import static com.sun.tools.javac.main.Option.*; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
66 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
10 | 67 |
|
68 |
||
69 |
/** This class could be the main entry point for GJC when GJC is used as a |
|
70 |
* component in a larger software system. It provides operations to |
|
71 |
* construct a new compiler, and to run a new compiler on a set of source |
|
72 |
* files. |
|
73 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
74 |
* <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
|
75 |
* If you write code that depends on this, you do so at your own risk. |
10 | 76 |
* This code and its internal interfaces are subject to change or |
77 |
* deletion without notice.</b> |
|
78 |
*/ |
|
19921
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
79 |
public class JavaCompiler { |
10 | 80 |
/** The context key for the compiler. */ |
22163 | 81 |
protected static final Context.Key<JavaCompiler> compilerKey = new Context.Key<>(); |
10 | 82 |
|
83 |
/** Get the JavaCompiler instance for this context. */ |
|
84 |
public static JavaCompiler instance(Context context) { |
|
85 |
JavaCompiler instance = context.get(compilerKey); |
|
86 |
if (instance == null) |
|
87 |
instance = new JavaCompiler(context); |
|
88 |
return instance; |
|
89 |
} |
|
90 |
||
91 |
/** The current version number as a string. |
|
92 |
*/ |
|
93 |
public static String version() { |
|
94 |
return version("release"); // mm.nn.oo[-milestone] |
|
95 |
} |
|
96 |
||
97 |
/** The current full version number as a string. |
|
98 |
*/ |
|
99 |
public static String fullVersion() { |
|
100 |
return version("full"); // mm.mm.oo[-milestone]-build |
|
101 |
} |
|
102 |
||
103 |
private static final String versionRBName = "com.sun.tools.javac.resources.version"; |
|
104 |
private static ResourceBundle versionRB; |
|
105 |
||
106 |
private static String version(String key) { |
|
107 |
if (versionRB == null) { |
|
108 |
try { |
|
109 |
versionRB = ResourceBundle.getBundle(versionRBName); |
|
110 |
} catch (MissingResourceException e) { |
|
6031
50004868a787
6964768: need test program to validate javac resource bundles
jjg
parents:
5847
diff
changeset
|
111 |
return Log.getLocalizedString("version.not.available"); |
10 | 112 |
} |
113 |
} |
|
114 |
try { |
|
115 |
return versionRB.getString(key); |
|
116 |
} |
|
117 |
catch (MissingResourceException e) { |
|
6031
50004868a787
6964768: need test program to validate javac resource bundles
jjg
parents:
5847
diff
changeset
|
118 |
return Log.getLocalizedString("version.not.available"); |
10 | 119 |
} |
120 |
} |
|
121 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
122 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
123 |
* Control how the compiler's latter phases (attr, flow, desugar, generate) |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
124 |
* are connected. Each individual file is processed by each phase in turn, |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
125 |
* but with different compile policies, you can control the order in which |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
126 |
* each class is processed through its next phase. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
127 |
* |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
128 |
* <p>Generally speaking, the compiler will "fail fast" in the face of |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
129 |
* errors, although not aggressively so. flow, desugar, etc become no-ops |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
130 |
* once any errors have occurred. No attempt is currently made to determine |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
131 |
* if it might be safe to process a class through its next phase because |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
132 |
* it does not depend on any unrelated errors that might have occurred. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
133 |
*/ |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
134 |
protected static enum CompilePolicy { |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
135 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
136 |
* Just attribute the parse trees. |
10 | 137 |
*/ |
138 |
ATTR_ONLY, |
|
139 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
140 |
/** |
10 | 141 |
* Just attribute and do flow analysis on the parse trees. |
142 |
* This should catch most user errors. |
|
143 |
*/ |
|
144 |
CHECK_ONLY, |
|
145 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
146 |
/** |
10 | 147 |
* Attribute everything, then do flow analysis for everything, |
148 |
* then desugar everything, and only then generate output. |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
149 |
* This means no output will be generated if there are any |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
150 |
* errors in any classes. |
10 | 151 |
*/ |
152 |
SIMPLE, |
|
153 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
154 |
/** |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
155 |
* Groups the classes for each source file together, then process |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
156 |
* each group in a manner equivalent to the {@code SIMPLE} policy. |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
157 |
* This means no output will be generated if there are any |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
158 |
* errors in any of the classes in a source file. |
10 | 159 |
*/ |
160 |
BY_FILE, |
|
161 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
162 |
/** |
10 | 163 |
* Completely process each entry on the todo list in turn. |
164 |
* -- this is the same for 1.5. |
|
165 |
* Means output might be generated for some classes in a compilation unit |
|
166 |
* and not others. |
|
167 |
*/ |
|
168 |
BY_TODO; |
|
169 |
||
170 |
static CompilePolicy decode(String option) { |
|
171 |
if (option == null) |
|
172 |
return DEFAULT_COMPILE_POLICY; |
|
173 |
else if (option.equals("attr")) |
|
174 |
return ATTR_ONLY; |
|
175 |
else if (option.equals("check")) |
|
176 |
return CHECK_ONLY; |
|
177 |
else if (option.equals("simple")) |
|
178 |
return SIMPLE; |
|
179 |
else if (option.equals("byfile")) |
|
180 |
return BY_FILE; |
|
181 |
else if (option.equals("bytodo")) |
|
182 |
return BY_TODO; |
|
183 |
else |
|
184 |
return DEFAULT_COMPILE_POLICY; |
|
185 |
} |
|
186 |
} |
|
187 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14548
diff
changeset
|
188 |
private static final CompilePolicy DEFAULT_COMPILE_POLICY = CompilePolicy.BY_TODO; |
10 | 189 |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
190 |
protected static enum ImplicitSourcePolicy { |
10 | 191 |
/** Don't generate or process implicitly read source files. */ |
192 |
NONE, |
|
193 |
/** Generate classes for implicitly read source files. */ |
|
194 |
CLASS, |
|
195 |
/** Like CLASS, but generate warnings if annotation processing occurs */ |
|
196 |
UNSET; |
|
197 |
||
198 |
static ImplicitSourcePolicy decode(String option) { |
|
199 |
if (option == null) |
|
200 |
return UNSET; |
|
201 |
else if (option.equals("none")) |
|
202 |
return NONE; |
|
203 |
else if (option.equals("class")) |
|
204 |
return CLASS; |
|
205 |
else |
|
206 |
return UNSET; |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
/** The log to be used for error reporting. |
|
211 |
*/ |
|
212 |
public Log log; |
|
213 |
||
169 | 214 |
/** Factory for creating diagnostic objects |
215 |
*/ |
|
216 |
JCDiagnostic.Factory diagFactory; |
|
217 |
||
10 | 218 |
/** The tree factory module. |
219 |
*/ |
|
220 |
protected TreeMaker make; |
|
221 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
222 |
/** The class finder. |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
223 |
*/ |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
224 |
protected ClassFinder finder; |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
225 |
|
10 | 226 |
/** The class reader. |
227 |
*/ |
|
228 |
protected ClassReader reader; |
|
229 |
||
230 |
/** The class writer. |
|
231 |
*/ |
|
232 |
protected ClassWriter writer; |
|
233 |
||
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
234 |
/** The native header writer. |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
235 |
*/ |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
236 |
protected JNIWriter jniWriter; |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
237 |
|
10 | 238 |
/** The module for the symbol table entry phases. |
239 |
*/ |
|
240 |
protected Enter enter; |
|
241 |
||
242 |
/** The symbol table. |
|
243 |
*/ |
|
244 |
protected Symtab syms; |
|
245 |
||
246 |
/** The language version. |
|
247 |
*/ |
|
248 |
protected Source source; |
|
249 |
||
250 |
/** The module for code generation. |
|
251 |
*/ |
|
252 |
protected Gen gen; |
|
253 |
||
254 |
/** The name table. |
|
255 |
*/ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
256 |
protected Names names; |
10 | 257 |
|
258 |
/** The attributor. |
|
259 |
*/ |
|
260 |
protected Attr attr; |
|
261 |
||
262 |
/** The attributor. |
|
263 |
*/ |
|
264 |
protected Check chk; |
|
265 |
||
266 |
/** The flow analyzer. |
|
267 |
*/ |
|
268 |
protected Flow flow; |
|
269 |
||
270 |
/** The type eraser. |
|
271 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
272 |
protected TransTypes transTypes; |
10 | 273 |
|
274 |
/** The syntactic sugar desweetener. |
|
275 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
276 |
protected Lower lower; |
10 | 277 |
|
278 |
/** The annotation annotator. |
|
279 |
*/ |
|
280 |
protected Annotate annotate; |
|
281 |
||
282 |
/** Force a completion failure on this name |
|
283 |
*/ |
|
284 |
protected final Name completionFailureName; |
|
285 |
||
286 |
/** Type utilities. |
|
287 |
*/ |
|
288 |
protected Types types; |
|
289 |
||
290 |
/** Access to file objects. |
|
291 |
*/ |
|
292 |
protected JavaFileManager fileManager; |
|
293 |
||
294 |
/** Factory for parsers. |
|
295 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
296 |
protected ParserFactory parserFactory; |
10 | 297 |
|
12016 | 298 |
/** Broadcasting listener for progress events |
10 | 299 |
*/ |
12016 | 300 |
protected MultiTaskListener taskListener; |
10 | 301 |
|
302 |
/** |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
303 |
* SourceCompleter that delegates to the readSourceFile method of this class. |
19921
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
304 |
*/ |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
305 |
protected final Symbol.Completer sourceCompleter = |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
306 |
new Symbol.Completer() { |
19921
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
307 |
@Override |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
308 |
public void complete(Symbol sym) throws CompletionFailure { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
309 |
readSourceFile((ClassSymbol) sym); |
19921
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
310 |
} |
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
311 |
}; |
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
312 |
|
58bcbe156057
8023974: Drop 'implements Completer' and 'implements SourceCompleter' from ClassReader resp. JavaCompiler.
jfranck
parents:
19664
diff
changeset
|
313 |
/** |
8618
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
314 |
* Command line options. |
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
315 |
*/ |
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
316 |
protected Options options; |
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
317 |
|
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
318 |
protected Context context; |
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
319 |
|
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
320 |
/** |
10 | 321 |
* Flag set if any annotation processing occurred. |
322 |
**/ |
|
323 |
protected boolean annotationProcessingOccurred; |
|
324 |
||
325 |
/** |
|
326 |
* Flag set if any implicit source files read. |
|
327 |
**/ |
|
328 |
protected boolean implicitSourceFilesRead; |
|
329 |
||
16968 | 330 |
protected CompileStates compileStates; |
331 |
||
10 | 332 |
/** Construct a new compiler using a shared context. |
333 |
*/ |
|
8614 | 334 |
public JavaCompiler(Context context) { |
10 | 335 |
this.context = context; |
336 |
context.put(compilerKey, this); |
|
337 |
||
338 |
// if fileManager not already set, register the JavacFileManager to be used |
|
339 |
if (context.get(JavaFileManager.class) == null) |
|
340 |
JavacFileManager.preRegister(context); |
|
341 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
342 |
names = Names.instance(context); |
10 | 343 |
log = Log.instance(context); |
169 | 344 |
diagFactory = JCDiagnostic.Factory.instance(context); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
345 |
finder = ClassFinder.instance(context); |
10 | 346 |
reader = ClassReader.instance(context); |
347 |
make = TreeMaker.instance(context); |
|
348 |
writer = ClassWriter.instance(context); |
|
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
349 |
jniWriter = JNIWriter.instance(context); |
10 | 350 |
enter = Enter.instance(context); |
351 |
todo = Todo.instance(context); |
|
352 |
||
353 |
fileManager = context.get(JavaFileManager.class); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
354 |
parserFactory = ParserFactory.instance(context); |
16968 | 355 |
compileStates = CompileStates.instance(context); |
10 | 356 |
|
357 |
try { |
|
358 |
// catch completion problems with predefineds |
|
359 |
syms = Symtab.instance(context); |
|
360 |
} catch (CompletionFailure ex) { |
|
361 |
// inlined Check.completionError as it is not initialized yet |
|
169 | 362 |
log.error("cant.access", ex.sym, ex.getDetailValue()); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
363 |
if (ex instanceof ClassFinder.BadClassFile) |
10 | 364 |
throw new Abort(); |
365 |
} |
|
366 |
source = Source.instance(context); |
|
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
367 |
Target target = Target.instance(context); |
10 | 368 |
attr = Attr.instance(context); |
369 |
chk = Check.instance(context); |
|
370 |
gen = Gen.instance(context); |
|
371 |
flow = Flow.instance(context); |
|
372 |
transTypes = TransTypes.instance(context); |
|
373 |
lower = Lower.instance(context); |
|
374 |
annotate = Annotate.instance(context); |
|
375 |
types = Types.instance(context); |
|
12016 | 376 |
taskListener = MultiTaskListener.instance(context); |
10 | 377 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
378 |
finder.sourceCompleter = sourceCompleter; |
10 | 379 |
|
8618
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
380 |
options = Options.instance(context); |
10 | 381 |
|
6721 | 382 |
verbose = options.isSet(VERBOSE); |
383 |
sourceOutput = options.isSet(PRINTSOURCE); // used to be -s |
|
384 |
stubOutput = options.isSet("-stubs"); |
|
385 |
relax = options.isSet("-relax"); |
|
386 |
printFlat = options.isSet("-printflat"); |
|
387 |
attrParseOnly = options.isSet("-attrparseonly"); |
|
388 |
encoding = options.get(ENCODING); |
|
389 |
lineDebugInfo = options.isUnset(G_CUSTOM) || |
|
390 |
options.isSet(G_CUSTOM, "lines"); |
|
391 |
genEndPos = options.isSet(XJCOV) || |
|
10 | 392 |
context.get(DiagnosticListener.class) != null; |
6721 | 393 |
devVerbose = options.isSet("dev"); |
394 |
processPcks = options.isSet("process.packages"); |
|
395 |
werror = options.isSet(WERROR); |
|
10 | 396 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24604
diff
changeset
|
397 |
// Should this be with other option checking, in Main |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
398 |
if (source.compareTo(Source.DEFAULT) < 0) { |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
399 |
if (options.isUnset(XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option)) { |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
400 |
if (fileManager instanceof BaseFileManager) { |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
401 |
if (((BaseFileManager) fileManager).isDefaultBootClassPath()) |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
402 |
log.warning(LintCategory.OPTIONS, "source.no.bootclasspath", source.name); |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
403 |
} |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
404 |
} |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
405 |
} |
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
406 |
|
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24604
diff
changeset
|
407 |
// Should this be with other option checking, in Main |
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
408 |
checkForObsoleteOptions(target); |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
409 |
|
6721 | 410 |
verboseCompilePolicy = options.isSet("verboseCompilePolicy"); |
10 | 411 |
|
412 |
if (attrParseOnly) |
|
413 |
compilePolicy = CompilePolicy.ATTR_ONLY; |
|
414 |
else |
|
415 |
compilePolicy = CompilePolicy.decode(options.get("compilePolicy")); |
|
416 |
||
417 |
implicitSourcePolicy = ImplicitSourcePolicy.decode(options.get("-implicit")); |
|
418 |
||
419 |
completionFailureName = |
|
6721 | 420 |
options.isSet("failcomplete") |
10 | 421 |
? names.fromString(options.get("failcomplete")) |
422 |
: null; |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
423 |
|
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
424 |
shouldStopPolicyIfError = |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
425 |
options.isSet("shouldStopPolicy") // backwards compatible |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
426 |
? CompileState.valueOf(options.get("shouldStopPolicy")) |
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
427 |
: options.isSet("shouldStopPolicyIfError") |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
428 |
? CompileState.valueOf(options.get("shouldStopPolicyIfError")) |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
429 |
: CompileState.INIT; |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
430 |
shouldStopPolicyIfNoError = |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
431 |
options.isSet("shouldStopPolicyIfNoError") |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
432 |
? CompileState.valueOf(options.get("shouldStopPolicyIfNoError")) |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
433 |
: CompileState.GENERATE; |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
434 |
|
6721 | 435 |
if (options.isUnset("oldDiags")) |
2984
e15ff3a34054
6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents:
2514
diff
changeset
|
436 |
log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context)); |
10 | 437 |
} |
438 |
||
24897
655b72d7b96e
7026941: 199: path options ignored when reusing filemanager across tasks
jjg
parents:
24604
diff
changeset
|
439 |
// Should this be with other option checking, in Main |
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
440 |
private void checkForObsoleteOptions(Target target) { |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
441 |
// Unless lint checking on options is disabled, check for |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
442 |
// obsolete source and target options. |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
443 |
boolean obsoleteOptionFound = false; |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
444 |
|
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
445 |
boolean lintOptions = |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
446 |
options.isUnset(XLINT_CUSTOM, "-"+LintCategory.OPTIONS.option); |
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
447 |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
448 |
switch (source.compareTo(Source.MIN)) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
449 |
case -1: |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
450 |
log.error("option.removed.source", source.name, Source.MIN.name); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
451 |
break; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
452 |
case 0: |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
453 |
if (lintOptions) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
454 |
log.warning(LintCategory.OPTIONS, "option.obsolete.source", source.name); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
455 |
obsoleteOptionFound = true; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
456 |
} |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
457 |
break; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
458 |
} |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
459 |
// check target version request |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
460 |
switch (target.compareTo(Target.MIN)) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
461 |
case -1: |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
462 |
log.error("option.removed.target", target.name, Target.MIN.name); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
463 |
break; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
464 |
case 0: |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
465 |
if (lintOptions) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
466 |
log.warning(LintCategory.OPTIONS, "option.obsolete.target", target.name); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
467 |
obsoleteOptionFound = true; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
468 |
} |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
469 |
break; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
24898
diff
changeset
|
470 |
} |
19508
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
471 |
|
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
472 |
if (obsoleteOptionFound) |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
473 |
log.warning(LintCategory.OPTIONS, "option.obsolete.suppression"); |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
474 |
} |
e2cd0ed6c9b0
8011043: Warn about use of 1.5 and earlier source and target values
darcy
parents:
18394
diff
changeset
|
475 |
|
10 | 476 |
/* Switches: |
477 |
*/ |
|
478 |
||
479 |
/** Verbose output. |
|
480 |
*/ |
|
481 |
public boolean verbose; |
|
482 |
||
483 |
/** Emit plain Java source files rather than class files. |
|
484 |
*/ |
|
485 |
public boolean sourceOutput; |
|
486 |
||
487 |
/** Emit stub source files rather than class files. |
|
488 |
*/ |
|
489 |
public boolean stubOutput; |
|
490 |
||
491 |
/** Generate attributed parse tree only. |
|
492 |
*/ |
|
493 |
public boolean attrParseOnly; |
|
494 |
||
495 |
/** Switch: relax some constraints for producing the jsr14 prototype. |
|
496 |
*/ |
|
497 |
boolean relax; |
|
498 |
||
499 |
/** Debug switch: Emit Java sources after inner class flattening. |
|
500 |
*/ |
|
501 |
public boolean printFlat; |
|
502 |
||
503 |
/** The encoding to be used for source input. |
|
504 |
*/ |
|
505 |
public String encoding; |
|
506 |
||
507 |
/** Generate code with the LineNumberTable attribute for debugging |
|
508 |
*/ |
|
509 |
public boolean lineDebugInfo; |
|
510 |
||
511 |
/** Switch: should we store the ending positions? |
|
512 |
*/ |
|
513 |
public boolean genEndPos; |
|
514 |
||
515 |
/** Switch: should we debug ignored exceptions |
|
516 |
*/ |
|
517 |
protected boolean devVerbose; |
|
518 |
||
519 |
/** Switch: should we (annotation) process packages as well |
|
520 |
*/ |
|
521 |
protected boolean processPcks; |
|
522 |
||
1996 | 523 |
/** Switch: treat warnings as errors |
524 |
*/ |
|
525 |
protected boolean werror; |
|
526 |
||
17578 | 527 |
/** Switch: is annotation processing requested explicitly via |
10 | 528 |
* CompilationTask.setProcessors? |
529 |
*/ |
|
530 |
protected boolean explicitAnnotationProcessingRequested = false; |
|
531 |
||
532 |
/** |
|
533 |
* The policy for the order in which to perform the compilation |
|
534 |
*/ |
|
535 |
protected CompilePolicy compilePolicy; |
|
536 |
||
537 |
/** |
|
538 |
* The policy for what to do with implicitly read source files |
|
539 |
*/ |
|
540 |
protected ImplicitSourcePolicy implicitSourcePolicy; |
|
541 |
||
542 |
/** |
|
543 |
* Report activity related to compilePolicy |
|
544 |
*/ |
|
545 |
public boolean verboseCompilePolicy; |
|
546 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
547 |
/** |
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
548 |
* Policy of how far to continue compilation after errors have occurred. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
549 |
* Set this to minimum CompileState (INIT) to stop as soon as possible |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
550 |
* after errors. |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
551 |
*/ |
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
552 |
public CompileState shouldStopPolicyIfError; |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
553 |
|
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
554 |
/** |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
555 |
* Policy of how far to continue compilation when no errors have occurred. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
556 |
* Set this to maximum CompileState (GENERATE) to perform full compilation. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
557 |
* Set this lower to perform partial compilation, such as -proc:only. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
558 |
*/ |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
559 |
public CompileState shouldStopPolicyIfNoError; |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
560 |
|
15385 | 561 |
/** A queue of all as yet unattributed classes. |
10 | 562 |
*/ |
563 |
public Todo todo; |
|
564 |
||
10637
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
565 |
/** A list of items to be closed when the compilation is complete. |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
566 |
*/ |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
567 |
public List<Closeable> closeables = List.nil(); |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
568 |
|
10 | 569 |
/** The set of currently compiled inputfiles, needed to ensure |
570 |
* we don't accidentally overwrite an input file when -s is set. |
|
571 |
* initialized by `compile'. |
|
572 |
*/ |
|
22163 | 573 |
protected Set<JavaFileObject> inputFiles = new HashSet<>(); |
10 | 574 |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
575 |
protected boolean shouldStop(CompileState cs) { |
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
576 |
CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError()) |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
577 |
? shouldStopPolicyIfError |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
578 |
: shouldStopPolicyIfNoError; |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
579 |
return cs.isAfter(shouldStopPolicy); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
580 |
} |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
581 |
|
10 | 582 |
/** The number of errors reported so far. |
583 |
*/ |
|
584 |
public int errorCount() { |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
585 |
if (werror && log.nerrors == 0 && log.nwarnings > 0) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
586 |
log.error("warnings.and.werror"); |
1996 | 587 |
} |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6156
diff
changeset
|
588 |
return log.nerrors; |
10 | 589 |
} |
590 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
591 |
protected final <T> Queue<T> stopIfError(CompileState cs, Queue<T> queue) { |
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
592 |
return shouldStop(cs) ? new ListBuffer<T>() : queue; |
10 | 593 |
} |
594 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
595 |
protected final <T> List<T> stopIfError(CompileState cs, List<T> list) { |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
596 |
return shouldStop(cs) ? List.<T>nil() : list; |
10 | 597 |
} |
598 |
||
599 |
/** The number of warnings reported so far. |
|
600 |
*/ |
|
601 |
public int warningCount() { |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
602 |
return log.nwarnings; |
10 | 603 |
} |
604 |
||
605 |
/** Try to open input stream with given name. |
|
606 |
* Report an error if this fails. |
|
607 |
* @param filename The file name of the input stream to be opened. |
|
608 |
*/ |
|
609 |
public CharSequence readSource(JavaFileObject filename) { |
|
610 |
try { |
|
611 |
inputFiles.add(filename); |
|
612 |
return filename.getCharContent(false); |
|
613 |
} catch (IOException e) { |
|
5007
28dee2489196
6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
jjg
parents:
5004
diff
changeset
|
614 |
log.error("error.reading.file", filename, JavacFileManager.getMessage(e)); |
10 | 615 |
return null; |
616 |
} |
|
617 |
} |
|
618 |
||
619 |
/** Parse contents of input stream. |
|
620 |
* @param filename The name of the file from which input stream comes. |
|
14259 | 621 |
* @param content The characters to be parsed. |
10 | 622 |
*/ |
623 |
protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) { |
|
624 |
long msec = now(); |
|
24069 | 625 |
JCCompilationUnit tree = make.TopLevel(List.<JCTree>nil()); |
10 | 626 |
if (content != null) { |
627 |
if (verbose) { |
|
8630 | 628 |
log.printVerbose("parsing.started", filename); |
10 | 629 |
} |
12016 | 630 |
if (!taskListener.isEmpty()) { |
10 | 631 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); |
632 |
taskListener.started(e); |
|
15562
e05336e44a9e
8007344: javac may not make tree end positions and/or doc comments available to processors and listeners
jjg
parents:
15385
diff
changeset
|
633 |
keepComments = true; |
e05336e44a9e
8007344: javac may not make tree end positions and/or doc comments available to processors and listeners
jjg
parents:
15385
diff
changeset
|
634 |
genEndPos = true; |
10 | 635 |
} |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
636 |
Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo); |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
1046
diff
changeset
|
637 |
tree = parser.parseCompilationUnit(); |
10 | 638 |
if (verbose) { |
8630 | 639 |
log.printVerbose("parsing.done", Long.toString(elapsed(msec))); |
10 | 640 |
} |
641 |
} |
|
642 |
||
643 |
tree.sourcefile = filename; |
|
644 |
||
12016 | 645 |
if (content != null && !taskListener.isEmpty()) { |
10 | 646 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree); |
647 |
taskListener.finished(e); |
|
648 |
} |
|
649 |
||
650 |
return tree; |
|
651 |
} |
|
652 |
// where |
|
653 |
public boolean keepComments = false; |
|
654 |
protected boolean keepComments() { |
|
655 |
return keepComments || sourceOutput || stubOutput; |
|
656 |
} |
|
657 |
||
658 |
||
659 |
/** Parse contents of file. |
|
660 |
* @param filename The name of the file to be parsed. |
|
661 |
*/ |
|
662 |
@Deprecated |
|
6581 | 663 |
public JCTree.JCCompilationUnit parse(String filename) { |
10 | 664 |
JavacFileManager fm = (JavacFileManager)fileManager; |
665 |
return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next()); |
|
666 |
} |
|
667 |
||
668 |
/** Parse contents of file. |
|
669 |
* @param filename The name of the file to be parsed. |
|
670 |
*/ |
|
671 |
public JCTree.JCCompilationUnit parse(JavaFileObject filename) { |
|
672 |
JavaFileObject prev = log.useSource(filename); |
|
673 |
try { |
|
674 |
JCTree.JCCompilationUnit t = parse(filename, readSource(filename)); |
|
675 |
if (t.endPositions != null) |
|
676 |
log.setEndPosTable(filename, t.endPositions); |
|
677 |
return t; |
|
678 |
} finally { |
|
679 |
log.useSource(prev); |
|
680 |
} |
|
681 |
} |
|
682 |
||
8851
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
683 |
/** Resolve an identifier which may be the binary name of a class or |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
684 |
* the Java name of a class or package. |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
685 |
* @param name The name to resolve |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
686 |
*/ |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
687 |
public Symbol resolveBinaryNameOrIdent(String name) { |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
688 |
try { |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
689 |
Name flatname = names.fromString(name.replace("/", ".")); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
690 |
return finder.loadClass(flatname); |
8851
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
691 |
} catch (CompletionFailure ignore) { |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
692 |
return resolveIdent(name); |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
693 |
} |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
694 |
} |
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
695 |
|
10 | 696 |
/** Resolve an identifier. |
697 |
* @param name The identifier to resolve |
|
698 |
*/ |
|
699 |
public Symbol resolveIdent(String name) { |
|
700 |
if (name.equals("")) |
|
701 |
return syms.errSymbol; |
|
702 |
JavaFileObject prev = log.useSource(null); |
|
703 |
try { |
|
704 |
JCExpression tree = null; |
|
705 |
for (String s : name.split("\\.", -1)) { |
|
706 |
if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords |
|
707 |
return syms.errSymbol; |
|
708 |
tree = (tree == null) ? make.Ident(names.fromString(s)) |
|
709 |
: make.Select(tree, names.fromString(s)); |
|
710 |
} |
|
711 |
JCCompilationUnit toplevel = |
|
24069 | 712 |
make.TopLevel(List.<JCTree>nil()); |
10 | 713 |
toplevel.packge = syms.unnamedPackage; |
714 |
return attr.attribIdent(tree, toplevel); |
|
715 |
} finally { |
|
716 |
log.useSource(prev); |
|
717 |
} |
|
718 |
} |
|
719 |
||
720 |
/** Emit plain Java source for a class. |
|
721 |
* @param env The attribution environment of the outermost class |
|
722 |
* containing this class. |
|
723 |
* @param cdef The class definition to be printed. |
|
724 |
*/ |
|
725 |
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { |
|
726 |
JavaFileObject outFile |
|
727 |
= fileManager.getJavaFileForOutput(CLASS_OUTPUT, |
|
728 |
cdef.sym.flatname.toString(), |
|
729 |
JavaFileObject.Kind.SOURCE, |
|
730 |
null); |
|
731 |
if (inputFiles.contains(outFile)) { |
|
732 |
log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile); |
|
733 |
return null; |
|
734 |
} else { |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21497
diff
changeset
|
735 |
try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) { |
10 | 736 |
new Pretty(out, true).printUnit(env.toplevel, cdef); |
737 |
if (verbose) |
|
8630 | 738 |
log.printVerbose("wrote.file", outFile); |
10 | 739 |
} |
740 |
return outFile; |
|
20617 | 741 |
} |
10 | 742 |
} |
743 |
||
744 |
/** Generate code and emit a class file for a given class |
|
745 |
* @param env The attribution environment of the outermost class |
|
746 |
* containing this class. |
|
747 |
* @param cdef The class definition from which code is generated. |
|
748 |
*/ |
|
749 |
JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { |
|
750 |
try { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
751 |
if (gen.genClass(env, cdef) && (errorCount() == 0)) |
10 | 752 |
return writer.writeClass(cdef.sym); |
753 |
} catch (ClassWriter.PoolOverflow ex) { |
|
754 |
log.error(cdef.pos(), "limit.pool"); |
|
755 |
} catch (ClassWriter.StringOverflow ex) { |
|
756 |
log.error(cdef.pos(), "limit.string.overflow", |
|
757 |
ex.value.substring(0, 20)); |
|
758 |
} catch (CompletionFailure ex) { |
|
759 |
chk.completionError(cdef.pos(), ex); |
|
760 |
} |
|
761 |
return null; |
|
762 |
} |
|
763 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
764 |
/** Compile a source file that has been accessed by the class finder. |
10 | 765 |
* @param c The class the source file of which needs to be compiled. |
766 |
*/ |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
767 |
private void readSourceFile(ClassSymbol c) throws CompletionFailure { |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
768 |
readSourceFile(null, c); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
769 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
770 |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
771 |
/** Compile a ClassSymbol from source, optionally using the given compilation unit as |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
772 |
* the source tree. |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
773 |
* @param tree the compilation unit in which the given ClassSymbol resides, |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
774 |
* or null if should be parsed from source |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
775 |
* @param c the ClassSymbol to complete |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
776 |
*/ |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
777 |
public void readSourceFile(JCCompilationUnit tree, ClassSymbol c) throws CompletionFailure { |
10 | 778 |
if (completionFailureName == c.fullname) { |
779 |
throw new CompletionFailure(c, "user-selected completion failure by class name"); |
|
780 |
} |
|
781 |
JavaFileObject filename = c.classfile; |
|
782 |
JavaFileObject prev = log.useSource(filename); |
|
783 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
784 |
if (tree == null) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
785 |
try { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
786 |
tree = parse(filename, filename.getCharContent(false)); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
787 |
} catch (IOException e) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
788 |
log.error("error.reading.file", filename, JavacFileManager.getMessage(e)); |
24069 | 789 |
tree = make.TopLevel(List.<JCTree>nil()); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
790 |
} finally { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
791 |
log.useSource(prev); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
792 |
} |
10 | 793 |
} |
794 |
||
12016 | 795 |
if (!taskListener.isEmpty()) { |
10 | 796 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree); |
797 |
taskListener.started(e); |
|
798 |
} |
|
799 |
||
800 |
enter.complete(List.of(tree), c); |
|
801 |
||
12016 | 802 |
if (!taskListener.isEmpty()) { |
10 | 803 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree); |
804 |
taskListener.finished(e); |
|
805 |
} |
|
806 |
||
807 |
if (enter.getEnv(c) == null) { |
|
808 |
boolean isPkgInfo = |
|
809 |
tree.sourcefile.isNameCompatible("package-info", |
|
810 |
JavaFileObject.Kind.SOURCE); |
|
811 |
if (isPkgInfo) { |
|
812 |
if (enter.getEnv(tree.packge) == null) { |
|
169 | 813 |
JCDiagnostic diag = |
814 |
diagFactory.fragment("file.does.not.contain.package", |
|
10 | 815 |
c.location()); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
816 |
throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory); |
10 | 817 |
} |
818 |
} else { |
|
169 | 819 |
JCDiagnostic diag = |
820 |
diagFactory.fragment("file.doesnt.contain.class", |
|
821 |
c.getQualifiedName()); |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
822 |
throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory); |
10 | 823 |
} |
824 |
} |
|
825 |
||
826 |
implicitSourceFilesRead = true; |
|
827 |
} |
|
828 |
||
829 |
/** Track when the JavaCompiler has been used to compile something. */ |
|
830 |
private boolean hasBeenUsed = false; |
|
831 |
private long start_msec = 0; |
|
832 |
public long elapsed_msec = 0; |
|
833 |
||
834 |
public void compile(List<JavaFileObject> sourceFileObject) |
|
835 |
throws Throwable { |
|
836 |
compile(sourceFileObject, List.<String>nil(), null); |
|
837 |
} |
|
838 |
||
839 |
/** |
|
840 |
* Main method: compile a list of files, return all compiled classes |
|
841 |
* |
|
842 |
* @param sourceFileObjects file objects to be compiled |
|
843 |
* @param classnames class names to process for annotations |
|
844 |
* @param processors user provided annotation processors to bypass |
|
845 |
* discovery, {@code null} means that no processors were provided |
|
846 |
*/ |
|
847 |
public void compile(List<JavaFileObject> sourceFileObjects, |
|
848 |
List<String> classnames, |
|
849 |
Iterable<? extends Processor> processors) |
|
850 |
{ |
|
24898
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
851 |
if (!taskListener.isEmpty()) { |
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
852 |
taskListener.started(new TaskEvent(TaskEvent.Kind.COMPILATION)); |
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
853 |
} |
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
854 |
|
10 | 855 |
if (processors != null && processors.iterator().hasNext()) |
856 |
explicitAnnotationProcessingRequested = true; |
|
857 |
// as a JavaCompiler can only be used once, throw an exception if |
|
858 |
// it has been used before. |
|
859 |
if (hasBeenUsed) |
|
860 |
throw new AssertionError("attempt to reuse JavaCompiler"); |
|
861 |
hasBeenUsed = true; |
|
862 |
||
8618
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
863 |
// forcibly set the equivalent of -Xlint:-options, so that no further |
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
864 |
// warnings about command line options are generated from this point on |
11314 | 865 |
options.put(XLINT_CUSTOM.text + "-" + LintCategory.OPTIONS.option, "true"); |
866 |
options.remove(XLINT_CUSTOM.text + LintCategory.OPTIONS.option); |
|
8618
913fb63a554b
7022337: repeated warnings about bootclasspath not set
jjg
parents:
8614
diff
changeset
|
867 |
|
10 | 868 |
start_msec = now(); |
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
869 |
|
10 | 870 |
try { |
871 |
initProcessAnnotations(processors); |
|
872 |
||
873 |
// These method calls must be chained to avoid memory leaks |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
874 |
processAnnotations( |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
875 |
enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))), |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
876 |
classnames); |
10 | 877 |
|
23115
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
878 |
// If it's safe to do so, skip attr / flow / gen for implicit classes |
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
879 |
if (taskListener.isEmpty() && |
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
880 |
implicitSourcePolicy == ImplicitSourcePolicy.NONE) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
881 |
todo.retainFiles(inputFiles); |
23115
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
882 |
} |
97722ad6c874
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
alundblad
parents:
22165
diff
changeset
|
883 |
|
10 | 884 |
switch (compilePolicy) { |
885 |
case ATTR_ONLY: |
|
886 |
attribute(todo); |
|
887 |
break; |
|
888 |
||
889 |
case CHECK_ONLY: |
|
890 |
flow(attribute(todo)); |
|
891 |
break; |
|
892 |
||
893 |
case SIMPLE: |
|
894 |
generate(desugar(flow(attribute(todo)))); |
|
895 |
break; |
|
896 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
897 |
case BY_FILE: { |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
898 |
Queue<Queue<Env<AttrContext>>> q = todo.groupByFile(); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
899 |
while (!q.isEmpty() && !shouldStop(CompileState.ATTR)) { |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
900 |
generate(desugar(flow(attribute(q.remove())))); |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
901 |
} |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
902 |
} |
10 | 903 |
break; |
904 |
||
905 |
case BY_TODO: |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
906 |
while (!todo.isEmpty()) |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
907 |
generate(desugar(flow(attribute(todo.remove())))); |
10 | 908 |
break; |
909 |
||
910 |
default: |
|
8032 | 911 |
Assert.error("unknown compile policy"); |
10 | 912 |
} |
913 |
} catch (Abort ex) { |
|
914 |
if (devVerbose) |
|
7335
8b390fd27190
6900037: javac should warn if earlier -source is used and bootclasspath not set
jjg
parents:
7076
diff
changeset
|
915 |
ex.printStackTrace(System.err); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
916 |
} finally { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
917 |
if (verbose) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
918 |
elapsed_msec = elapsed(start_msec); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
919 |
log.printVerbose("total", Long.toString(elapsed_msec)); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
920 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
921 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
922 |
reportDeferredDiagnostics(); |
10 | 923 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
924 |
if (!log.hasDiagnosticListener()) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
925 |
printCount("error", errorCount()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
926 |
printCount("warn", warningCount()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
927 |
} |
24898
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
928 |
if (!taskListener.isEmpty()) { |
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
929 |
taskListener.finished(new TaskEvent(TaskEvent.Kind.COMPILATION)); |
88fa65d2ac87
8033414: javac Plugin to receive notification (before and) after the compilation.
jlahoda
parents:
24897
diff
changeset
|
930 |
} |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
931 |
close(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
932 |
if (procEnvImpl != null) |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
933 |
procEnvImpl.close(); |
10 | 934 |
} |
935 |
} |
|
936 |
||
14957
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
937 |
/** |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
938 |
* Set needRootClasses to true, in JavaCompiler subclass constructor |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
939 |
* that want to collect public apis of classes supplied on the command line. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
940 |
*/ |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
941 |
protected boolean needRootClasses = false; |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
942 |
|
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
943 |
/** |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
944 |
* The list of classes explicitly supplied on the command line for compilation. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
945 |
* Not always populated. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
946 |
*/ |
10 | 947 |
private List<JCClassDecl> rootClasses; |
948 |
||
949 |
/** |
|
950 |
* Parses a list of files. |
|
951 |
*/ |
|
6581 | 952 |
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
953 |
if (shouldStop(CompileState.PARSE)) |
10 | 954 |
return List.nil(); |
955 |
||
956 |
//parse all files |
|
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
957 |
ListBuffer<JCCompilationUnit> trees = new ListBuffer<>(); |
22163 | 958 |
Set<JavaFileObject> filesSoFar = new HashSet<>(); |
6596
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
959 |
for (JavaFileObject fileObject : fileObjects) { |
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
960 |
if (!filesSoFar.contains(fileObject)) { |
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
961 |
filesSoFar.add(fileObject); |
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
962 |
trees.append(parse(fileObject)); |
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
963 |
} |
3274cf9d4873
6900149: IllegalStateException when compiling same files and DiagnosticListener is set.
sundar
parents:
6594
diff
changeset
|
964 |
} |
10 | 965 |
return trees.toList(); |
966 |
} |
|
967 |
||
968 |
/** |
|
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
969 |
* Enter the symbols found in a list of parse trees if the compilation |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
970 |
* is expected to proceed beyond anno processing into attr. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
971 |
* As a side-effect, this puts elements on the "todo" list. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
972 |
* Also stores a list of all top level classes in rootClasses. |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
973 |
*/ |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
974 |
public List<JCCompilationUnit> enterTreesIfNeeded(List<JCCompilationUnit> roots) { |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
975 |
if (shouldStop(CompileState.ATTR)) |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
976 |
return List.nil(); |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
977 |
return enterTrees(roots); |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
978 |
} |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
979 |
|
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
12213
diff
changeset
|
980 |
/** |
10 | 981 |
* Enter the symbols found in a list of parse trees. |
982 |
* As a side-effect, this puts elements on the "todo" list. |
|
983 |
* Also stores a list of all top level classes in rootClasses. |
|
984 |
*/ |
|
985 |
public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) { |
|
986 |
//enter symbols for all files |
|
12016 | 987 |
if (!taskListener.isEmpty()) { |
10 | 988 |
for (JCCompilationUnit unit: roots) { |
989 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit); |
|
990 |
taskListener.started(e); |
|
991 |
} |
|
992 |
} |
|
993 |
||
994 |
enter.main(roots); |
|
995 |
||
12016 | 996 |
if (!taskListener.isEmpty()) { |
10 | 997 |
for (JCCompilationUnit unit: roots) { |
998 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit); |
|
999 |
taskListener.finished(e); |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
14957
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1003 |
// If generating source, or if tracking public apis, |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1004 |
// then remember the classes declared in |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1005 |
// the original compilation units listed on the command line. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1006 |
if (needRootClasses || sourceOutput || stubOutput) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1007 |
ListBuffer<JCClassDecl> cdefs = new ListBuffer<>(); |
10 | 1008 |
for (JCCompilationUnit unit : roots) { |
1009 |
for (List<JCTree> defs = unit.defs; |
|
1010 |
defs.nonEmpty(); |
|
1011 |
defs = defs.tail) { |
|
1012 |
if (defs.head instanceof JCClassDecl) |
|
1013 |
cdefs.append((JCClassDecl)defs.head); |
|
1014 |
} |
|
1015 |
} |
|
1016 |
rootClasses = cdefs.toList(); |
|
1017 |
} |
|
6572
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1018 |
|
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1019 |
// Ensure the input files have been recorded. Although this is normally |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1020 |
// done by readSource, it may not have been done if the trees were read |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1021 |
// in a prior round of annotation processing, and the trees have been |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1022 |
// cleaned and are being reused. |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1023 |
for (JCCompilationUnit unit : roots) { |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1024 |
inputFiles.add(unit.sourcefile); |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1025 |
} |
4ca2051ff71a
6935638: -implicit:none prevents compilation with annotation processing
jjg
parents:
6355
diff
changeset
|
1026 |
|
10 | 1027 |
return roots; |
1028 |
} |
|
1029 |
||
1030 |
/** |
|
1031 |
* Set to true to enable skeleton annotation processing code. |
|
1032 |
* Currently, we assume this variable will be replaced more |
|
1033 |
* advanced logic to figure out if annotation processing is |
|
1034 |
* needed. |
|
1035 |
*/ |
|
1036 |
boolean processAnnotations = false; |
|
1037 |
||
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1038 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1039 |
|
10 | 1040 |
/** |
1041 |
* Object to handle annotation processing. |
|
1042 |
*/ |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3557
diff
changeset
|
1043 |
private JavacProcessingEnvironment procEnvImpl = null; |
10 | 1044 |
|
1045 |
/** |
|
1046 |
* Check if we should process annotations. |
|
1047 |
* If so, and if no scanner is yet registered, then set up the DocCommentScanner |
|
1048 |
* to catch doc comments, and set keepComments so the parser records them in |
|
1049 |
* the compilation unit. |
|
1050 |
* |
|
1051 |
* @param processors user provided annotation processors to bypass |
|
1052 |
* discovery, {@code null} means that no processors were provided |
|
1053 |
*/ |
|
6581 | 1054 |
public void initProcessAnnotations(Iterable<? extends Processor> processors) { |
10 | 1055 |
// Process annotations if processing is not disabled and there |
1056 |
// is at least one Processor available. |
|
6721 | 1057 |
if (options.isSet(PROC, "none")) { |
10 | 1058 |
processAnnotations = false; |
1059 |
} else if (procEnvImpl == null) { |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1060 |
procEnvImpl = JavacProcessingEnvironment.instance(context); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1061 |
procEnvImpl.setProcessors(processors); |
10 | 1062 |
processAnnotations = procEnvImpl.atLeastOneProcessor(); |
1063 |
||
1064 |
if (processAnnotations) { |
|
1065 |
options.put("save-parameter-names", "save-parameter-names"); |
|
1066 |
reader.saveParameterNames = true; |
|
1067 |
keepComments = true; |
|
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6596
diff
changeset
|
1068 |
genEndPos = true; |
12016 | 1069 |
if (!taskListener.isEmpty()) |
10 | 1070 |
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1071 |
deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); |
10 | 1072 |
} else { // free resources |
1073 |
procEnvImpl.close(); |
|
1074 |
} |
|
1075 |
} |
|
1076 |
} |
|
1077 |
||
1078 |
// TODO: called by JavacTaskImpl |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1079 |
public void processAnnotations(List<JCCompilationUnit> roots) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1080 |
processAnnotations(roots, List.<String>nil()); |
10 | 1081 |
} |
1082 |
||
1083 |
/** |
|
12016 | 1084 |
* Process any annotations found in the specified compilation units. |
10 | 1085 |
* @param roots a list of compilation units |
1086 |
* @return an instance of the compiler in which to complete the compilation |
|
1087 |
*/ |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1088 |
// Implementation note: when this method is called, log.deferredDiagnostics |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1089 |
// will have been set true by initProcessAnnotations, meaning that any diagnostics |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1090 |
// that are reported will go into the log.deferredDiagnostics queue. |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1091 |
// By the time this method exits, log.deferDiagnostics must be set back to false, |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1092 |
// and all deferredDiagnostics must have been handled: i.e. either reported |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1093 |
// or determined to be transient, and therefore suppressed. |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1094 |
public void processAnnotations(List<JCCompilationUnit> roots, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1095 |
List<String> classnames) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1096 |
if (shouldStop(CompileState.PROCESS)) { |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6156
diff
changeset
|
1097 |
// Errors were encountered. |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1098 |
// Unless all the errors are resolve errors, the errors were parse errors |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6156
diff
changeset
|
1099 |
// or other errors during enter which cannot be fixed by running |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6156
diff
changeset
|
1100 |
// any annotation processors. |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1101 |
if (unrecoverableError()) { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1102 |
deferredDiagnosticHandler.reportDeferredDiagnostics(); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1103 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1104 |
return ; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1105 |
} |
10 | 1106 |
} |
1107 |
||
1108 |
// ASSERT: processAnnotations and procEnvImpl should have been set up by |
|
1109 |
// by initProcessAnnotations |
|
1110 |
||
1111 |
// NOTE: The !classnames.isEmpty() checks should be refactored to Main. |
|
1112 |
||
1113 |
if (!processAnnotations) { |
|
1114 |
// If there are no annotation processors present, and |
|
1115 |
// annotation processing is to occur with compilation, |
|
1116 |
// emit a warning. |
|
6721 | 1117 |
if (options.isSet(PROC, "only")) { |
10 | 1118 |
log.warning("proc.proc-only.requested.no.procs"); |
1119 |
todo.clear(); |
|
1120 |
} |
|
1121 |
// If not processing annotations, classnames must be empty |
|
1122 |
if (!classnames.isEmpty()) { |
|
1123 |
log.error("proc.no.explicit.annotation.processing.requested", |
|
1124 |
classnames); |
|
1125 |
} |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1126 |
Assert.checkNull(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1127 |
return ; // continue regular compilation |
10 | 1128 |
} |
1129 |
||
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1130 |
Assert.checkNonNull(deferredDiagnosticHandler); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1131 |
|
10 | 1132 |
try { |
1133 |
List<ClassSymbol> classSymbols = List.nil(); |
|
1134 |
List<PackageSymbol> pckSymbols = List.nil(); |
|
1135 |
if (!classnames.isEmpty()) { |
|
1136 |
// Check for explicit request for annotation |
|
1137 |
// processing |
|
1138 |
if (!explicitAnnotationProcessingRequested()) { |
|
1139 |
log.error("proc.no.explicit.annotation.processing.requested", |
|
1140 |
classnames); |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1141 |
deferredDiagnosticHandler.reportDeferredDiagnostics(); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1142 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1143 |
return ; // TODO: Will this halt compilation? |
10 | 1144 |
} else { |
1145 |
boolean errors = false; |
|
1146 |
for (String nameStr : classnames) { |
|
8851
e630c590eb10
6930508: Passing nested class names on javac command line interfere with subsequent name -> class lookup
jjg
parents:
8845
diff
changeset
|
1147 |
Symbol sym = resolveBinaryNameOrIdent(nameStr); |
11867
1fa9d18707da
7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
11314
diff
changeset
|
1148 |
if (sym == null || |
1fa9d18707da
7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
11314
diff
changeset
|
1149 |
(sym.kind == Kinds.PCK && !processPcks) || |
1fa9d18707da
7142672: Problems with the value passed to the 'classes' param of JavaCompiler.CompilationTask.getTask(...)
jjh
parents:
11314
diff
changeset
|
1150 |
sym.kind == Kinds.ABSENT_TYP) { |
10 | 1151 |
log.error("proc.cant.find.class", nameStr); |
1152 |
errors = true; |
|
1153 |
continue; |
|
1154 |
} |
|
1155 |
try { |
|
1156 |
if (sym.kind == Kinds.PCK) |
|
1157 |
sym.complete(); |
|
1158 |
if (sym.exists()) { |
|
1159 |
if (sym.kind == Kinds.PCK) |
|
1160 |
pckSymbols = pckSymbols.prepend((PackageSymbol)sym); |
|
1161 |
else |
|
1162 |
classSymbols = classSymbols.prepend((ClassSymbol)sym); |
|
1163 |
continue; |
|
1164 |
} |
|
8032 | 1165 |
Assert.check(sym.kind == Kinds.PCK); |
10 | 1166 |
log.warning("proc.package.does.not.exist", nameStr); |
1167 |
pckSymbols = pckSymbols.prepend((PackageSymbol)sym); |
|
1168 |
} catch (CompletionFailure e) { |
|
1169 |
log.error("proc.cant.find.class", nameStr); |
|
1170 |
errors = true; |
|
1171 |
continue; |
|
1172 |
} |
|
1173 |
} |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1174 |
if (errors) { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1175 |
deferredDiagnosticHandler.reportDeferredDiagnostics(); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1176 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1177 |
return ; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1178 |
} |
10 | 1179 |
} |
1180 |
} |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3557
diff
changeset
|
1181 |
try { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1182 |
annotationProcessingOccurred = |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1183 |
procEnvImpl.doProcessing(roots, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1184 |
classSymbols, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1185 |
pckSymbols, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1186 |
deferredDiagnosticHandler); |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1187 |
// doProcessing will have handled deferred diagnostics |
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3557
diff
changeset
|
1188 |
} finally { |
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3557
diff
changeset
|
1189 |
procEnvImpl.close(); |
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3557
diff
changeset
|
1190 |
} |
10 | 1191 |
} catch (CompletionFailure ex) { |
169 | 1192 |
log.error("cant.access", ex.sym, ex.getDetailValue()); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1193 |
if (deferredDiagnosticHandler != null) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1194 |
deferredDiagnosticHandler.reportDeferredDiagnostics(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1195 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1196 |
} |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1197 |
} |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1198 |
} |
10 | 1199 |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1200 |
private boolean unrecoverableError() { |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1201 |
if (deferredDiagnosticHandler != null) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1202 |
for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1203 |
if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RECOVERABLE)) |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1204 |
return true; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14365
diff
changeset
|
1205 |
} |
10 | 1206 |
} |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1207 |
return false; |
10 | 1208 |
} |
1209 |
||
1210 |
boolean explicitAnnotationProcessingRequested() { |
|
1211 |
return |
|
1212 |
explicitAnnotationProcessingRequested || |
|
8623
cc57bd7697a2
6986895: compiler gives misleading message for no input files
jjg
parents:
8618
diff
changeset
|
1213 |
explicitAnnotationProcessingRequested(options); |
cc57bd7697a2
6986895: compiler gives misleading message for no input files
jjg
parents:
8618
diff
changeset
|
1214 |
} |
cc57bd7697a2
6986895: compiler gives misleading message for no input files
jjg
parents:
8618
diff
changeset
|
1215 |
|
cc57bd7697a2
6986895: compiler gives misleading message for no input files
jjg
parents:
8618
diff
changeset
|
1216 |
static boolean explicitAnnotationProcessingRequested(Options options) { |
cc57bd7697a2
6986895: compiler gives misleading message for no input files
jjg
parents:
8618
diff
changeset
|
1217 |
return |
6721 | 1218 |
options.isSet(PROCESSOR) || |
1219 |
options.isSet(PROCESSORPATH) || |
|
1220 |
options.isSet(PROC, "only") || |
|
1221 |
options.isSet(XPRINT); |
|
10 | 1222 |
} |
1223 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1224 |
public void setDeferredDiagnosticHandler(Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1225 |
this.deferredDiagnosticHandler = deferredDiagnosticHandler; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1226 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1227 |
|
10 | 1228 |
/** |
1229 |
* Attribute a list of parse trees, such as found on the "todo" list. |
|
1230 |
* Note that attributing classes may cause additional files to be |
|
1231 |
* parsed and entered via the SourceCompleter. |
|
1232 |
* Attribution of the entries in the list does not stop if any errors occur. |
|
1233 |
* @returns a list of environments for attributd classes. |
|
1234 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1235 |
public Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1236 |
ListBuffer<Env<AttrContext>> results = new ListBuffer<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1237 |
while (!envs.isEmpty()) |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1238 |
results.append(attribute(envs.remove())); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1239 |
return stopIfError(CompileState.ATTR, results); |
10 | 1240 |
} |
1241 |
||
1242 |
/** |
|
1243 |
* Attribute a parse tree. |
|
1244 |
* @returns the attributed parse tree |
|
1245 |
*/ |
|
1246 |
public Env<AttrContext> attribute(Env<AttrContext> env) { |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1247 |
if (compileStates.isDone(env, CompileState.ATTR)) |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1248 |
return env; |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1249 |
|
10 | 1250 |
if (verboseCompilePolicy) |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
6031
diff
changeset
|
1251 |
printNote("[attribute " + env.enclClass.sym + "]"); |
10 | 1252 |
if (verbose) |
8630 | 1253 |
log.printVerbose("checking.attribution", env.enclClass.sym); |
10 | 1254 |
|
12016 | 1255 |
if (!taskListener.isEmpty()) { |
10 | 1256 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym); |
1257 |
taskListener.started(e); |
|
1258 |
} |
|
1259 |
||
1260 |
JavaFileObject prev = log.useSource( |
|
1261 |
env.enclClass.sym.sourcefile != null ? |
|
1262 |
env.enclClass.sym.sourcefile : |
|
1263 |
env.toplevel.sourcefile); |
|
1264 |
try { |
|
8845 | 1265 |
attr.attrib(env); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6582
diff
changeset
|
1266 |
if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) { |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6582
diff
changeset
|
1267 |
//if in fail-over mode, ensure that AST expression nodes |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6582
diff
changeset
|
1268 |
//are correctly initialized (e.g. they have a type/symbol) |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1269 |
attr.postAttr(env.tree); |
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6582
diff
changeset
|
1270 |
} |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1271 |
compileStates.put(env, CompileState.ATTR); |
14957
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1272 |
if (rootClasses != null && rootClasses.contains(env.enclClass)) { |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1273 |
// This was a class that was explicitly supplied for compilation. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1274 |
// If we want to capture the public api of this class, |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1275 |
// then now is a good time to do it. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1276 |
reportPublicApi(env.enclClass.sym); |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1277 |
} |
10 | 1278 |
} |
1279 |
finally { |
|
1280 |
log.useSource(prev); |
|
1281 |
} |
|
1282 |
||
1283 |
return env; |
|
1284 |
} |
|
1285 |
||
14957
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1286 |
/** Report the public api of a class that was supplied explicitly for compilation, |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1287 |
* for example on the command line to javac. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1288 |
* @param sym The symbol of the class. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1289 |
*/ |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1290 |
public void reportPublicApi(ClassSymbol sym) { |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1291 |
// Override to collect the reported public api. |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1292 |
} |
ea7808ffcf6d
8004657: Add hooks to javac to enable reporting dependency information.
ohrstrom
parents:
14952
diff
changeset
|
1293 |
|
10 | 1294 |
/** |
1295 |
* Perform dataflow checks on attributed parse trees. |
|
1296 |
* These include checks for definite assignment and unreachable statements. |
|
1297 |
* If any errors occur, an empty list will be returned. |
|
1298 |
* @returns the list of attributed parse trees |
|
1299 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1300 |
public Queue<Env<AttrContext>> flow(Queue<Env<AttrContext>> envs) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1301 |
ListBuffer<Env<AttrContext>> results = new ListBuffer<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1302 |
for (Env<AttrContext> env: envs) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1303 |
flow(env, results); |
10 | 1304 |
} |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1305 |
return stopIfError(CompileState.FLOW, results); |
10 | 1306 |
} |
1307 |
||
1308 |
/** |
|
1309 |
* Perform dataflow checks on an attributed parse tree. |
|
1310 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1311 |
public Queue<Env<AttrContext>> flow(Env<AttrContext> env) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1312 |
ListBuffer<Env<AttrContext>> results = new ListBuffer<>(); |
10 | 1313 |
flow(env, results); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1314 |
return stopIfError(CompileState.FLOW, results); |
10 | 1315 |
} |
1316 |
||
1317 |
/** |
|
1318 |
* Perform dataflow checks on an attributed parse tree. |
|
1319 |
*/ |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1320 |
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) { |
24392
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1321 |
if (compileStates.isDone(env, CompileState.FLOW)) { |
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1322 |
results.add(env); |
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1323 |
return; |
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1324 |
} |
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1325 |
|
10 | 1326 |
try { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1327 |
if (shouldStop(CompileState.FLOW)) |
10 | 1328 |
return; |
1329 |
||
24392
aca305440fb9
8040822: Duplicated notifications can be sent to TaskListener
jlahoda
parents:
24069
diff
changeset
|
1330 |
if (relax) { |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1331 |
results.add(env); |
10 | 1332 |
return; |
1333 |
} |
|
1334 |
||
1335 |
if (verboseCompilePolicy) |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1336 |
printNote("[flow " + env.enclClass.sym + "]"); |
10 | 1337 |
JavaFileObject prev = log.useSource( |
1338 |
env.enclClass.sym.sourcefile != null ? |
|
1339 |
env.enclClass.sym.sourcefile : |
|
1340 |
env.toplevel.sourcefile); |
|
1341 |
try { |
|
1342 |
make.at(Position.FIRSTPOS); |
|
1343 |
TreeMaker localMake = make.forToplevel(env.toplevel); |
|
6156
e15c221efaac
6970833: Try-with-resource implementation throws an NPE during Flow analysis
mcimadamore
parents:
6143
diff
changeset
|
1344 |
flow.analyzeTree(env, localMake); |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1345 |
compileStates.put(env, CompileState.FLOW); |
10 | 1346 |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1347 |
if (shouldStop(CompileState.FLOW)) |
10 | 1348 |
return; |
1349 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1350 |
results.add(env); |
10 | 1351 |
} |
1352 |
finally { |
|
1353 |
log.useSource(prev); |
|
1354 |
} |
|
1355 |
} |
|
1356 |
finally { |
|
12016 | 1357 |
if (!taskListener.isEmpty()) { |
10 | 1358 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym); |
1359 |
taskListener.finished(e); |
|
1360 |
} |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
/** |
|
1365 |
* Prepare attributed parse trees, in conjunction with their attribution contexts, |
|
1366 |
* for source or code generation. |
|
1367 |
* If any errors occur, an empty list will be returned. |
|
1368 |
* @returns a list containing the classes to be generated |
|
1369 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1370 |
public Queue<Pair<Env<AttrContext>, JCClassDecl>> desugar(Queue<Env<AttrContext>> envs) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1371 |
ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = new ListBuffer<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1372 |
for (Env<AttrContext> env: envs) |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1373 |
desugar(env, results); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1374 |
return stopIfError(CompileState.FLOW, results); |
10 | 1375 |
} |
1376 |
||
22163 | 1377 |
HashMap<Env<AttrContext>, Queue<Pair<Env<AttrContext>, JCClassDecl>>> desugaredEnvs = new HashMap<>(); |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1378 |
|
10 | 1379 |
/** |
1380 |
* Prepare attributed parse trees, in conjunction with their attribution contexts, |
|
1381 |
* for source or code generation. If the file was not listed on the command line, |
|
1382 |
* the current implicitSourcePolicy is taken into account. |
|
1383 |
* The preparation stops as soon as an error is found. |
|
1384 |
*/ |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1385 |
protected void desugar(final Env<AttrContext> env, Queue<Pair<Env<AttrContext>, JCClassDecl>> results) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1386 |
if (shouldStop(CompileState.TRANSTYPES)) |
10 | 1387 |
return; |
1388 |
||
1389 |
if (implicitSourcePolicy == ImplicitSourcePolicy.NONE |
|
1390 |
&& !inputFiles.contains(env.toplevel.sourcefile)) { |
|
1391 |
return; |
|
1392 |
} |
|
1393 |
||
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1394 |
if (compileStates.isDone(env, CompileState.LOWER)) { |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1395 |
results.addAll(desugaredEnvs.get(env)); |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1396 |
return; |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1397 |
} |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1398 |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1399 |
/** |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1400 |
* Ensure that superclasses of C are desugared before C itself. This is |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1401 |
* required for two reasons: (i) as erasure (TransTypes) destroys |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1402 |
* information needed in flow analysis and (ii) as some checks carried |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1403 |
* out during lowering require that all synthetic fields/methods have |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1404 |
* already been added to C and its superclasses. |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1405 |
*/ |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1406 |
class ScanNested extends TreeScanner { |
22163 | 1407 |
Set<Env<AttrContext>> dependencies = new LinkedHashSet<>(); |
21497
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1408 |
protected boolean hasLambdas; |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1409 |
@Override |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1410 |
public void visitClassDef(JCClassDecl node) { |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1411 |
Type st = types.supertype(node.sym.type); |
16968 | 1412 |
boolean envForSuperTypeFound = false; |
1413 |
while (!envForSuperTypeFound && st.hasTag(CLASS)) { |
|
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1414 |
ClassSymbol c = st.tsym.outermostClass(); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1415 |
Env<AttrContext> stEnv = enter.getEnv(c); |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1416 |
if (stEnv != null && env != stEnv) { |
16968 | 1417 |
if (dependencies.add(stEnv)) { |
21497
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1418 |
boolean prevHasLambdas = hasLambdas; |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1419 |
try { |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1420 |
scan(stEnv.tree); |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1421 |
} finally { |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1422 |
/* |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1423 |
* ignore any updates to hasLambdas made during |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1424 |
* the nested scan, this ensures an initalized |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1425 |
* LambdaToMethod is available only to those |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1426 |
* classes that contain lambdas |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1427 |
*/ |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1428 |
hasLambdas = prevHasLambdas; |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1429 |
} |
16968 | 1430 |
} |
1431 |
envForSuperTypeFound = true; |
|
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1432 |
} |
16968 | 1433 |
st = types.supertype(st); |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1434 |
} |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1435 |
super.visitClassDef(node); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1436 |
} |
21497
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1437 |
@Override |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1438 |
public void visitLambda(JCLambda tree) { |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1439 |
hasLambdas = true; |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1440 |
super.visitLambda(tree); |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1441 |
} |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1442 |
@Override |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1443 |
public void visitReference(JCMemberReference tree) { |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1444 |
hasLambdas = true; |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1445 |
super.visitReference(tree); |
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1446 |
} |
10 | 1447 |
} |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1448 |
ScanNested scanner = new ScanNested(); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1449 |
scanner.scan(env.tree); |
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1450 |
for (Env<AttrContext> dep: scanner.dependencies) { |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1451 |
if (!compileStates.isDone(dep, CompileState.FLOW)) |
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1452 |
desugaredEnvs.put(dep, desugar(flow(attribute(dep)))); |
936
1d395a623f16
6726015: JavaCompiler: replace desugarLater by compileStates
jjg
parents:
864
diff
changeset
|
1453 |
} |
10 | 1454 |
|
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1455 |
//We need to check for error another time as more classes might |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1456 |
//have been attributed and analyzed at this stage |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1457 |
if (shouldStop(CompileState.TRANSTYPES)) |
1046
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1458 |
return; |
e395ce284cbf
6734819: Javac performs flows analysis on already translated classes
mcimadamore
parents:
936
diff
changeset
|
1459 |
|
10 | 1460 |
if (verboseCompilePolicy) |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1461 |
printNote("[desugar " + env.enclClass.sym + "]"); |
10 | 1462 |
|
1463 |
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? |
|
1464 |
env.enclClass.sym.sourcefile : |
|
1465 |
env.toplevel.sourcefile); |
|
1466 |
try { |
|
1467 |
//save tree prior to rewriting |
|
1468 |
JCTree untranslated = env.tree; |
|
1469 |
||
1470 |
make.at(Position.FIRSTPOS); |
|
1471 |
TreeMaker localMake = make.forToplevel(env.toplevel); |
|
1472 |
||
24069 | 1473 |
if (env.tree.hasTag(JCTree.Tag.PACKAGEDEF)) { |
10 | 1474 |
if (!(stubOutput || sourceOutput || printFlat)) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1475 |
if (shouldStop(CompileState.LOWER)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1476 |
return; |
10 | 1477 |
List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake); |
1478 |
if (pdef.head != null) { |
|
8032 | 1479 |
Assert.check(pdef.tail.isEmpty()); |
22163 | 1480 |
results.add(new Pair<>(env, (JCClassDecl)pdef.head)); |
10 | 1481 |
} |
1482 |
} |
|
1483 |
return; |
|
1484 |
} |
|
1485 |
||
1486 |
if (stubOutput) { |
|
1487 |
//emit stub Java source file, only for compilation |
|
1488 |
//units enumerated explicitly on the command line |
|
1489 |
JCClassDecl cdef = (JCClassDecl)env.tree; |
|
1490 |
if (untranslated instanceof JCClassDecl && |
|
1491 |
rootClasses.contains((JCClassDecl)untranslated) && |
|
1492 |
((cdef.mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1493 |
cdef.sym.packge().getQualifiedName() == names.java_lang)) { |
|
22163 | 1494 |
results.add(new Pair<>(env, removeMethodBodies(cdef))); |
10 | 1495 |
} |
1496 |
return; |
|
1497 |
} |
|
1498 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1499 |
if (shouldStop(CompileState.TRANSTYPES)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1500 |
return; |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1501 |
|
10 | 1502 |
env.tree = transTypes.translateTopLevelClass(env.tree, localMake); |
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1503 |
compileStates.put(env, CompileState.TRANSTYPES); |
10 | 1504 |
|
21497
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1505 |
if (source.allowLambda() && scanner.hasLambdas) { |
18394
e7e0700732ad
8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents:
17582
diff
changeset
|
1506 |
if (shouldStop(CompileState.UNLAMBDA)) |
e7e0700732ad
8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents:
17582
diff
changeset
|
1507 |
return; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
1508 |
|
21497
ad075a07ee79
8026936: Initialize LamdbaToMethod lazily and as required
ksrini
parents:
20617
diff
changeset
|
1509 |
env.tree = LambdaToMethod.instance(context).translateTopLevelClass(env, env.tree, localMake); |
18394
e7e0700732ad
8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents:
17582
diff
changeset
|
1510 |
compileStates.put(env, CompileState.UNLAMBDA); |
e7e0700732ad
8016607: javac, avoid analyzing lambdas for source 7 compilation
vromero
parents:
17582
diff
changeset
|
1511 |
} |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
1512 |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1513 |
if (shouldStop(CompileState.LOWER)) |
10 | 1514 |
return; |
1515 |
||
1516 |
if (sourceOutput) { |
|
1517 |
//emit standard Java source file, only for compilation |
|
1518 |
//units enumerated explicitly on the command line |
|
1519 |
JCClassDecl cdef = (JCClassDecl)env.tree; |
|
1520 |
if (untranslated instanceof JCClassDecl && |
|
1521 |
rootClasses.contains((JCClassDecl)untranslated)) { |
|
22163 | 1522 |
results.add(new Pair<>(env, cdef)); |
10 | 1523 |
} |
1524 |
return; |
|
1525 |
} |
|
1526 |
||
1527 |
//translate out inner classes |
|
1528 |
List<JCTree> cdefs = lower.translateTopLevelClass(env, env.tree, localMake); |
|
3557
a803afefa115
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
mcimadamore
parents:
3151
diff
changeset
|
1529 |
compileStates.put(env, CompileState.LOWER); |
10 | 1530 |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1531 |
if (shouldStop(CompileState.LOWER)) |
10 | 1532 |
return; |
1533 |
||
1534 |
//generate code for each class |
|
1535 |
for (List<JCTree> l = cdefs; l.nonEmpty(); l = l.tail) { |
|
1536 |
JCClassDecl cdef = (JCClassDecl)l.head; |
|
22163 | 1537 |
results.add(new Pair<>(env, cdef)); |
10 | 1538 |
} |
1539 |
} |
|
1540 |
finally { |
|
1541 |
log.useSource(prev); |
|
1542 |
} |
|
1543 |
||
1544 |
} |
|
1545 |
||
1546 |
/** Generates the source or class file for a list of classes. |
|
1547 |
* The decision to generate a source file or a class file is |
|
1548 |
* based upon the compiler's options. |
|
1549 |
* Generation stops if an error occurs while writing files. |
|
1550 |
*/ |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1551 |
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1552 |
generate(queue, null); |
10 | 1553 |
} |
1554 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1555 |
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) { |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1556 |
if (shouldStop(CompileState.GENERATE)) |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1557 |
return; |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1558 |
|
10 | 1559 |
boolean usePrintSource = (stubOutput || sourceOutput || printFlat); |
1560 |
||
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1561 |
for (Pair<Env<AttrContext>, JCClassDecl> x: queue) { |
10 | 1562 |
Env<AttrContext> env = x.fst; |
1563 |
JCClassDecl cdef = x.snd; |
|
1564 |
||
1565 |
if (verboseCompilePolicy) { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1566 |
printNote("[generate " |
10 | 1567 |
+ (usePrintSource ? " source" : "code") |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1568 |
+ " " + cdef.sym + "]"); |
10 | 1569 |
} |
1570 |
||
12016 | 1571 |
if (!taskListener.isEmpty()) { |
10 | 1572 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym); |
1573 |
taskListener.started(e); |
|
1574 |
} |
|
1575 |
||
1576 |
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? |
|
1577 |
env.enclClass.sym.sourcefile : |
|
1578 |
env.toplevel.sourcefile); |
|
1579 |
try { |
|
1580 |
JavaFileObject file; |
|
1581 |
if (usePrintSource) |
|
1582 |
file = printSource(env, cdef); |
|
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1583 |
else { |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1584 |
if (fileManager.hasLocation(StandardLocation.NATIVE_HEADER_OUTPUT) |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1585 |
&& jniWriter.needsHeader(cdef.sym)) { |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1586 |
jniWriter.write(cdef.sym); |
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1587 |
} |
10 | 1588 |
file = genCode(env, cdef); |
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
12016
diff
changeset
|
1589 |
} |
10 | 1590 |
if (results != null && file != null) |
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1260
diff
changeset
|
1591 |
results.add(file); |
10 | 1592 |
} catch (IOException ex) { |
1593 |
log.error(cdef.pos(), "class.cant.write", |
|
1594 |
cdef.sym, ex.getMessage()); |
|
1595 |
return; |
|
1596 |
} finally { |
|
1597 |
log.useSource(prev); |
|
1598 |
} |
|
1599 |
||
12016 | 1600 |
if (!taskListener.isEmpty()) { |
10 | 1601 |
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym); |
1602 |
taskListener.finished(e); |
|
1603 |
} |
|
1604 |
} |
|
1605 |
} |
|
1606 |
||
1607 |
// where |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1608 |
Map<JCCompilationUnit, Queue<Env<AttrContext>>> groupByFile(Queue<Env<AttrContext>> envs) { |
10 | 1609 |
// use a LinkedHashMap to preserve the order of the original list as much as possible |
22163 | 1610 |
Map<JCCompilationUnit, Queue<Env<AttrContext>>> map = new LinkedHashMap<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1611 |
for (Env<AttrContext> env: envs) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1612 |
Queue<Env<AttrContext>> sublist = map.get(env.toplevel); |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1613 |
if (sublist == null) { |
22163 | 1614 |
sublist = new ListBuffer<>(); |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1615 |
map.put(env.toplevel, sublist); |
10 | 1616 |
} |
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
1617 |
sublist.add(env); |
10 | 1618 |
} |
1619 |
return map; |
|
1620 |
} |
|
1621 |
||
1622 |
JCClassDecl removeMethodBodies(JCClassDecl cdef) { |
|
1623 |
final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0; |
|
1624 |
class MethodBodyRemover extends TreeTranslator { |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1625 |
@Override |
10 | 1626 |
public void visitMethodDef(JCMethodDecl tree) { |
1627 |
tree.mods.flags &= ~Flags.SYNCHRONIZED; |
|
1628 |
for (JCVariableDecl vd : tree.params) |
|
1629 |
vd.mods.flags &= ~Flags.FINAL; |
|
1630 |
tree.body = null; |
|
1631 |
super.visitMethodDef(tree); |
|
1632 |
} |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1633 |
@Override |
10 | 1634 |
public void visitVarDef(JCVariableDecl tree) { |
1635 |
if (tree.init != null && tree.init.type.constValue() == null) |
|
1636 |
tree.init = null; |
|
1637 |
super.visitVarDef(tree); |
|
1638 |
} |
|
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1639 |
@Override |
10 | 1640 |
public void visitClassDef(JCClassDecl tree) { |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19921
diff
changeset
|
1641 |
ListBuffer<JCTree> newdefs = new ListBuffer<>(); |
10 | 1642 |
for (List<JCTree> it = tree.defs; it.tail != null; it = it.tail) { |
1643 |
JCTree t = it.head; |
|
1644 |
switch (t.getTag()) { |
|
10950 | 1645 |
case CLASSDEF: |
10 | 1646 |
if (isInterface || |
1647 |
(((JCClassDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1648 |
(((JCClassDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCClassDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1649 |
newdefs.append(t); |
|
1650 |
break; |
|
10950 | 1651 |
case METHODDEF: |
10 | 1652 |
if (isInterface || |
1653 |
(((JCMethodDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
|
1654 |
((JCMethodDecl) t).sym.name == names.init || |
|
1655 |
(((JCMethodDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCMethodDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1656 |
newdefs.append(t); |
|
1657 |
break; |
|
10950 | 1658 |
case VARDEF: |
10 | 1659 |
if (isInterface || (((JCVariableDecl) t).mods.flags & (Flags.PROTECTED|Flags.PUBLIC)) != 0 || |
1660 |
(((JCVariableDecl) t).mods.flags & (Flags.PRIVATE)) == 0 && ((JCVariableDecl) t).sym.packge().getQualifiedName() == names.java_lang) |
|
1661 |
newdefs.append(t); |
|
1662 |
break; |
|
1663 |
default: |
|
1664 |
break; |
|
1665 |
} |
|
1666 |
} |
|
1667 |
tree.defs = newdefs.toList(); |
|
1668 |
super.visitClassDef(tree); |
|
1669 |
} |
|
1670 |
} |
|
1671 |
MethodBodyRemover r = new MethodBodyRemover(); |
|
1672 |
return r.translate(cdef); |
|
1673 |
} |
|
1674 |
||
1675 |
public void reportDeferredDiagnostics() { |
|
8624
7db12f12a04e
6986892: confusing warning given after errors in annotation processing
jjg
parents:
8623
diff
changeset
|
1676 |
if (errorCount() == 0 |
7db12f12a04e
6986892: confusing warning given after errors in annotation processing
jjg
parents:
8623
diff
changeset
|
1677 |
&& annotationProcessingOccurred |
10 | 1678 |
&& implicitSourceFilesRead |
1679 |
&& implicitSourcePolicy == ImplicitSourcePolicy.UNSET) { |
|
1680 |
if (explicitAnnotationProcessingRequested()) |
|
1681 |
log.warning("proc.use.implicit"); |
|
1682 |
else |
|
1683 |
log.warning("proc.use.proc.or.implicit"); |
|
1684 |
} |
|
1685 |
chk.reportDeferredDiagnostics(); |
|
17582
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
17578
diff
changeset
|
1686 |
if (log.compressedOutput) { |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
17578
diff
changeset
|
1687 |
log.mandatoryNote(null, "compressed.diags"); |
4079713129dd
8012003: Method diagnostics resolution need to be simplified in some cases
mcimadamore
parents:
17578
diff
changeset
|
1688 |
} |
10 | 1689 |
} |
1690 |
||
1691 |
/** Close the compiler, flushing the logs |
|
1692 |
*/ |
|
1693 |
public void close() { |
|
1694 |
rootClasses = null; |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24392
diff
changeset
|
1695 |
finder = null; |
10 | 1696 |
reader = null; |
1697 |
make = null; |
|
1698 |
writer = null; |
|
1699 |
enter = null; |
|
1700 |
if (todo != null) |
|
1701 |
todo.clear(); |
|
1702 |
todo = null; |
|
1703 |
parserFactory = null; |
|
1704 |
syms = null; |
|
1705 |
source = null; |
|
1706 |
attr = null; |
|
1707 |
chk = null; |
|
1708 |
gen = null; |
|
1709 |
flow = null; |
|
1710 |
transTypes = null; |
|
1711 |
lower = null; |
|
1712 |
annotate = null; |
|
1713 |
types = null; |
|
1714 |
||
1715 |
log.flush(); |
|
1716 |
try { |
|
1717 |
fileManager.flush(); |
|
1718 |
} catch (IOException e) { |
|
1719 |
throw new Abort(e); |
|
1720 |
} finally { |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1721 |
if (names != null) |
10 | 1722 |
names.dispose(); |
1723 |
names = null; |
|
10637
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1724 |
|
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1725 |
for (Closeable c: closeables) { |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1726 |
try { |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1727 |
c.close(); |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1728 |
} catch (IOException e) { |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1729 |
// When javac uses JDK 7 as a baseline, this code would be |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1730 |
// better written to set any/all exceptions from all the |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1731 |
// Closeables as suppressed exceptions on the FatalError |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1732 |
// that is thrown. |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1733 |
JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close"); |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1734 |
throw new FatalError(msg, e); |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1735 |
} |
2ea5fbb913ac
7092965: javac should not close processorClassLoader before end of compilation
jjg
parents:
8851
diff
changeset
|
1736 |
} |
17551
03f330c02d97
8004082: test/tools/javac/plugin/showtype/Test.java fails on windows: jtreg can't delete plugin.jar
jjg
parents:
16968
diff
changeset
|
1737 |
closeables = List.nil(); |
10 | 1738 |
} |
1739 |
} |
|
1740 |
||
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1741 |
protected void printNote(String lines) { |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
1742 |
log.printRawLines(Log.WriterKind.NOTICE, lines); |
2514
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1743 |
} |
f8929e3790b4
6813059: replace use of JavaCompiler.errorCount with shouldContinue
jjg
parents:
2212
diff
changeset
|
1744 |
|
10 | 1745 |
/** Print numbers of errors and warnings. |
1746 |
*/ |
|
14952 | 1747 |
public void printCount(String kind, int count) { |
10 | 1748 |
if (count != 0) { |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
6031
diff
changeset
|
1749 |
String key; |
10 | 1750 |
if (count == 1) |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
6031
diff
changeset
|
1751 |
key = "count." + kind; |
10 | 1752 |
else |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
6031
diff
changeset
|
1753 |
key = "count." + kind + ".plural"; |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
11052
diff
changeset
|
1754 |
log.printLines(WriterKind.ERROR, key, String.valueOf(count)); |
11052
65b9fa7eaf55
7108668: allow Log to be initialized and used earlier
jjg
parents:
10950
diff
changeset
|
1755 |
log.flush(Log.WriterKind.ERROR); |
10 | 1756 |
} |
1757 |
} |
|
1758 |
||
1759 |
private static long now() { |
|
1760 |
return System.currentTimeMillis(); |
|
1761 |
} |
|
1762 |
||
1763 |
private static long elapsed(long then) { |
|
1764 |
return now() - then; |
|
1765 |
} |
|
1766 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1767 |
public void newRound() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1768 |
inputFiles.clear(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23115
diff
changeset
|
1769 |
todo.clear(); |
10 | 1770 |
} |
1771 |
} |