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