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