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