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