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