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