author | alanb |
Thu, 17 Mar 2016 19:04:28 +0000 | |
changeset 36526 | 3b41f1c69604 |
parent 36492 | 12abe038f3d9 |
child 37759 | f0b5daef41b6 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35810 | 2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.processing; |
|
27 |
||
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
28 |
import java.io.Closeable; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
29 |
import java.io.File; |
36526 | 30 |
import java.io.IOException; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
31 |
import java.io.PrintWriter; |
9069
bcab4a29758f
6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents:
8847
diff
changeset
|
32 |
import java.io.StringWriter; |
36526 | 33 |
import java.lang.reflect.Method; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
34 |
import java.net.MalformedURLException; |
12016 | 35 |
import java.net.URL; |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
36 |
import java.nio.file.Path; |
12016 | 37 |
import java.util.*; |
38 |
import java.util.regex.*; |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
39 |
import java.util.stream.Collectors; |
10 | 40 |
|
41 |
import javax.annotation.processing.*; |
|
42 |
import javax.lang.model.SourceVersion; |
|
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
43 |
import javax.lang.model.element.*; |
10 | 44 |
import javax.lang.model.util.*; |
45 |
import javax.tools.JavaFileManager; |
|
12016 | 46 |
import javax.tools.JavaFileObject; |
36526 | 47 |
import javax.tools.JavaFileObject.Kind; |
10 | 48 |
import javax.tools.StandardJavaFileManager; |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
49 |
|
12016 | 50 |
import static javax.tools.StandardLocation.*; |
10 | 51 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
52 |
import com.sun.source.util.TaskEvent; |
12016 | 53 |
import com.sun.tools.javac.api.MultiTaskListener; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
54 |
import com.sun.tools.javac.code.*; |
36526 | 55 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
56 |
import com.sun.tools.javac.code.Symbol.*; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
57 |
import com.sun.tools.javac.code.Type.ClassType; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
58 |
import com.sun.tools.javac.code.Types; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
59 |
import com.sun.tools.javac.comp.AttrContext; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
60 |
import com.sun.tools.javac.comp.Check; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
61 |
import com.sun.tools.javac.comp.Enter; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
62 |
import com.sun.tools.javac.comp.Env; |
36526 | 63 |
import com.sun.tools.javac.comp.Modules; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
64 |
import com.sun.tools.javac.file.JavacFileManager; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
65 |
import com.sun.tools.javac.main.JavaCompiler; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
66 |
import com.sun.tools.javac.model.JavacElements; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
67 |
import com.sun.tools.javac.model.JavacTypes; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
68 |
import com.sun.tools.javac.platform.PlatformDescription; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
69 |
import com.sun.tools.javac.platform.PlatformDescription.PluginInfo; |
36526 | 70 |
import com.sun.tools.javac.resources.CompilerProperties.Errors; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
71 |
import com.sun.tools.javac.tree.*; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
72 |
import com.sun.tools.javac.tree.JCTree.*; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
73 |
import com.sun.tools.javac.util.Abort; |
8032 | 74 |
import com.sun.tools.javac.util.Assert; |
9071
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
75 |
import com.sun.tools.javac.util.ClientCodeException; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
76 |
import com.sun.tools.javac.util.Context; |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
77 |
import com.sun.tools.javac.util.Convert; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
78 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
79 |
import com.sun.tools.javac.util.DefinedBy.Api; |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
80 |
import com.sun.tools.javac.util.Iterators; |
6581 | 81 |
import com.sun.tools.javac.util.JCDiagnostic; |
12016 | 82 |
import com.sun.tools.javac.util.JavacMessages; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
83 |
import com.sun.tools.javac.util.List; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
84 |
import com.sun.tools.javac.util.Log; |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
27224
diff
changeset
|
85 |
import com.sun.tools.javac.util.MatchingUtils; |
36526 | 86 |
import com.sun.tools.javac.util.ModuleHelper; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
87 |
import com.sun.tools.javac.util.Name; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
735
diff
changeset
|
88 |
import com.sun.tools.javac.util.Names; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
169
diff
changeset
|
89 |
import com.sun.tools.javac.util.Options; |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
90 |
|
12016 | 91 |
import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
92 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
12016 | 93 |
import static com.sun.tools.javac.main.Option.*; |
16968 | 94 |
import static com.sun.tools.javac.comp.CompileStates.CompileState; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
95 |
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; |
10 | 96 |
|
97 |
/** |
|
98 |
* Objects of this class hold and manage the state needed to support |
|
99 |
* annotation processing. |
|
100 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5841
diff
changeset
|
101 |
* <p><b>This is NOT part of any supported API. |
10 | 102 |
* If you write code that depends on this, you do so at your own risk. |
103 |
* This code and its internal interfaces are subject to change or |
|
104 |
* deletion without notice.</b> |
|
105 |
*/ |
|
106 |
public class JavacProcessingEnvironment implements ProcessingEnvironment, Closeable { |
|
19651 | 107 |
private final Options options; |
10 | 108 |
|
109 |
private final boolean printProcessorInfo; |
|
110 |
private final boolean printRounds; |
|
111 |
private final boolean verbose; |
|
112 |
private final boolean lint; |
|
113 |
private final boolean fatalErrors; |
|
6153
277c719ff46e
6403456: -Werror should work with annotation processing
jjg
parents:
6143
diff
changeset
|
114 |
private final boolean werror; |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
115 |
private final boolean showResolveErrors; |
10 | 116 |
|
117 |
private final JavacFiler filer; |
|
118 |
private final JavacMessager messager; |
|
119 |
private final JavacElements elementUtils; |
|
120 |
private final JavacTypes typeUtils; |
|
36526 | 121 |
private final JavaCompiler compiler; |
122 |
private final Modules modules; |
|
123 |
private final ModuleHelper moduleHelper; |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
124 |
private final Types types; |
10 | 125 |
|
126 |
/** |
|
127 |
* Holds relevant state history of which processors have been |
|
128 |
* used. |
|
129 |
*/ |
|
130 |
private DiscoveredProcessors discoveredProcs; |
|
131 |
||
132 |
/** |
|
133 |
* Map of processor-specific options. |
|
134 |
*/ |
|
135 |
private final Map<String, String> processorOptions; |
|
136 |
||
137 |
/** |
|
138 |
*/ |
|
139 |
private final Set<String> unmatchedProcessorOptions; |
|
140 |
||
141 |
/** |
|
142 |
* Annotations implicitly processed and claimed by javac. |
|
143 |
*/ |
|
144 |
private final Set<String> platformAnnotations; |
|
145 |
||
146 |
/** |
|
147 |
* Set of packages given on command line. |
|
148 |
*/ |
|
149 |
private Set<PackageSymbol> specifiedPackages = Collections.emptySet(); |
|
150 |
||
151 |
/** The log to be used for error reporting. |
|
152 |
*/ |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
153 |
final Log log; |
10 | 154 |
|
6581 | 155 |
/** Diagnostic factory. |
156 |
*/ |
|
157 |
JCDiagnostic.Factory diags; |
|
158 |
||
10 | 159 |
/** |
160 |
* Source level of the compile. |
|
161 |
*/ |
|
162 |
Source source; |
|
163 |
||
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3300
diff
changeset
|
164 |
private ClassLoader processorClassLoader; |
36526 | 165 |
private ServiceLoader<Processor> serviceLoader; |
166 |
private SecurityException processorLoaderException; |
|
167 |
||
168 |
private final JavaFileManager fileManager; |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3300
diff
changeset
|
169 |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
170 |
/** |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
171 |
* JavacMessages object used for localization |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
172 |
*/ |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
173 |
private JavacMessages messages; |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
174 |
|
12016 | 175 |
private MultiTaskListener taskListener; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
176 |
private final Symtab symtab; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
177 |
private final Names names; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
178 |
private final Enter enter; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
179 |
private final Completer initialCompleter; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
180 |
private final Check chk; |
36526 | 181 |
private final ModuleSymbol defaultModule; |
12016 | 182 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
183 |
private final Context context; |
10 | 184 |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
185 |
/** Get the JavacProcessingEnvironment instance for this context. */ |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
186 |
public static JavacProcessingEnvironment instance(Context context) { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
187 |
JavacProcessingEnvironment instance = context.get(JavacProcessingEnvironment.class); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
188 |
if (instance == null) |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
189 |
instance = new JavacProcessingEnvironment(context); |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
190 |
return instance; |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
191 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
192 |
|
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
193 |
protected JavacProcessingEnvironment(Context context) { |
10 | 194 |
this.context = context; |
17551
03f330c02d97
8004082: test/tools/javac/plugin/showtype/Test.java fails on windows: jtreg can't delete plugin.jar
jjg
parents:
16968
diff
changeset
|
195 |
context.put(JavacProcessingEnvironment.class, this); |
10 | 196 |
log = Log.instance(context); |
197 |
source = Source.instance(context); |
|
6581 | 198 |
diags = JCDiagnostic.Factory.instance(context); |
199 |
options = Options.instance(context); |
|
6721 | 200 |
printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); |
201 |
printRounds = options.isSet(XPRINTROUNDS); |
|
202 |
verbose = options.isSet(VERBOSE); |
|
203 |
lint = Lint.instance(context).isEnabled(PROCESSING); |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
204 |
compiler = JavaCompiler.instance(context); |
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
14044
diff
changeset
|
205 |
if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
14044
diff
changeset
|
206 |
compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; |
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
14044
diff
changeset
|
207 |
} |
6721 | 208 |
fatalErrors = options.isSet("fatalEnterError"); |
209 |
showResolveErrors = options.isSet("showResolveErrors"); |
|
210 |
werror = options.isSet(WERROR); |
|
36526 | 211 |
fileManager = context.get(JavaFileManager.class); |
10 | 212 |
platformAnnotations = initPlatformAnnotations(); |
213 |
||
6924
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
6721
diff
changeset
|
214 |
// Initialize services before any processors are initialized |
10 | 215 |
// in case processors use them. |
216 |
filer = new JavacFiler(context); |
|
217 |
messager = new JavacMessager(context, this); |
|
6924
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
6721
diff
changeset
|
218 |
elementUtils = JavacElements.instance(context); |
ef7a9281ad2f
6988836: A new JavacElements is created for each round of annotation processing
jjg
parents:
6721
diff
changeset
|
219 |
typeUtils = JavacTypes.instance(context); |
36526 | 220 |
modules = Modules.instance(context); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
221 |
types = Types.instance(context); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
222 |
processorOptions = initProcessorOptions(); |
10 | 223 |
unmatchedProcessorOptions = initUnmatchedProcessorOptions(); |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
224 |
messages = JavacMessages.instance(context); |
12016 | 225 |
taskListener = MultiTaskListener.instance(context); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
226 |
symtab = Symtab.instance(context); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
227 |
names = Names.instance(context); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
228 |
enter = Enter.instance(context); |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
229 |
initialCompleter = ClassFinder.instance(context).getCompleter(); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
230 |
chk = Check.instance(context); |
36526 | 231 |
moduleHelper = ModuleHelper.instance(context); |
232 |
initProcessorLoader(); |
|
233 |
||
234 |
defaultModule = source.allowModules() && options.isUnset("noModules") |
|
235 |
? symtab.unnamedModule : symtab.noModule; |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
236 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
237 |
|
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
238 |
public void setProcessors(Iterable<? extends Processor> processors) { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
239 |
Assert.checkNull(discoveredProcs); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
240 |
initProcessorIterator(processors); |
10 | 241 |
} |
242 |
||
243 |
private Set<String> initPlatformAnnotations() { |
|
22163 | 244 |
Set<String> platformAnnotations = new HashSet<>(); |
10 | 245 |
platformAnnotations.add("java.lang.Deprecated"); |
246 |
platformAnnotations.add("java.lang.Override"); |
|
247 |
platformAnnotations.add("java.lang.SuppressWarnings"); |
|
248 |
platformAnnotations.add("java.lang.annotation.Documented"); |
|
249 |
platformAnnotations.add("java.lang.annotation.Inherited"); |
|
250 |
platformAnnotations.add("java.lang.annotation.Retention"); |
|
251 |
platformAnnotations.add("java.lang.annotation.Target"); |
|
252 |
return Collections.unmodifiableSet(platformAnnotations); |
|
253 |
} |
|
254 |
||
36526 | 255 |
private void initProcessorLoader() { |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
256 |
try { |
36526 | 257 |
if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) { |
258 |
try { |
|
259 |
serviceLoader = fileManager.getServiceLoader(ANNOTATION_PROCESSOR_MODULE_PATH, Processor.class); |
|
260 |
} catch (IOException e) { |
|
261 |
throw new Abort(e); |
|
262 |
} |
|
263 |
} else { |
|
264 |
// If processorpath is not explicitly set, use the classpath. |
|
265 |
processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) |
|
266 |
? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH) |
|
267 |
: fileManager.getClassLoader(CLASS_PATH); |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
268 |
|
36526 | 269 |
moduleHelper.addExports(processorClassLoader); |
270 |
||
271 |
if (processorClassLoader != null && processorClassLoader instanceof Closeable) { |
|
272 |
compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader); |
|
273 |
} |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
274 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
275 |
} catch (SecurityException e) { |
36526 | 276 |
processorLoaderException = e; |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
277 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
278 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
279 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
280 |
private void initProcessorIterator(Iterable<? extends Processor> processors) { |
10 | 281 |
Iterator<? extends Processor> processorIterator; |
282 |
||
6721 | 283 |
if (options.isSet(XPRINT)) { |
10 | 284 |
try { |
285 |
Processor processor = PrintingProcessor.class.newInstance(); |
|
286 |
processorIterator = List.of(processor).iterator(); |
|
287 |
} catch (Throwable t) { |
|
288 |
AssertionError assertError = |
|
289 |
new AssertionError("Problem instantiating PrintingProcessor."); |
|
290 |
assertError.initCause(t); |
|
291 |
throw assertError; |
|
292 |
} |
|
293 |
} else if (processors != null) { |
|
294 |
processorIterator = processors.iterator(); |
|
295 |
} else { |
|
36526 | 296 |
if (processorLoaderException == null) { |
10 | 297 |
/* |
298 |
* If the "-processor" option is used, search the appropriate |
|
299 |
* path for the named class. Otherwise, use a service |
|
300 |
* provider mechanism to create the processor iterator. |
|
301 |
*/ |
|
36526 | 302 |
String processorNames = options.get(PROCESSOR); |
303 |
if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) { |
|
304 |
processorIterator = (processorNames == null) ? |
|
305 |
new ServiceIterator(serviceLoader, log) : |
|
306 |
new NameServiceIterator(serviceLoader, log, processorNames); |
|
307 |
} else if (processorNames != null) { |
|
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3300
diff
changeset
|
308 |
processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log); |
10 | 309 |
} else { |
3656
d4e34b76b0c3
6558476: com/sun/tools/javac/Main.compile don't release file handles on return
jjg
parents:
3300
diff
changeset
|
310 |
processorIterator = new ServiceIterator(processorClassLoader, log); |
10 | 311 |
} |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
312 |
} else { |
10 | 313 |
/* |
314 |
* A security exception will occur if we can't create a classloader. |
|
315 |
* Ignore the exception if, with hindsight, we didn't need it anyway |
|
316 |
* (i.e. no processor was specified either explicitly, or implicitly, |
|
317 |
* in service configuration file.) Otherwise, we cannot continue. |
|
318 |
*/ |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
319 |
processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", |
36526 | 320 |
processorLoaderException); |
10 | 321 |
} |
322 |
} |
|
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
323 |
PlatformDescription platformProvider = context.get(PlatformDescription.class); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
324 |
java.util.List<Processor> platformProcessors = Collections.emptyList(); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
325 |
if (platformProvider != null) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
326 |
platformProcessors = platformProvider.getAnnotationProcessors() |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
327 |
.stream() |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
328 |
.map(ap -> ap.getPlugin()) |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
329 |
.collect(Collectors.toList()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
330 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
331 |
List<Iterator<? extends Processor>> iterators = List.of(processorIterator, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
332 |
platformProcessors.iterator()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
333 |
Iterator<? extends Processor> compoundIterator = |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
334 |
Iterators.createCompoundIterator(iterators, i -> i); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
335 |
discoveredProcs = new DiscoveredProcessors(compoundIterator); |
10 | 336 |
} |
337 |
||
36526 | 338 |
public <S> ServiceLoader<S> getServiceLoader(Class<S> service) { |
339 |
if (fileManager.hasLocation(ANNOTATION_PROCESSOR_MODULE_PATH)) { |
|
340 |
try { |
|
341 |
return fileManager.getServiceLoader(ANNOTATION_PROCESSOR_MODULE_PATH, service); |
|
342 |
} catch (IOException e) { |
|
343 |
throw new Abort(e); |
|
344 |
} |
|
345 |
} else { |
|
346 |
return ServiceLoader.load(service, getProcessorClassLoader()); |
|
347 |
} |
|
348 |
} |
|
349 |
||
10 | 350 |
/** |
351 |
* Returns an empty processor iterator if no processors are on the |
|
352 |
* relevant path, otherwise if processors are present, logs an |
|
353 |
* error. Called when a service loader is unavailable for some |
|
354 |
* reason, either because a service loader class cannot be found |
|
355 |
* or because a security policy prevents class loaders from being |
|
356 |
* created. |
|
357 |
* |
|
358 |
* @param key The resource key to use to log an error message |
|
359 |
* @param e If non-null, pass this exception to Abort |
|
360 |
*/ |
|
361 |
private Iterator<Processor> handleServiceLoaderUnavailability(String key, Exception e) { |
|
362 |
if (fileManager instanceof JavacFileManager) { |
|
363 |
StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager; |
|
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
364 |
Iterable<? extends Path> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH) |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
365 |
? standardFileManager.getLocationAsPaths(ANNOTATION_PROCESSOR_PATH) |
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
366 |
: standardFileManager.getLocationAsPaths(CLASS_PATH); |
10 | 367 |
|
6721 | 368 |
if (needClassLoader(options.get(PROCESSOR), workingPath) ) |
10 | 369 |
handleException(key, e); |
370 |
||
371 |
} else { |
|
372 |
handleException(key, e); |
|
373 |
} |
|
374 |
||
375 |
java.util.List<Processor> pl = Collections.emptyList(); |
|
376 |
return pl.iterator(); |
|
377 |
} |
|
378 |
||
379 |
/** |
|
380 |
* Handle a security exception thrown during initializing the |
|
381 |
* Processor iterator. |
|
382 |
*/ |
|
383 |
private void handleException(String key, Exception e) { |
|
384 |
if (e != null) { |
|
385 |
log.error(key, e.getLocalizedMessage()); |
|
386 |
throw new Abort(e); |
|
387 |
} else { |
|
388 |
log.error(key); |
|
389 |
throw new Abort(); |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
/** |
|
394 |
* Use a service loader appropriate for the platform to provide an |
|
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
395 |
* iterator over annotations processors; fails if a loader is |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
396 |
* needed but unavailable. |
10 | 397 |
*/ |
398 |
private class ServiceIterator implements Iterator<Processor> { |
|
36526 | 399 |
Iterator<Processor> iterator; |
400 |
Log log; |
|
401 |
ServiceLoader<Processor> loader; |
|
10 | 402 |
|
403 |
ServiceIterator(ClassLoader classLoader, Log log) { |
|
404 |
this.log = log; |
|
405 |
try { |
|
406 |
try { |
|
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
407 |
loader = ServiceLoader.load(Processor.class, classLoader); |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
408 |
this.iterator = loader.iterator(); |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
409 |
} catch (Exception e) { |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
410 |
// Fail softly if a loader is not actually needed. |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
411 |
this.iterator = handleServiceLoaderUnavailability("proc.no.service", null); |
10 | 412 |
} |
413 |
} catch (Throwable t) { |
|
414 |
log.error("proc.service.problem"); |
|
415 |
throw new Abort(t); |
|
416 |
} |
|
417 |
} |
|
418 |
||
36526 | 419 |
ServiceIterator(ServiceLoader<Processor> loader, Log log) { |
420 |
this.log = log; |
|
421 |
this.loader = loader; |
|
422 |
this.iterator = loader.iterator(); |
|
423 |
} |
|
424 |
||
425 |
@Override |
|
10 | 426 |
public boolean hasNext() { |
427 |
try { |
|
36526 | 428 |
return internalHasNext(); |
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
429 |
} catch(ServiceConfigurationError sce) { |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
430 |
log.error("proc.bad.config.file", sce.getLocalizedMessage()); |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
431 |
throw new Abort(sce); |
10 | 432 |
} catch (Throwable t) { |
433 |
throw new Abort(t); |
|
434 |
} |
|
435 |
} |
|
436 |
||
36526 | 437 |
boolean internalHasNext() { |
438 |
return iterator.hasNext(); |
|
439 |
} |
|
440 |
||
441 |
@Override |
|
10 | 442 |
public Processor next() { |
443 |
try { |
|
36526 | 444 |
return internalNext(); |
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
445 |
} catch (ServiceConfigurationError sce) { |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
446 |
log.error("proc.bad.config.file", sce.getLocalizedMessage()); |
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
447 |
throw new Abort(sce); |
10 | 448 |
} catch (Throwable t) { |
449 |
throw new Abort(t); |
|
450 |
} |
|
451 |
} |
|
452 |
||
36526 | 453 |
Processor internalNext() { |
454 |
return iterator.next(); |
|
455 |
} |
|
456 |
||
457 |
@Override |
|
10 | 458 |
public void remove() { |
459 |
throw new UnsupportedOperationException(); |
|
460 |
} |
|
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
461 |
|
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
462 |
public void close() { |
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
463 |
if (loader != null) { |
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
464 |
try { |
10186
31a86b7e18ca
6575445: Update annotation processor to only use java.util.ServiceLoader
darcy
parents:
10182
diff
changeset
|
465 |
loader.reload(); |
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
466 |
} catch(Exception e) { |
22163 | 467 |
// Ignore problems during a call to reload. |
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
468 |
} |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
469 |
} |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
470 |
} |
10 | 471 |
} |
472 |
||
36526 | 473 |
private class NameServiceIterator extends ServiceIterator { |
474 |
private Map<String, Processor> namedProcessorsMap = new HashMap<>();; |
|
475 |
private Iterator<String> processorNames = null; |
|
476 |
private Processor nextProc = null; |
|
477 |
||
478 |
public NameServiceIterator(ServiceLoader<Processor> loader, Log log, String theNames) { |
|
479 |
super(loader, log); |
|
480 |
this.processorNames = Arrays.asList(theNames.split(",")).iterator(); |
|
481 |
} |
|
482 |
||
483 |
@Override |
|
484 |
boolean internalHasNext() { |
|
485 |
if (nextProc != null) { |
|
486 |
return true; |
|
487 |
} |
|
488 |
if (!processorNames.hasNext()) { |
|
489 |
namedProcessorsMap = null; |
|
490 |
return false; |
|
491 |
} |
|
492 |
String processorName = processorNames.next(); |
|
493 |
Processor theProcessor = namedProcessorsMap.get(processorName); |
|
494 |
if (theProcessor != null) { |
|
495 |
namedProcessorsMap.remove(processorName); |
|
496 |
nextProc = theProcessor; |
|
497 |
return true; |
|
498 |
} else { |
|
499 |
while (iterator.hasNext()) { |
|
500 |
theProcessor = iterator.next(); |
|
501 |
String name = theProcessor.getClass().getName(); |
|
502 |
if (name.equals(processorName)) { |
|
503 |
nextProc = theProcessor; |
|
504 |
return true; |
|
505 |
} else { |
|
506 |
namedProcessorsMap.put(name, theProcessor); |
|
507 |
} |
|
508 |
} |
|
509 |
log.error(Errors.ProcProcessorNotFound(processorName)); |
|
510 |
return false; |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
@Override |
|
515 |
Processor internalNext() { |
|
516 |
if (hasNext()) { |
|
517 |
Processor p = nextProc; |
|
518 |
nextProc = null; |
|
519 |
return p; |
|
520 |
} else { |
|
521 |
throw new NoSuchElementException(); |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
10 | 525 |
|
526 |
private static class NameProcessIterator implements Iterator<Processor> { |
|
527 |
Processor nextProc = null; |
|
528 |
Iterator<String> names; |
|
529 |
ClassLoader processorCL; |
|
530 |
Log log; |
|
531 |
||
532 |
NameProcessIterator(String names, ClassLoader processorCL, Log log) { |
|
533 |
this.names = Arrays.asList(names.split(",")).iterator(); |
|
534 |
this.processorCL = processorCL; |
|
535 |
this.log = log; |
|
536 |
} |
|
537 |
||
538 |
public boolean hasNext() { |
|
539 |
if (nextProc != null) |
|
540 |
return true; |
|
541 |
else { |
|
542 |
if (!names.hasNext()) |
|
543 |
return false; |
|
544 |
else { |
|
545 |
String processorName = names.next(); |
|
546 |
||
547 |
Processor processor; |
|
548 |
try { |
|
549 |
try { |
|
36526 | 550 |
Class<?> processorClass = processorCL.loadClass(processorName); |
551 |
ensureReadable(processorClass); |
|
10 | 552 |
processor = |
36526 | 553 |
(Processor) (processorClass.newInstance()); |
10 | 554 |
} catch (ClassNotFoundException cnfe) { |
555 |
log.error("proc.processor.not.found", processorName); |
|
556 |
return false; |
|
557 |
} catch (ClassCastException cce) { |
|
558 |
log.error("proc.processor.wrong.type", processorName); |
|
559 |
return false; |
|
560 |
} catch (Exception e ) { |
|
561 |
log.error("proc.processor.cant.instantiate", processorName); |
|
562 |
return false; |
|
563 |
} |
|
9071
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
564 |
} catch(ClientCodeException e) { |
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
565 |
throw e; |
10 | 566 |
} catch(Throwable t) { |
567 |
throw new AnnotationProcessingError(t); |
|
568 |
} |
|
569 |
nextProc = processor; |
|
570 |
return true; |
|
571 |
} |
|
572 |
||
573 |
} |
|
574 |
} |
|
575 |
||
576 |
public Processor next() { |
|
577 |
if (hasNext()) { |
|
578 |
Processor p = nextProc; |
|
579 |
nextProc = null; |
|
580 |
return p; |
|
581 |
} else |
|
582 |
throw new NoSuchElementException(); |
|
583 |
} |
|
584 |
||
585 |
public void remove () { |
|
586 |
throw new UnsupportedOperationException(); |
|
587 |
} |
|
36526 | 588 |
|
589 |
/** |
|
590 |
* Ensures that the module of the given class is readable to this |
|
591 |
* module. |
|
592 |
*/ |
|
593 |
private void ensureReadable(Class<?> targetClass) { |
|
594 |
try { |
|
595 |
Method getModuleMethod = Class.class.getMethod("getModule"); |
|
596 |
Object thisModule = getModuleMethod.invoke(this.getClass()); |
|
597 |
Object targetModule = getModuleMethod.invoke(targetClass); |
|
598 |
||
599 |
Class<?> moduleClass = getModuleMethod.getReturnType(); |
|
600 |
Method addReadsMethod = moduleClass.getMethod("addReads", moduleClass); |
|
601 |
addReadsMethod.invoke(thisModule, targetModule); |
|
602 |
} catch (NoSuchMethodException e) { |
|
603 |
// ignore |
|
604 |
} catch (Exception e) { |
|
605 |
throw new InternalError(e); |
|
606 |
} |
|
607 |
} |
|
10 | 608 |
} |
609 |
||
610 |
public boolean atLeastOneProcessor() { |
|
611 |
return discoveredProcs.iterator().hasNext(); |
|
612 |
} |
|
613 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
614 |
private Map<String, String> initProcessorOptions() { |
10 | 615 |
Set<String> keySet = options.keySet(); |
22163 | 616 |
Map<String, String> tempOptions = new LinkedHashMap<>(); |
10 | 617 |
|
618 |
for(String key : keySet) { |
|
619 |
if (key.startsWith("-A") && key.length() > 2) { |
|
620 |
int sepIndex = key.indexOf('='); |
|
621 |
String candidateKey = null; |
|
622 |
String candidateValue = null; |
|
623 |
||
624 |
if (sepIndex == -1) |
|
625 |
candidateKey = key.substring(2); |
|
626 |
else if (sepIndex >= 3) { |
|
627 |
candidateKey = key.substring(2, sepIndex); |
|
628 |
candidateValue = (sepIndex < key.length()-1)? |
|
629 |
key.substring(sepIndex+1) : null; |
|
630 |
} |
|
631 |
tempOptions.put(candidateKey, candidateValue); |
|
632 |
} |
|
633 |
} |
|
634 |
||
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
635 |
PlatformDescription platformProvider = context.get(PlatformDescription.class); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
636 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
637 |
if (platformProvider != null) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
638 |
for (PluginInfo<Processor> ap : platformProvider.getAnnotationProcessors()) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
639 |
tempOptions.putAll(ap.getOptions()); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
640 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
641 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
30066
diff
changeset
|
642 |
|
10 | 643 |
return Collections.unmodifiableMap(tempOptions); |
644 |
} |
|
645 |
||
646 |
private Set<String> initUnmatchedProcessorOptions() { |
|
22163 | 647 |
Set<String> unmatchedProcessorOptions = new HashSet<>(); |
10 | 648 |
unmatchedProcessorOptions.addAll(processorOptions.keySet()); |
649 |
return unmatchedProcessorOptions; |
|
650 |
} |
|
651 |
||
652 |
/** |
|
653 |
* State about how a processor has been used by the tool. If a |
|
654 |
* processor has been used on a prior round, its process method is |
|
655 |
* called on all subsequent rounds, perhaps with an empty set of |
|
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
14044
diff
changeset
|
656 |
* annotations to process. The {@code annotationSupported} method |
10 | 657 |
* caches the supported annotation information from the first (and |
658 |
* only) getSupportedAnnotationTypes call to the processor. |
|
659 |
*/ |
|
660 |
static class ProcessorState { |
|
661 |
public Processor processor; |
|
662 |
public boolean contributed; |
|
663 |
private ArrayList<Pattern> supportedAnnotationPatterns; |
|
664 |
private ArrayList<String> supportedOptionNames; |
|
665 |
||
666 |
ProcessorState(Processor p, Log log, Source source, ProcessingEnvironment env) { |
|
667 |
processor = p; |
|
668 |
contributed = false; |
|
669 |
||
670 |
try { |
|
671 |
processor.init(env); |
|
672 |
||
673 |
checkSourceVersionCompatibility(source, log); |
|
674 |
||
22163 | 675 |
supportedAnnotationPatterns = new ArrayList<>(); |
10 | 676 |
for (String importString : processor.getSupportedAnnotationTypes()) { |
677 |
supportedAnnotationPatterns.add(importStringToPattern(importString, |
|
678 |
processor, |
|
679 |
log)); |
|
680 |
} |
|
681 |
||
22163 | 682 |
supportedOptionNames = new ArrayList<>(); |
10 | 683 |
for (String optionName : processor.getSupportedOptions() ) { |
684 |
if (checkOptionName(optionName, log)) |
|
685 |
supportedOptionNames.add(optionName); |
|
686 |
} |
|
687 |
||
9071
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
688 |
} catch (ClientCodeException e) { |
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
689 |
throw e; |
10 | 690 |
} catch (Throwable t) { |
691 |
throw new AnnotationProcessingError(t); |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
/** |
|
696 |
* Checks whether or not a processor's source version is |
|
697 |
* compatible with the compilation source version. The |
|
698 |
* processor's source version needs to be greater than or |
|
699 |
* equal to the source version of the compile. |
|
700 |
*/ |
|
701 |
private void checkSourceVersionCompatibility(Source source, Log log) { |
|
702 |
SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); |
|
703 |
||
704 |
if (procSourceVersion.compareTo(Source.toSourceVersion(source)) < 0 ) { |
|
705 |
log.warning("proc.processor.incompatible.source.version", |
|
706 |
procSourceVersion, |
|
707 |
processor.getClass().getName(), |
|
708 |
source.name); |
|
709 |
} |
|
710 |
} |
|
711 |
||
712 |
private boolean checkOptionName(String optionName, Log log) { |
|
713 |
boolean valid = isValidOptionName(optionName); |
|
714 |
if (!valid) |
|
715 |
log.error("proc.processor.bad.option.name", |
|
716 |
optionName, |
|
717 |
processor.getClass().getName()); |
|
718 |
return valid; |
|
719 |
} |
|
720 |
||
721 |
public boolean annotationSupported(String annotationName) { |
|
722 |
for(Pattern p: supportedAnnotationPatterns) { |
|
723 |
if (p.matcher(annotationName).matches()) |
|
724 |
return true; |
|
725 |
} |
|
726 |
return false; |
|
727 |
} |
|
728 |
||
729 |
/** |
|
730 |
* Remove options that are matched by this processor. |
|
731 |
*/ |
|
732 |
public void removeSupportedOptions(Set<String> unmatchedProcessorOptions) { |
|
733 |
unmatchedProcessorOptions.removeAll(supportedOptionNames); |
|
734 |
} |
|
735 |
} |
|
736 |
||
737 |
// TODO: These two classes can probably be rewritten better... |
|
738 |
/** |
|
739 |
* This class holds information about the processors that have |
|
36526 | 740 |
* been discovered so far as well as the means to discover more, if |
10 | 741 |
* necessary. A single iterator should be used per round of |
742 |
* annotation processing. The iterator first visits already |
|
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
743 |
* discovered processors then fails over to the service provider |
10 | 744 |
* mechanism if additional queries are made. |
745 |
*/ |
|
746 |
class DiscoveredProcessors implements Iterable<ProcessorState> { |
|
747 |
||
748 |
class ProcessorStateIterator implements Iterator<ProcessorState> { |
|
749 |
DiscoveredProcessors psi; |
|
750 |
Iterator<ProcessorState> innerIter; |
|
751 |
boolean onProcInterator; |
|
752 |
||
753 |
ProcessorStateIterator(DiscoveredProcessors psi) { |
|
754 |
this.psi = psi; |
|
755 |
this.innerIter = psi.procStateList.iterator(); |
|
756 |
this.onProcInterator = false; |
|
757 |
} |
|
758 |
||
759 |
public ProcessorState next() { |
|
760 |
if (!onProcInterator) { |
|
761 |
if (innerIter.hasNext()) |
|
762 |
return innerIter.next(); |
|
763 |
else |
|
764 |
onProcInterator = true; |
|
765 |
} |
|
766 |
||
767 |
if (psi.processorIterator.hasNext()) { |
|
768 |
ProcessorState ps = new ProcessorState(psi.processorIterator.next(), |
|
769 |
log, source, JavacProcessingEnvironment.this); |
|
770 |
psi.procStateList.add(ps); |
|
771 |
return ps; |
|
772 |
} else |
|
773 |
throw new NoSuchElementException(); |
|
774 |
} |
|
775 |
||
776 |
public boolean hasNext() { |
|
777 |
if (onProcInterator) |
|
778 |
return psi.processorIterator.hasNext(); |
|
779 |
else |
|
780 |
return innerIter.hasNext() || psi.processorIterator.hasNext(); |
|
781 |
} |
|
782 |
||
783 |
public void remove () { |
|
784 |
throw new UnsupportedOperationException(); |
|
785 |
} |
|
786 |
||
787 |
/** |
|
788 |
* Run all remaining processors on the procStateList that |
|
789 |
* have not already run this round with an empty set of |
|
790 |
* annotations. |
|
791 |
*/ |
|
792 |
public void runContributingProcs(RoundEnvironment re) { |
|
793 |
if (!onProcInterator) { |
|
794 |
Set<TypeElement> emptyTypeElements = Collections.emptySet(); |
|
795 |
while(innerIter.hasNext()) { |
|
796 |
ProcessorState ps = innerIter.next(); |
|
797 |
if (ps.contributed) |
|
798 |
callProcessor(ps.processor, emptyTypeElements, re); |
|
799 |
} |
|
800 |
} |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
Iterator<? extends Processor> processorIterator; |
|
805 |
ArrayList<ProcessorState> procStateList; |
|
806 |
||
807 |
public ProcessorStateIterator iterator() { |
|
808 |
return new ProcessorStateIterator(this); |
|
809 |
} |
|
810 |
||
811 |
DiscoveredProcessors(Iterator<? extends Processor> processorIterator) { |
|
812 |
this.processorIterator = processorIterator; |
|
22163 | 813 |
this.procStateList = new ArrayList<>(); |
10 | 814 |
} |
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
815 |
|
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
816 |
/** |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
817 |
* Free jar files, etc. if using a service loader. |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
818 |
*/ |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
819 |
public void close() { |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
820 |
if (processorIterator != null && |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
821 |
processorIterator instanceof ServiceIterator) { |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
822 |
((ServiceIterator) processorIterator).close(); |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
823 |
} |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
824 |
} |
10 | 825 |
} |
826 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
827 |
private void discoverAndRunProcs(Set<TypeElement> annotationsPresent, |
10 | 828 |
List<ClassSymbol> topLevelClasses, |
829 |
List<PackageSymbol> packageInfoFiles) { |
|
22163 | 830 |
Map<String, TypeElement> unmatchedAnnotations = new HashMap<>(annotationsPresent.size()); |
10 | 831 |
|
832 |
for(TypeElement a : annotationsPresent) { |
|
833 |
unmatchedAnnotations.put(a.getQualifiedName().toString(), |
|
834 |
a); |
|
835 |
} |
|
836 |
||
837 |
// Give "*" processors a chance to match |
|
838 |
if (unmatchedAnnotations.size() == 0) |
|
839 |
unmatchedAnnotations.put("", null); |
|
840 |
||
841 |
DiscoveredProcessors.ProcessorStateIterator psi = discoveredProcs.iterator(); |
|
842 |
// TODO: Create proper argument values; need past round |
|
843 |
// information to fill in this constructor. Note that the 1 |
|
844 |
// st round of processing could be the last round if there |
|
845 |
// were parse errors on the initial source files; however, we |
|
846 |
// are not doing processing in that case. |
|
847 |
||
22163 | 848 |
Set<Element> rootElements = new LinkedHashSet<>(); |
10 | 849 |
rootElements.addAll(topLevelClasses); |
850 |
rootElements.addAll(packageInfoFiles); |
|
851 |
rootElements = Collections.unmodifiableSet(rootElements); |
|
852 |
||
853 |
RoundEnvironment renv = new JavacRoundEnvironment(false, |
|
854 |
false, |
|
855 |
rootElements, |
|
856 |
JavacProcessingEnvironment.this); |
|
857 |
||
858 |
while(unmatchedAnnotations.size() > 0 && psi.hasNext() ) { |
|
859 |
ProcessorState ps = psi.next(); |
|
22163 | 860 |
Set<String> matchedNames = new HashSet<>(); |
861 |
Set<TypeElement> typeElements = new LinkedHashSet<>(); |
|
5003
fd0b30cdbe5c
6929645: Address various findbugs warnings in langtools
darcy
parents:
5001
diff
changeset
|
862 |
|
fd0b30cdbe5c
6929645: Address various findbugs warnings in langtools
darcy
parents:
5001
diff
changeset
|
863 |
for (Map.Entry<String, TypeElement> entry: unmatchedAnnotations.entrySet()) { |
fd0b30cdbe5c
6929645: Address various findbugs warnings in langtools
darcy
parents:
5001
diff
changeset
|
864 |
String unmatchedAnnotationName = entry.getKey(); |
10 | 865 |
if (ps.annotationSupported(unmatchedAnnotationName) ) { |
866 |
matchedNames.add(unmatchedAnnotationName); |
|
5003
fd0b30cdbe5c
6929645: Address various findbugs warnings in langtools
darcy
parents:
5001
diff
changeset
|
867 |
TypeElement te = entry.getValue(); |
10 | 868 |
if (te != null) |
869 |
typeElements.add(te); |
|
870 |
} |
|
871 |
} |
|
872 |
||
873 |
if (matchedNames.size() > 0 || ps.contributed) { |
|
874 |
boolean processingResult = callProcessor(ps.processor, typeElements, renv); |
|
875 |
ps.contributed = true; |
|
876 |
ps.removeSupportedOptions(unmatchedProcessorOptions); |
|
877 |
||
878 |
if (printProcessorInfo || verbose) { |
|
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
10950
diff
changeset
|
879 |
log.printLines("x.print.processor.info", |
6143
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5847
diff
changeset
|
880 |
ps.processor.getClass().getName(), |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5847
diff
changeset
|
881 |
matchedNames.toString(), |
79b7dee406cc
6966732: replace use of static Log.getLocalizedString with non-static alternative where possible
jjg
parents:
5847
diff
changeset
|
882 |
processingResult); |
10 | 883 |
} |
884 |
||
885 |
if (processingResult) { |
|
886 |
unmatchedAnnotations.keySet().removeAll(matchedNames); |
|
887 |
} |
|
888 |
||
889 |
} |
|
890 |
} |
|
891 |
unmatchedAnnotations.remove(""); |
|
892 |
||
893 |
if (lint && unmatchedAnnotations.size() > 0) { |
|
894 |
// Remove annotations processed by javac |
|
895 |
unmatchedAnnotations.keySet().removeAll(platformAnnotations); |
|
896 |
if (unmatchedAnnotations.size() > 0) { |
|
897 |
log.warning("proc.annotations.without.processors", |
|
898 |
unmatchedAnnotations.keySet()); |
|
899 |
} |
|
900 |
} |
|
901 |
||
902 |
// Run contributing processors that haven't run yet |
|
903 |
psi.runContributingProcs(renv); |
|
904 |
} |
|
905 |
||
906 |
/** |
|
907 |
* Computes the set of annotations on the symbol in question. |
|
908 |
* Leave class public for external testing purposes. |
|
909 |
*/ |
|
910 |
public static class ComputeAnnotationSet extends |
|
25690
b1dac768ab79
8050430: Provided new utility visitors supporting SourceVersion.RELEASE_9
darcy
parents:
24604
diff
changeset
|
911 |
ElementScanner9<Set<TypeElement>, Set<TypeElement>> { |
10 | 912 |
final Elements elements; |
913 |
||
914 |
public ComputeAnnotationSet(Elements elements) { |
|
915 |
super(); |
|
916 |
this.elements = elements; |
|
917 |
} |
|
918 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
919 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
10 | 920 |
public Set<TypeElement> visitPackage(PackageElement e, Set<TypeElement> p) { |
921 |
// Don't scan enclosed elements of a package |
|
922 |
return p; |
|
923 |
} |
|
924 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
925 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
926 |
public Set<TypeElement> visitType(TypeElement e, Set<TypeElement> p) { |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
927 |
// Type parameters are not considered to be enclosed by a type |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
928 |
scan(e.getTypeParameters(), p); |
23795
62509b72088e
8038080: annotation processors don't visit declaration parameter annotations
jfranck
parents:
22442
diff
changeset
|
929 |
return super.visitType(e, p); |
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
930 |
} |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
931 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
932 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
933 |
public Set<TypeElement> visitExecutable(ExecutableElement e, Set<TypeElement> p) { |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
934 |
// Type parameters are not considered to be enclosed by an executable |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
935 |
scan(e.getTypeParameters(), p); |
23795
62509b72088e
8038080: annotation processors don't visit declaration parameter annotations
jfranck
parents:
22442
diff
changeset
|
936 |
return super.visitExecutable(e, p); |
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
937 |
} |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
938 |
|
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
939 |
void addAnnotations(Element e, Set<TypeElement> p) { |
10 | 940 |
for (AnnotationMirror annotationMirror : |
941 |
elements.getAllAnnotationMirrors(e) ) { |
|
942 |
Element e2 = annotationMirror.getAnnotationType().asElement(); |
|
943 |
p.add((TypeElement) e2); |
|
944 |
} |
|
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
945 |
} |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
946 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
947 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
18669
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
948 |
public Set<TypeElement> scan(Element e, Set<TypeElement> p) { |
99572d59c916
7162089: Add support for repeating annotations to javax.annotation.processing
darcy
parents:
17551
diff
changeset
|
949 |
addAnnotations(e, p); |
10 | 950 |
return super.scan(e, p); |
951 |
} |
|
952 |
} |
|
953 |
||
954 |
private boolean callProcessor(Processor proc, |
|
955 |
Set<? extends TypeElement> tes, |
|
956 |
RoundEnvironment renv) { |
|
957 |
try { |
|
958 |
return proc.process(tes, renv); |
|
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
959 |
} catch (ClassFinder.BadClassFile ex) { |
9077
6ee59e40b258
7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
9071
diff
changeset
|
960 |
log.error("proc.cant.access.1", ex.sym, ex.getDetailValue()); |
6ee59e40b258
7031108: NPE in javac.jvm.ClassReader.findMethod in PackageElement.enclosedElements from AP in incr build
jjg
parents:
9071
diff
changeset
|
961 |
return false; |
10 | 962 |
} catch (CompletionFailure ex) { |
963 |
StringWriter out = new StringWriter(); |
|
964 |
ex.printStackTrace(new PrintWriter(out)); |
|
169 | 965 |
log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString()); |
10 | 966 |
return false; |
9071
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
967 |
} catch (ClientCodeException e) { |
88cd61b4e5aa
6437138: JSR 199: Compiler doesn't diagnose crash in user code
jjg
parents:
9069
diff
changeset
|
968 |
throw e; |
10 | 969 |
} catch (Throwable t) { |
970 |
throw new AnnotationProcessingError(t); |
|
971 |
} |
|
972 |
} |
|
973 |
||
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
974 |
/** |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
975 |
* Helper object for a single round of annotation processing. |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
976 |
*/ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
977 |
class Round { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
978 |
/** The round number. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
979 |
final int number; |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
980 |
/** The diagnostic handler for the round. */ |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
981 |
final Log.DeferredDiagnosticHandler deferredDiagnosticHandler; |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
982 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
983 |
/** The ASTs to be compiled. */ |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
984 |
List<JCCompilationUnit> roots; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
985 |
/** The trees that need to be cleaned - includes roots and implicitly parsed trees. */ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
986 |
Set<JCCompilationUnit> treesToClean; |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
987 |
/** The classes to be compiler that have were generated. */ |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
988 |
Map<String, JavaFileObject> genClassFiles; |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
989 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
990 |
/** The set of annotations to be processed this round. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
991 |
Set<TypeElement> annotationsPresent; |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
992 |
/** The set of top level classes to be processed this round. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
993 |
List<ClassSymbol> topLevelClasses; |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
994 |
/** The set of package-info files to be processed this round. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
995 |
List<PackageSymbol> packageInfoFiles; |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
996 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
997 |
/** Create a round (common code). */ |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
998 |
private Round(int number, Set<JCCompilationUnit> treesToClean, |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
999 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1000 |
this.number = number; |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1001 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1002 |
if (number == 1) { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1003 |
Assert.checkNonNull(deferredDiagnosticHandler); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1004 |
this.deferredDiagnosticHandler = deferredDiagnosticHandler; |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1005 |
} else { |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1006 |
this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1007 |
compiler.setDeferredDiagnosticHandler(this.deferredDiagnosticHandler); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1008 |
} |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1009 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1010 |
// the following will be populated as needed |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1011 |
topLevelClasses = List.nil(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1012 |
packageInfoFiles = List.nil(); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1013 |
this.treesToClean = treesToClean; |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1014 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1015 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1016 |
/** Create the first round. */ |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1017 |
Round(List<JCCompilationUnit> roots, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1018 |
List<ClassSymbol> classSymbols, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1019 |
Set<JCCompilationUnit> treesToClean, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1020 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1021 |
this(1, treesToClean, deferredDiagnosticHandler); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1022 |
this.roots = roots; |
22163 | 1023 |
genClassFiles = new HashMap<>(); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1024 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1025 |
// The reverse() in the following line is to maintain behavioural |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1026 |
// compatibility with the previous revision of the code. Strictly speaking, |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1027 |
// it should not be necessary, but a javah golden file test fails without it. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1028 |
topLevelClasses = |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1029 |
getTopLevelClasses(roots).prependList(classSymbols.reverse()); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1030 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1031 |
packageInfoFiles = getPackageInfoFiles(roots); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1032 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1033 |
findAnnotationsPresent(); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1034 |
} |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1035 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1036 |
/** Create a new round. */ |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1037 |
private Round(Round prev, |
6581 | 1038 |
Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1039 |
this(prev.number+1, prev.treesToClean, null); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1040 |
prev.newRound(); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1041 |
this.genClassFiles = prev.genClassFiles; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1042 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1043 |
List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1044 |
roots = prev.roots.appendList(parsedFiles); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1045 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1046 |
// Check for errors after parsing |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1047 |
if (unrecoverableError()) |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1048 |
return; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1049 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1050 |
enterClassFiles(genClassFiles); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1051 |
List<ClassSymbol> newClasses = enterClassFiles(newClassFiles); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1052 |
genClassFiles.putAll(newClassFiles); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1053 |
enterTrees(roots); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1054 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1055 |
if (unrecoverableError()) |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1056 |
return; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1057 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1058 |
topLevelClasses = join( |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1059 |
getTopLevelClasses(parsedFiles), |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1060 |
getTopLevelClassesFromClasses(newClasses)); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1061 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1062 |
packageInfoFiles = join( |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1063 |
getPackageInfoFiles(parsedFiles), |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1064 |
getPackageInfoFilesFromClasses(newClasses)); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1065 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1066 |
findAnnotationsPresent(); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1067 |
} |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1068 |
|
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1069 |
/** Create the next round to be used. */ |
6581 | 1070 |
Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1071 |
return new Round(this, newSourceFiles, newClassFiles); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1072 |
} |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1073 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1074 |
/** Prepare the compiler for the final compilation. */ |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1075 |
void finalCompiler() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1076 |
newRound(); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1077 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1078 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1079 |
/** Return the number of errors found so far in this round. |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1080 |
* This may include uncoverable errors, such as parse errors, |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1081 |
* and transient errors, such as missing symbols. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1082 |
int errorCount() { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1083 |
return compiler.errorCount(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1084 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1085 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1086 |
/** Return the number of warnings found so far in this round. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1087 |
int warningCount() { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1088 |
return compiler.warningCount(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1089 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1090 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1091 |
/** Return whether or not an unrecoverable error has occurred. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1092 |
boolean unrecoverableError() { |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1093 |
if (messager.errorRaised()) |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1094 |
return true; |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1095 |
|
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1096 |
for (JCDiagnostic d: deferredDiagnosticHandler.getDiagnostics()) { |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1097 |
switch (d.getKind()) { |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1098 |
case WARNING: |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1099 |
if (werror) |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1100 |
return true; |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1101 |
break; |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1102 |
|
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1103 |
case ERROR: |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7072
diff
changeset
|
1104 |
if (fatalErrors || !d.isFlagSet(RECOVERABLE)) |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1105 |
return true; |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1106 |
break; |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1107 |
} |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1108 |
} |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1109 |
|
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1110 |
return false; |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1111 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1112 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1113 |
/** Find the set of annotations present in the set of top level |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1114 |
* classes and package info files to be processed this round. */ |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1115 |
void findAnnotationsPresent() { |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1116 |
ComputeAnnotationSet annotationComputer = new ComputeAnnotationSet(elementUtils); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1117 |
// Use annotation processing to compute the set of annotations present |
22163 | 1118 |
annotationsPresent = new LinkedHashSet<>(); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1119 |
for (ClassSymbol classSym : topLevelClasses) |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1120 |
annotationComputer.scan(classSym, annotationsPresent); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1121 |
for (PackageSymbol pkgSym : packageInfoFiles) |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1122 |
annotationComputer.scan(pkgSym, annotationsPresent); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1123 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1124 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1125 |
/** Enter a set of generated class files. */ |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1126 |
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) { |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1127 |
List<ClassSymbol> list = List.nil(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1128 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1129 |
for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) { |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1130 |
Name name = names.fromString(entry.getKey()); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1131 |
JavaFileObject file = entry.getValue(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1132 |
if (file.getKind() != JavaFileObject.Kind.CLASS) |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1133 |
throw new AssertionError(file); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1134 |
ClassSymbol cs; |
36526 | 1135 |
// TODO: for now, we assume that generated code is in a default module; |
1136 |
// in time, we need a way to be able to specify the module for generated code |
|
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1137 |
if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1138 |
Name packageName = Convert.packagePart(name); |
36526 | 1139 |
PackageSymbol p = symtab.enterPackage(defaultModule, packageName); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1140 |
if (p.package_info == null) |
36526 | 1141 |
p.package_info = symtab.enterClass(defaultModule, Convert.shortName(name), p); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1142 |
cs = p.package_info; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1143 |
cs.reset(); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1144 |
if (cs.classfile == null) |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1145 |
cs.classfile = file; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1146 |
cs.completer = initialCompleter; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1147 |
} else { |
36526 | 1148 |
cs = symtab.enterClass(defaultModule, name); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1149 |
cs.reset(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1150 |
cs.classfile = file; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1151 |
cs.completer = initialCompleter; |
36526 | 1152 |
cs.owner.members().enter(cs); //XXX - OverwriteBetweenCompilations; syms.getClass is not sufficient anymore |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1153 |
} |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1154 |
list = list.prepend(cs); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1155 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1156 |
return list.reverse(); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1157 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1158 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1159 |
/** Enter a set of syntax trees. */ |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1160 |
private void enterTrees(List<JCCompilationUnit> roots) { |
36526 | 1161 |
compiler.enterTrees(compiler.initModules(roots)); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1162 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1163 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1164 |
/** Run a processing round. */ |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1165 |
void run(boolean lastRound, boolean errorStatus) { |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1166 |
printRoundInfo(lastRound); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1167 |
|
12016 | 1168 |
if (!taskListener.isEmpty()) |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1169 |
taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1170 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1171 |
try { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1172 |
if (lastRound) { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1173 |
filer.setLastRound(true); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1174 |
Set<Element> emptyRootElements = Collections.emptySet(); // immutable |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1175 |
RoundEnvironment renv = new JavacRoundEnvironment(true, |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1176 |
errorStatus, |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1177 |
emptyRootElements, |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1178 |
JavacProcessingEnvironment.this); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1179 |
discoveredProcs.iterator().runContributingProcs(renv); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1180 |
} else { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1181 |
discoverAndRunProcs(annotationsPresent, topLevelClasses, packageInfoFiles); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1182 |
} |
20615
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1183 |
} catch (Throwable t) { |
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1184 |
// we're specifically expecting Abort here, but if any Throwable |
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1185 |
// comes by, we should flush all deferred diagnostics, rather than |
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1186 |
// drop them on the ground. |
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1187 |
deferredDiagnosticHandler.reportDeferredDiagnostics(); |
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1188 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1189 |
compiler.setDeferredDiagnosticHandler(null); |
20615
77f2d47729b0
8022163: javac exits with 0 status and no messages on error to construct an ann-procesor
jjg
parents:
19651
diff
changeset
|
1190 |
throw t; |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1191 |
} finally { |
12016 | 1192 |
if (!taskListener.isEmpty()) |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1193 |
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1194 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1195 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1196 |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1197 |
void showDiagnostics(boolean showAll) { |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1198 |
Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1199 |
if (!showAll) { |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1200 |
// suppress errors, which are all presumed to be transient resolve errors |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1201 |
kinds.remove(JCDiagnostic.Kind.ERROR); |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1202 |
} |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1203 |
deferredDiagnosticHandler.reportDeferredDiagnostics(kinds); |
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14057
diff
changeset
|
1204 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1205 |
compiler.setDeferredDiagnosticHandler(null); |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1206 |
} |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1207 |
|
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1208 |
/** Print info about this round. */ |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1209 |
private void printRoundInfo(boolean lastRound) { |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1210 |
if (printRounds || verbose) { |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1211 |
List<ClassSymbol> tlc = lastRound ? List.<ClassSymbol>nil() : topLevelClasses; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1212 |
Set<TypeElement> ap = lastRound ? Collections.<TypeElement>emptySet() : annotationsPresent; |
11053
48713f779b1d
7108669: cleanup Log methods for direct printing to streams
jjg
parents:
10950
diff
changeset
|
1213 |
log.printLines("x.print.rounds", |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1214 |
number, |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1215 |
"{" + tlc.toString(", ") + "}", |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1216 |
ap, |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1217 |
lastRound); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1218 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1219 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1220 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1221 |
/** Prepare for new round of annotation processing. Cleans trees, resets symbols, and |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1222 |
* asks selected services to prepare to a new round of annotation processing. |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1223 |
*/ |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1224 |
private void newRound() { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1225 |
//ensure treesToClean contains all trees, including implicitly parsed ones |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1226 |
for (Env<AttrContext> env : enter.getEnvs()) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1227 |
treesToClean.add(env.toplevel); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1228 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1229 |
for (JCCompilationUnit node : treesToClean) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1230 |
treeCleaner.scan(node); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1231 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1232 |
chk.newRound(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1233 |
enter.newRound(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1234 |
filer.newRound(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1235 |
messager.newRound(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1236 |
compiler.newRound(); |
36526 | 1237 |
modules.newRound(); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1238 |
types.newRound(); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1239 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1240 |
boolean foundError = false; |
11316
4dcad625e72e
7111022: javac no long prints last round of processing
jjg
parents:
11314
diff
changeset
|
1241 |
|
36526 | 1242 |
for (ClassSymbol cs : symtab.getAllClasses()) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
1243 |
if (cs.kind == ERR) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1244 |
foundError = true; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1245 |
break; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1246 |
} |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1247 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1248 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1249 |
if (foundError) { |
36526 | 1250 |
for (ClassSymbol cs : symtab.getAllClasses()) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
1251 |
if (cs.classfile != null || cs.kind == ERR) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1252 |
cs.reset(); |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26266
diff
changeset
|
1253 |
cs.type = new ClassType(cs.type.getEnclosingType(), null, cs); |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29427
diff
changeset
|
1254 |
if (cs.isCompleted()) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1255 |
cs.completer = initialCompleter; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1256 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1257 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1258 |
} |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1259 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1260 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1261 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1262 |
|
10 | 1263 |
|
1264 |
// TODO: internal catch clauses?; catch and rethrow an annotation |
|
1265 |
// processing error |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1266 |
public boolean doProcessing(List<JCCompilationUnit> roots, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1267 |
List<ClassSymbol> classSymbols, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1268 |
Iterable<? extends PackageSymbol> pckSymbols, |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1269 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1270 |
final Set<JCCompilationUnit> treesToClean = |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1271 |
Collections.newSetFromMap(new IdentityHashMap<JCCompilationUnit, Boolean>()); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1272 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1273 |
//fill already attributed implicit trees: |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1274 |
for (Env<AttrContext> env : enter.getEnvs()) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1275 |
treesToClean.add(env.toplevel); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1276 |
} |
10 | 1277 |
|
22163 | 1278 |
Set<PackageSymbol> specifiedPackages = new LinkedHashSet<>(); |
10 | 1279 |
for (PackageSymbol psym : pckSymbols) |
1280 |
specifiedPackages.add(psym); |
|
1281 |
this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); |
|
1282 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1283 |
Round round = new Round(roots, classSymbols, treesToClean, deferredDiagnosticHandler); |
10 | 1284 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1285 |
boolean errorStatus; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1286 |
boolean moreToDo; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1287 |
do { |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1288 |
// Run processors for round n |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1289 |
round.run(false, false); |
10 | 1290 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1291 |
// Processors for round n have run to completion. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1292 |
// Check for errors and whether there is more work to do. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1293 |
errorStatus = round.unrecoverableError(); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1294 |
moreToDo = moreToDo(); |
10 | 1295 |
|
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1296 |
round.showDiagnostics(errorStatus || showResolveErrors); |
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1297 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1298 |
// Set up next round. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1299 |
// Copy mutable collections returned from filer. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1300 |
round = round.next( |
22163 | 1301 |
new LinkedHashSet<>(filer.getGeneratedSourceFileObjects()), |
1302 |
new LinkedHashMap<>(filer.getGeneratedClasses())); |
|
10 | 1303 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1304 |
// Check for errors during setup. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1305 |
if (round.unrecoverableError()) |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1306 |
errorStatus = true; |
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1307 |
|
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1308 |
} while (moreToDo && !errorStatus); |
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1309 |
|
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1310 |
// run last round |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1311 |
round.run(true, errorStatus); |
6582
c7a4fb5a2f86
6403465: javac should defer diagnostics until it can be determined they are persistent
jjg
parents:
6581
diff
changeset
|
1312 |
round.showDiagnostics(true); |
10 | 1313 |
|
1314 |
filer.warnIfUnclosedFiles(); |
|
1315 |
warnIfUnmatchedOptions(); |
|
1316 |
||
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1317 |
/* |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1318 |
* If an annotation processor raises an error in a round, |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1319 |
* that round runs to completion and one last round occurs. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1320 |
* The last round may also occur because no more source or |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1321 |
* class files have been generated. Therefore, if an error |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1322 |
* was raised on either of the last *two* rounds, the compile |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1323 |
* should exit with a nonzero exit code. The current value of |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1324 |
* errorStatus holds whether or not an error was raised on the |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1325 |
* second to last round; errorRaised() gives the error status |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1326 |
* of the last round. |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1327 |
*/ |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1328 |
if (messager.errorRaised() |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1329 |
|| werror && round.warningCount() > 0 && round.errorCount() > 0) |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1330 |
errorStatus = true; |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1331 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1332 |
Set<JavaFileObject> newSourceFiles = |
22163 | 1333 |
new LinkedHashSet<>(filer.getGeneratedSourceFileObjects()); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1334 |
roots = round.roots; |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1335 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1336 |
errorStatus = errorStatus || (compiler.errorCount() > 0); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1337 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1338 |
if (!errorStatus) |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1339 |
round.finalCompiler(); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1340 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1341 |
if (newSourceFiles.size() > 0) |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1342 |
roots = roots.appendList(compiler.parseFiles(newSourceFiles)); |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1343 |
|
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1344 |
errorStatus = errorStatus || (compiler.errorCount() > 0); |
10 | 1345 |
|
1346 |
// Free resources |
|
1347 |
this.close(); |
|
1348 |
||
12016 | 1349 |
if (!taskListener.isEmpty()) |
10 | 1350 |
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); |
1351 |
||
1352 |
if (errorStatus) { |
|
1353 |
if (compiler.errorCount() == 0) |
|
1354 |
compiler.log.nerrors++; |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1355 |
return true; |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1356 |
} |
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1357 |
|
14050
9bfad4b4b6a2
7196464: upgrade JavaCompiler.shouldStopPolicy to accomodate policies in face of error and no error
jjg
parents:
14044
diff
changeset
|
1358 |
compiler.enterTreesIfNeeded(roots); |
10 | 1359 |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1360 |
return true; |
10 | 1361 |
} |
1362 |
||
1363 |
private void warnIfUnmatchedOptions() { |
|
1364 |
if (!unmatchedProcessorOptions.isEmpty()) { |
|
1365 |
log.warning("proc.unmatched.processor.options", unmatchedProcessorOptions.toString()); |
|
1366 |
} |
|
1367 |
} |
|
1368 |
||
1369 |
/** |
|
1370 |
* Free resources related to annotation processing. |
|
1371 |
*/ |
|
6581 | 1372 |
public void close() { |
10 | 1373 |
filer.close(); |
3764
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
1374 |
if (discoveredProcs != null) // Make calling close idempotent |
f0077f165983
6548708: Annotation processing should free service loader if there are no processors
darcy
parents:
3656
diff
changeset
|
1375 |
discoveredProcs.close(); |
10 | 1376 |
discoveredProcs = null; |
1377 |
} |
|
1378 |
||
1379 |
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) { |
|
1380 |
List<ClassSymbol> classes = List.nil(); |
|
1381 |
for (JCCompilationUnit unit : units) { |
|
1382 |
for (JCTree node : unit.defs) { |
|
10950 | 1383 |
if (node.hasTag(JCTree.Tag.CLASSDEF)) { |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1384 |
ClassSymbol sym = ((JCClassDecl) node).sym; |
8032 | 1385 |
Assert.checkNonNull(sym); |
6355
f01ebbf5a5f7
6975005: improve JavacProcessingEnvironment.Round abstraction
jjg
parents:
6162
diff
changeset
|
1386 |
classes = classes.prepend(sym); |
10 | 1387 |
} |
1388 |
} |
|
1389 |
} |
|
1390 |
return classes.reverse(); |
|
1391 |
} |
|
1392 |
||
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1393 |
private List<ClassSymbol> getTopLevelClassesFromClasses(List<? extends ClassSymbol> syms) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1394 |
List<ClassSymbol> classes = List.nil(); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1395 |
for (ClassSymbol sym : syms) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1396 |
if (!isPkgInfo(sym)) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1397 |
classes = classes.prepend(sym); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1398 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1399 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1400 |
return classes.reverse(); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1401 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1402 |
|
10 | 1403 |
private List<PackageSymbol> getPackageInfoFiles(List<? extends JCCompilationUnit> units) { |
1404 |
List<PackageSymbol> packages = List.nil(); |
|
1405 |
for (JCCompilationUnit unit : units) { |
|
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1406 |
if (isPkgInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE)) { |
10 | 1407 |
packages = packages.prepend(unit.packge); |
1408 |
} |
|
1409 |
} |
|
1410 |
return packages.reverse(); |
|
1411 |
} |
|
1412 |
||
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1413 |
private List<PackageSymbol> getPackageInfoFilesFromClasses(List<? extends ClassSymbol> syms) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1414 |
List<PackageSymbol> packages = List.nil(); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1415 |
for (ClassSymbol sym : syms) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1416 |
if (isPkgInfo(sym)) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1417 |
packages = packages.prepend((PackageSymbol) sym.owner); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1418 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1419 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1420 |
return packages.reverse(); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1421 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1422 |
|
6159
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1423 |
// avoid unchecked warning from use of varargs |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1424 |
private static <T> List<T> join(List<T> list1, List<T> list2) { |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1425 |
return list1.appendList(list2); |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1426 |
} |
88930a1c409e
6966604: JavacFiler not correctly notified of lastRound
jjg
parents:
6153
diff
changeset
|
1427 |
|
4871
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1428 |
private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1429 |
return fo.isNameCompatible("package-info", kind); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1430 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1431 |
|
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1432 |
private boolean isPkgInfo(ClassSymbol sym) { |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1433 |
return isPkgInfo(sym.classfile, JavaFileObject.Kind.CLASS) && (sym.packge().package_info == sym); |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1434 |
} |
655bba719625
6499119: Created package-info class file modeled improperly
jjg
parents:
3764
diff
changeset
|
1435 |
|
10 | 1436 |
/* |
1437 |
* Called retroactively to determine if a class loader was required, |
|
1438 |
* after we have failed to create one. |
|
1439 |
*/ |
|
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
1440 |
private boolean needClassLoader(String procNames, Iterable<? extends Path> workingpath) { |
10 | 1441 |
if (procNames != null) |
1442 |
return true; |
|
1443 |
||
1444 |
URL[] urls = new URL[1]; |
|
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
1445 |
for(Path pathElement : workingpath) { |
10 | 1446 |
try { |
36492
12abe038f3d9
8139474: -release 7 -verbose causes Javac exception
vromero
parents:
35810
diff
changeset
|
1447 |
urls[0] = pathElement.toUri().toURL(); |
10 | 1448 |
if (ServiceProxy.hasService(Processor.class, urls)) |
1449 |
return true; |
|
1450 |
} catch (MalformedURLException ex) { |
|
1451 |
throw new AssertionError(ex); |
|
1452 |
} |
|
1453 |
catch (ServiceProxy.ServiceConfigurationError e) { |
|
1454 |
log.error("proc.bad.config.file", e.getLocalizedMessage()); |
|
1455 |
return true; |
|
1456 |
} |
|
1457 |
} |
|
1458 |
||
1459 |
return false; |
|
1460 |
} |
|
1461 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1462 |
class ImplicitCompleter implements Completer { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1463 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1464 |
private final JCCompilationUnit topLevel; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1465 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1466 |
public ImplicitCompleter(JCCompilationUnit topLevel) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1467 |
this.topLevel = topLevel; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1468 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1469 |
|
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1470 |
@Override public void complete(Symbol sym) throws CompletionFailure { |
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
24396
diff
changeset
|
1471 |
compiler.readSourceFile(topLevel, (ClassSymbol) sym); |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1472 |
} |
10 | 1473 |
} |
1474 |
||
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1475 |
private final TreeScanner treeCleaner = new TreeScanner() { |
10 | 1476 |
public void scan(JCTree node) { |
1477 |
super.scan(node); |
|
1478 |
if (node != null) |
|
1479 |
node.type = null; |
|
1480 |
} |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1481 |
JCCompilationUnit topLevel; |
10 | 1482 |
public void visitTopLevel(JCCompilationUnit node) { |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1483 |
if (node.packge != null) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1484 |
if (node.packge.package_info != null) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1485 |
node.packge.package_info.reset(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1486 |
} |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1487 |
node.packge.reset(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1488 |
} |
36526 | 1489 |
boolean isModuleInfo = node.sourcefile.isNameCompatible("module-info", Kind.SOURCE); |
1490 |
if (isModuleInfo) { |
|
1491 |
node.modle.reset(); |
|
1492 |
node.modle.completer = sym -> modules.enter(List.of(node), node.modle.module_info); |
|
1493 |
node.modle.module_info.reset(); |
|
1494 |
node.modle.module_info.members_field = WriteableScope.create(node.modle.module_info); |
|
1495 |
} |
|
10 | 1496 |
node.packge = null; |
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1497 |
topLevel = node; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1498 |
try { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1499 |
super.visitTopLevel(node); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1500 |
} finally { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1501 |
topLevel = null; |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1502 |
} |
10 | 1503 |
} |
1504 |
public void visitClassDef(JCClassDecl node) { |
|
23810
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1505 |
if (node.sym != null) { |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1506 |
node.sym.reset(); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1507 |
node.sym.completer = new ImplicitCompleter(topLevel); |
b92eb80925f0
8038455: Use single Context for all rounds of annotation processing
jlahoda
parents:
23795
diff
changeset
|
1508 |
} |
10 | 1509 |
node.sym = null; |
1510 |
super.visitClassDef(node); |
|
1511 |
} |
|
1512 |
public void visitMethodDef(JCMethodDecl node) { |
|
1513 |
node.sym = null; |
|
1514 |
super.visitMethodDef(node); |
|
1515 |
} |
|
1516 |
public void visitVarDef(JCVariableDecl node) { |
|
1517 |
node.sym = null; |
|
1518 |
super.visitVarDef(node); |
|
1519 |
} |
|
1520 |
public void visitNewClass(JCNewClass node) { |
|
1521 |
node.constructor = null; |
|
1522 |
super.visitNewClass(node); |
|
1523 |
} |
|
1524 |
public void visitAssignop(JCAssignOp node) { |
|
1525 |
node.operator = null; |
|
1526 |
super.visitAssignop(node); |
|
1527 |
} |
|
1528 |
public void visitUnary(JCUnary node) { |
|
1529 |
node.operator = null; |
|
1530 |
super.visitUnary(node); |
|
1531 |
} |
|
1532 |
public void visitBinary(JCBinary node) { |
|
1533 |
node.operator = null; |
|
1534 |
super.visitBinary(node); |
|
1535 |
} |
|
1536 |
public void visitSelect(JCFieldAccess node) { |
|
1537 |
node.sym = null; |
|
1538 |
super.visitSelect(node); |
|
1539 |
} |
|
1540 |
public void visitIdent(JCIdent node) { |
|
1541 |
node.sym = null; |
|
1542 |
super.visitIdent(node); |
|
1543 |
} |
|
15385 | 1544 |
public void visitAnnotation(JCAnnotation node) { |
1545 |
node.attribute = null; |
|
1546 |
super.visitAnnotation(node); |
|
1547 |
} |
|
10 | 1548 |
}; |
1549 |
||
1550 |
||
1551 |
private boolean moreToDo() { |
|
1552 |
return filer.newFiles(); |
|
1553 |
} |
|
1554 |
||
1555 |
/** |
|
31751 | 1556 |
* {@inheritDoc} |
10 | 1557 |
* |
1558 |
* Command line options suitable for presenting to annotation |
|
13844 | 1559 |
* processors. |
1560 |
* {@literal "-Afoo=bar"} should be {@literal "-Afoo" => "bar"}. |
|
10 | 1561 |
*/ |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1562 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1563 |
public Map<String,String> getOptions() { |
1564 |
return processorOptions; |
|
1565 |
} |
|
1566 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1567 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1568 |
public Messager getMessager() { |
1569 |
return messager; |
|
1570 |
} |
|
1571 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1572 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1573 |
public Filer getFiler() { |
1574 |
return filer; |
|
1575 |
} |
|
1576 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1577 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1578 |
public JavacElements getElementUtils() { |
1579 |
return elementUtils; |
|
1580 |
} |
|
1581 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1582 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1583 |
public JavacTypes getTypeUtils() { |
1584 |
return typeUtils; |
|
1585 |
} |
|
1586 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1587 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1588 |
public SourceVersion getSourceVersion() { |
1589 |
return Source.toSourceVersion(source); |
|
1590 |
} |
|
1591 |
||
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
1592 |
@DefinedBy(Api.ANNOTATION_PROCESSING) |
10 | 1593 |
public Locale getLocale() { |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1260
diff
changeset
|
1594 |
return messages.getCurrentLocale(); |
10 | 1595 |
} |
1596 |
||
1597 |
public Set<Symbol.PackageSymbol> getSpecifiedPackages() { |
|
1598 |
return specifiedPackages; |
|
1599 |
} |
|
1600 |
||
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1601 |
public static final Pattern noMatches = Pattern.compile("(\\P{all})+"); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1602 |
|
10 | 1603 |
/** |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1604 |
* Convert import-style string for supported annotations into a |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1605 |
* regex matching that string. If the string is a valid |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1606 |
* import-style string, return a regex that won't match anything. |
10 | 1607 |
*/ |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1608 |
private static Pattern importStringToPattern(String s, Processor p, Log log) { |
29427
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
27224
diff
changeset
|
1609 |
if (MatchingUtils.isValidImportString(s)) { |
44f4e6905b67
8071851: Provide filtering of doclint checking based on packages
jlahoda
parents:
27224
diff
changeset
|
1610 |
return MatchingUtils.validImportStringToPattern(s); |
4937
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1611 |
} else { |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1612 |
log.warning("proc.malformed.supported.string", s, p.getClass().getName()); |
2fc03fb01efa
6927061: Refactor apt implemenation to use code from JSR 269
darcy
parents:
4934
diff
changeset
|
1613 |
return noMatches; // won't match any valid identifier |
10 | 1614 |
} |
1615 |
} |
|
1616 |
||
1617 |
/** |
|
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1618 |
* For internal use only. This method may be removed without warning. |
10 | 1619 |
*/ |
1620 |
public Context getContext() { |
|
1621 |
return context; |
|
1622 |
} |
|
1623 |
||
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1624 |
/** |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1625 |
* For internal use only. This method may be removed without warning. |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1626 |
*/ |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1627 |
public ClassLoader getProcessorClassLoader() { |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1628 |
return processorClassLoader; |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1629 |
} |
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14538
diff
changeset
|
1630 |
|
10 | 1631 |
public String toString() { |
1632 |
return "javac ProcessingEnvironment"; |
|
1633 |
} |
|
1634 |
||
1635 |
public static boolean isValidOptionName(String optionName) { |
|
1636 |
for(String s : optionName.split("\\.", -1)) { |
|
1637 |
if (!SourceVersion.isIdentifier(s)) |
|
1638 |
return false; |
|
1639 |
} |
|
1640 |
return true; |
|
1641 |
} |
|
1642 |
} |