author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5520 | 86e4b9a9da40 |
child 5848 | c5a4ce47e780 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2005, 2008, 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.api; |
|
27 |
||
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
30 |
import java.nio.CharBuffer; |
10 | 31 |
import java.util.*; |
32 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
33 |
||
34 |
import javax.annotation.processing.Processor; |
|
35 |
import javax.lang.model.element.Element; |
|
36 |
import javax.lang.model.element.TypeElement; |
|
37 |
import javax.lang.model.type.TypeMirror; |
|
38 |
import javax.tools.*; |
|
39 |
||
40 |
import com.sun.source.tree.*; |
|
41 |
import com.sun.source.util.*; |
|
42 |
import com.sun.tools.javac.code.*; |
|
43 |
import com.sun.tools.javac.code.Symbol.*; |
|
44 |
import com.sun.tools.javac.comp.*; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
45 |
import com.sun.tools.javac.file.JavacFileManager; |
10 | 46 |
import com.sun.tools.javac.main.*; |
47 |
import com.sun.tools.javac.model.*; |
|
48 |
import com.sun.tools.javac.parser.Parser; |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
49 |
import com.sun.tools.javac.parser.ParserFactory; |
10 | 50 |
import com.sun.tools.javac.tree.*; |
51 |
import com.sun.tools.javac.tree.JCTree.*; |
|
52 |
import com.sun.tools.javac.util.*; |
|
53 |
import com.sun.tools.javac.util.List; |
|
54 |
import com.sun.tools.javac.main.JavaCompiler; |
|
55 |
||
56 |
/** |
|
57 |
* Provides access to functionality specific to the Sun Java Compiler, javac. |
|
58 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
59 |
* <p><b>This is NOT part of any supported API. |
10 | 60 |
* If you write code that depends on this, you do so at your own |
61 |
* risk. This code and its internal interfaces are subject to change |
|
62 |
* or deletion without notice.</b></p> |
|
63 |
* |
|
64 |
* @author Peter von der Ahé |
|
65 |
* @author Jonathan Gibbons |
|
66 |
*/ |
|
67 |
public class JavacTaskImpl extends JavacTask { |
|
68 |
private JavacTool tool; |
|
69 |
private Main compilerMain; |
|
70 |
private JavaCompiler compiler; |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1355
diff
changeset
|
71 |
private Locale locale; |
10 | 72 |
private String[] args; |
73 |
private Context context; |
|
74 |
private List<JavaFileObject> fileObjects; |
|
75 |
private Map<JavaFileObject, JCCompilationUnit> notYetEntered; |
|
76 |
private ListBuffer<Env<AttrContext>> genList; |
|
77 |
private TaskListener taskListener; |
|
78 |
private AtomicBoolean used = new AtomicBoolean(); |
|
79 |
private Iterable<? extends Processor> processors; |
|
80 |
||
81 |
private Integer result = null; |
|
82 |
||
83 |
JavacTaskImpl(JavacTool tool, |
|
84 |
Main compilerMain, |
|
85 |
String[] args, |
|
86 |
Context context, |
|
87 |
List<JavaFileObject> fileObjects) { |
|
88 |
this.tool = tool; |
|
89 |
this.compilerMain = compilerMain; |
|
90 |
this.args = args; |
|
91 |
this.context = context; |
|
92 |
this.fileObjects = fileObjects; |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1355
diff
changeset
|
93 |
setLocale(Locale.getDefault()); |
10 | 94 |
// null checks |
95 |
compilerMain.getClass(); |
|
96 |
args.getClass(); |
|
97 |
context.getClass(); |
|
98 |
fileObjects.getClass(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
99 |
|
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
100 |
// force the use of the scanner that captures Javadoc comments |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
101 |
com.sun.tools.javac.parser.DocCommentScanner.Factory.preRegister(context); |
10 | 102 |
} |
103 |
||
104 |
JavacTaskImpl(JavacTool tool, |
|
105 |
Main compilerMain, |
|
106 |
Iterable<String> flags, |
|
107 |
Context context, |
|
108 |
Iterable<String> classes, |
|
109 |
Iterable<? extends JavaFileObject> fileObjects) { |
|
110 |
this(tool, compilerMain, toArray(flags, classes), context, toList(fileObjects)); |
|
111 |
} |
|
112 |
||
113 |
static private String[] toArray(Iterable<String> flags, Iterable<String> classes) { |
|
114 |
ListBuffer<String> result = new ListBuffer<String>(); |
|
115 |
if (flags != null) |
|
116 |
for (String flag : flags) |
|
117 |
result.append(flag); |
|
118 |
if (classes != null) |
|
119 |
for (String cls : classes) |
|
120 |
result.append(cls); |
|
121 |
return result.toArray(new String[result.length()]); |
|
122 |
} |
|
123 |
||
124 |
static private List<JavaFileObject> toList(Iterable<? extends JavaFileObject> fileObjects) { |
|
125 |
if (fileObjects == null) |
|
126 |
return List.nil(); |
|
127 |
ListBuffer<JavaFileObject> result = new ListBuffer<JavaFileObject>(); |
|
128 |
for (JavaFileObject fo : fileObjects) |
|
129 |
result.append(fo); |
|
130 |
return result.toList(); |
|
131 |
} |
|
132 |
||
133 |
public Boolean call() { |
|
134 |
if (!used.getAndSet(true)) { |
|
135 |
beginContext(); |
|
3149 | 136 |
notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>(); |
10 | 137 |
try { |
138 |
compilerMain.setFatalErrors(true); |
|
139 |
result = compilerMain.compile(args, context, fileObjects, processors); |
|
140 |
} finally { |
|
141 |
endContext(); |
|
142 |
} |
|
143 |
compilerMain = null; |
|
144 |
args = null; |
|
145 |
context = null; |
|
146 |
fileObjects = null; |
|
3149 | 147 |
notYetEntered = null; |
10 | 148 |
return result == 0; |
149 |
} else { |
|
150 |
throw new IllegalStateException("multiple calls to method 'call'"); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
public void setProcessors(Iterable<? extends Processor> processors) { |
|
155 |
processors.getClass(); // null check |
|
156 |
// not mt-safe |
|
157 |
if (used.get()) |
|
158 |
throw new IllegalStateException(); |
|
159 |
this.processors = processors; |
|
160 |
} |
|
161 |
||
162 |
public void setLocale(Locale locale) { |
|
163 |
if (used.get()) |
|
164 |
throw new IllegalStateException(); |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1355
diff
changeset
|
165 |
this.locale = locale; |
10 | 166 |
} |
167 |
||
168 |
private void prepareCompiler() throws IOException { |
|
169 |
if (!used.getAndSet(true)) { |
|
170 |
beginContext(); |
|
171 |
compilerMain.setOptions(Options.instance(context)); |
|
172 |
compilerMain.filenames = new ListBuffer<File>(); |
|
173 |
List<File> filenames = compilerMain.processArgs(CommandLine.parse(args)); |
|
174 |
if (!filenames.isEmpty()) |
|
175 |
throw new IllegalArgumentException("Malformed arguments " + filenames.toString(" ")); |
|
176 |
compiler = JavaCompiler.instance(context); |
|
177 |
compiler.keepComments = true; |
|
178 |
compiler.genEndPos = true; |
|
179 |
// NOTE: this value will be updated after annotation processing |
|
180 |
compiler.initProcessAnnotations(processors); |
|
181 |
notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>(); |
|
182 |
for (JavaFileObject file: fileObjects) |
|
183 |
notYetEntered.put(file, null); |
|
184 |
genList = new ListBuffer<Env<AttrContext>>(); |
|
185 |
// endContext will be called when all classes have been generated |
|
186 |
// TODO: should handle the case after each phase if errors have occurred |
|
187 |
args = null; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
private void beginContext() { |
|
192 |
context.put(JavacTaskImpl.class, this); |
|
193 |
if (context.get(TaskListener.class) != null) |
|
194 |
context.put(TaskListener.class, (TaskListener)null); |
|
195 |
if (taskListener != null) |
|
196 |
context.put(TaskListener.class, wrap(taskListener)); |
|
197 |
tool.beginContext(context); |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1355
diff
changeset
|
198 |
//initialize compiler's default locale |
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1355
diff
changeset
|
199 |
JavacMessages.instance(context).setCurrentLocale(locale); |
10 | 200 |
} |
201 |
// where |
|
202 |
private TaskListener wrap(final TaskListener tl) { |
|
203 |
tl.getClass(); // null check |
|
204 |
return new TaskListener() { |
|
205 |
public void started(TaskEvent e) { |
|
206 |
try { |
|
207 |
tl.started(e); |
|
208 |
} catch (Throwable t) { |
|
209 |
throw new ClientCodeException(t); |
|
210 |
} |
|
211 |
} |
|
212 |
||
213 |
public void finished(TaskEvent e) { |
|
214 |
try { |
|
215 |
tl.finished(e); |
|
216 |
} catch (Throwable t) { |
|
217 |
throw new ClientCodeException(t); |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
}; |
|
222 |
} |
|
223 |
||
224 |
private void endContext() { |
|
225 |
tool.endContext(); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
229 |
* Construct a JavaFileObject from the given file. |
|
230 |
* |
|
231 |
* <p><b>TODO: this method is useless here</b></p> |
|
232 |
* |
|
233 |
* @param file a file |
|
234 |
* @return a JavaFileObject from the standard file manager. |
|
235 |
*/ |
|
236 |
public JavaFileObject asJavaFileObject(File file) { |
|
237 |
JavacFileManager fm = (JavacFileManager)context.get(JavaFileManager.class); |
|
238 |
return fm.getRegularFile(file); |
|
239 |
} |
|
240 |
||
241 |
public void setTaskListener(TaskListener taskListener) { |
|
242 |
this.taskListener = taskListener; |
|
243 |
} |
|
244 |
||
245 |
/** |
|
246 |
* Parse the specified files returning a list of abstract syntax trees. |
|
247 |
* |
|
248 |
* @throws java.io.IOException TODO |
|
249 |
* @return a list of abstract syntax trees |
|
250 |
*/ |
|
251 |
public Iterable<? extends CompilationUnitTree> parse() throws IOException { |
|
252 |
try { |
|
253 |
prepareCompiler(); |
|
254 |
List<JCCompilationUnit> units = compiler.parseFiles(fileObjects); |
|
255 |
for (JCCompilationUnit unit: units) { |
|
256 |
JavaFileObject file = unit.getSourceFile(); |
|
257 |
if (notYetEntered.containsKey(file)) |
|
258 |
notYetEntered.put(file, unit); |
|
259 |
} |
|
260 |
return units; |
|
261 |
} |
|
262 |
finally { |
|
263 |
parsed = true; |
|
264 |
if (compiler != null && compiler.log != null) |
|
265 |
compiler.log.flush(); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
private boolean parsed = false; |
|
270 |
||
271 |
/** |
|
272 |
* Translate all the abstract syntax trees to elements. |
|
273 |
* |
|
274 |
* @throws IOException TODO |
|
275 |
* @return a list of elements corresponding to the top level |
|
276 |
* classes in the abstract syntax trees |
|
277 |
*/ |
|
278 |
public Iterable<? extends TypeElement> enter() throws IOException { |
|
279 |
return enter(null); |
|
280 |
} |
|
281 |
||
282 |
/** |
|
283 |
* Translate the given abstract syntax trees to elements. |
|
284 |
* |
|
285 |
* @param trees a list of abstract syntax trees. |
|
286 |
* @throws java.io.IOException TODO |
|
287 |
* @return a list of elements corresponding to the top level |
|
288 |
* classes in the abstract syntax trees |
|
289 |
*/ |
|
290 |
public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees) |
|
291 |
throws IOException |
|
292 |
{ |
|
293 |
prepareCompiler(); |
|
294 |
||
295 |
ListBuffer<JCCompilationUnit> roots = null; |
|
296 |
||
297 |
if (trees == null) { |
|
298 |
// If there are still files which were specified to be compiled |
|
299 |
// (i.e. in fileObjects) but which have not yet been entered, |
|
300 |
// then we make sure they have been parsed and add them to the |
|
301 |
// list to be entered. |
|
302 |
if (notYetEntered.size() > 0) { |
|
303 |
if (!parsed) |
|
304 |
parse(); // TODO would be nice to specify files needed to be parsed |
|
305 |
for (JavaFileObject file: fileObjects) { |
|
306 |
JCCompilationUnit unit = notYetEntered.remove(file); |
|
307 |
if (unit != null) { |
|
308 |
if (roots == null) |
|
309 |
roots = new ListBuffer<JCCompilationUnit>(); |
|
310 |
roots.append(unit); |
|
311 |
} |
|
312 |
} |
|
313 |
notYetEntered.clear(); |
|
314 |
} |
|
315 |
} |
|
316 |
else { |
|
317 |
for (CompilationUnitTree cu : trees) { |
|
318 |
if (cu instanceof JCCompilationUnit) { |
|
319 |
if (roots == null) |
|
320 |
roots = new ListBuffer<JCCompilationUnit>(); |
|
321 |
roots.append((JCCompilationUnit)cu); |
|
322 |
notYetEntered.remove(cu.getSourceFile()); |
|
323 |
} |
|
324 |
else |
|
325 |
throw new IllegalArgumentException(cu.toString()); |
|
326 |
} |
|
327 |
} |
|
328 |
||
329 |
if (roots == null) |
|
330 |
return List.nil(); |
|
331 |
||
332 |
try { |
|
333 |
List<JCCompilationUnit> units = compiler.enterTrees(roots.toList()); |
|
334 |
||
335 |
if (notYetEntered.isEmpty()) |
|
336 |
compiler = compiler.processAnnotations(units); |
|
337 |
||
338 |
ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>(); |
|
339 |
for (JCCompilationUnit unit : units) { |
|
340 |
for (JCTree node : unit.defs) |
|
341 |
if (node.getTag() == JCTree.CLASSDEF) |
|
342 |
elements.append(((JCTree.JCClassDecl) node).sym); |
|
343 |
} |
|
344 |
return elements.toList(); |
|
345 |
} |
|
346 |
finally { |
|
347 |
compiler.log.flush(); |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
/** |
|
352 |
* Complete all analysis. |
|
353 |
* @throws IOException TODO |
|
354 |
*/ |
|
355 |
@Override |
|
356 |
public Iterable<? extends Element> analyze() throws IOException { |
|
357 |
return analyze(null); |
|
358 |
} |
|
359 |
||
360 |
/** |
|
361 |
* Complete all analysis on the given classes. |
|
362 |
* This can be used to ensure that all compile time errors are reported. |
|
363 |
* The classes must have previously been returned from {@link #enter}. |
|
364 |
* If null is specified, all outstanding classes will be analyzed. |
|
365 |
* |
|
366 |
* @param classes a list of class elements |
|
367 |
*/ |
|
368 |
// This implementation requires that we open up privileges on JavaCompiler. |
|
369 |
// An alternative implementation would be to move this code to JavaCompiler and |
|
370 |
// wrap it here |
|
371 |
public Iterable<? extends Element> analyze(Iterable<? extends TypeElement> classes) throws IOException { |
|
372 |
enter(null); // ensure all classes have been entered |
|
373 |
||
374 |
final ListBuffer<Element> results = new ListBuffer<Element>(); |
|
375 |
try { |
|
376 |
if (classes == null) { |
|
377 |
handleFlowResults(compiler.flow(compiler.attribute(compiler.todo)), results); |
|
378 |
} else { |
|
379 |
Filter f = new Filter() { |
|
380 |
public void process(Env<AttrContext> env) { |
|
381 |
handleFlowResults(compiler.flow(compiler.attribute(env)), results); |
|
382 |
} |
|
383 |
}; |
|
384 |
f.run(compiler.todo, classes); |
|
385 |
} |
|
386 |
} finally { |
|
387 |
compiler.log.flush(); |
|
388 |
} |
|
389 |
return results; |
|
390 |
} |
|
391 |
// where |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
392 |
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) { |
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
393 |
for (Env<AttrContext> env: queue) { |
10 | 394 |
switch (env.tree.getTag()) { |
395 |
case JCTree.CLASSDEF: |
|
396 |
JCClassDecl cdef = (JCClassDecl) env.tree; |
|
397 |
if (cdef.sym != null) |
|
398 |
elems.append(cdef.sym); |
|
399 |
break; |
|
400 |
case JCTree.TOPLEVEL: |
|
401 |
JCCompilationUnit unit = (JCCompilationUnit) env.tree; |
|
402 |
if (unit.packge != null) |
|
403 |
elems.append(unit.packge); |
|
404 |
break; |
|
405 |
} |
|
406 |
} |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
407 |
genList.addAll(queue); |
10 | 408 |
} |
409 |
||
410 |
||
411 |
/** |
|
412 |
* Generate code. |
|
413 |
* @throws IOException TODO |
|
414 |
*/ |
|
415 |
@Override |
|
416 |
public Iterable<? extends JavaFileObject> generate() throws IOException { |
|
417 |
return generate(null); |
|
418 |
} |
|
419 |
||
420 |
/** |
|
421 |
* Generate code corresponding to the given classes. |
|
422 |
* The classes must have previously been returned from {@link #enter}. |
|
423 |
* If there are classes outstanding to be analyzed, that will be done before |
|
424 |
* any classes are generated. |
|
425 |
* If null is specified, code will be generated for all outstanding classes. |
|
426 |
* |
|
427 |
* @param classes a list of class elements |
|
428 |
*/ |
|
429 |
public Iterable<? extends JavaFileObject> generate(Iterable<? extends TypeElement> classes) throws IOException { |
|
430 |
final ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>(); |
|
431 |
try { |
|
432 |
analyze(null); // ensure all classes have been parsed, entered, and analyzed |
|
433 |
||
434 |
if (classes == null) { |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
435 |
compiler.generate(compiler.desugar(genList), results); |
10 | 436 |
genList.clear(); |
437 |
} |
|
438 |
else { |
|
439 |
Filter f = new Filter() { |
|
440 |
public void process(Env<AttrContext> env) { |
|
864
b1cf6afb8244
6724551: Use Queues instead of Lists to link compiler phases
jjg
parents:
735
diff
changeset
|
441 |
compiler.generate(compiler.desugar(ListBuffer.of(env)), results); |
10 | 442 |
} |
443 |
}; |
|
444 |
f.run(genList, classes); |
|
445 |
} |
|
446 |
if (genList.isEmpty()) { |
|
447 |
compiler.reportDeferredDiagnostics(); |
|
448 |
compiler.log.flush(); |
|
449 |
endContext(); |
|
450 |
} |
|
451 |
} |
|
452 |
finally { |
|
453 |
compiler.log.flush(); |
|
454 |
} |
|
455 |
return results; |
|
456 |
} |
|
457 |
||
458 |
public TypeMirror getTypeMirror(Iterable<? extends Tree> path) { |
|
459 |
// TODO: Should complete attribution if necessary |
|
460 |
Tree last = null; |
|
461 |
for (Tree node : path) |
|
462 |
last = node; |
|
463 |
return ((JCTree)last).type; |
|
464 |
} |
|
465 |
||
466 |
public JavacElements getElements() { |
|
467 |
if (context == null) |
|
468 |
throw new IllegalStateException(); |
|
469 |
return JavacElements.instance(context); |
|
470 |
} |
|
471 |
||
472 |
public JavacTypes getTypes() { |
|
473 |
if (context == null) |
|
474 |
throw new IllegalStateException(); |
|
475 |
return JavacTypes.instance(context); |
|
476 |
} |
|
477 |
||
478 |
public Iterable<? extends Tree> pathFor(CompilationUnitTree unit, Tree node) { |
|
479 |
return TreeInfo.pathFor((JCTree) node, (JCTree.JCCompilationUnit) unit).reverse(); |
|
480 |
} |
|
481 |
||
482 |
abstract class Filter { |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
483 |
void run(Queue<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) { |
10 | 484 |
Set<TypeElement> set = new HashSet<TypeElement>(); |
485 |
for (TypeElement item: classes) |
|
486 |
set.add(item); |
|
487 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
488 |
ListBuffer<Env<AttrContext>> defer = ListBuffer.<Env<AttrContext>>lb(); |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
489 |
while (list.peek() != null) { |
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
490 |
Env<AttrContext> env = list.remove(); |
10 | 491 |
ClassSymbol csym = env.enclClass.sym; |
492 |
if (csym != null && set.contains(csym.outermostClass())) |
|
493 |
process(env); |
|
494 |
else |
|
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
495 |
defer = defer.append(env); |
10 | 496 |
} |
497 |
||
1355
74cc97efef51
6420151: need to improve byfile compile policy to eliminate footprint issues
jjg
parents:
1258
diff
changeset
|
498 |
list.addAll(defer); |
10 | 499 |
} |
500 |
||
501 |
abstract void process(Env<AttrContext> env); |
|
502 |
} |
|
503 |
||
504 |
/** |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
505 |
* For internal use only. This method will be |
10 | 506 |
* removed without warning. |
507 |
*/ |
|
508 |
public Context getContext() { |
|
509 |
return context; |
|
510 |
} |
|
511 |
||
512 |
/** |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
513 |
* For internal use only. This method will be |
10 | 514 |
* removed without warning. |
515 |
*/ |
|
516 |
public void updateContext(Context newContext) { |
|
517 |
context = newContext; |
|
518 |
} |
|
519 |
||
520 |
/** |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
521 |
* For internal use only. This method will be |
10 | 522 |
* removed without warning. |
523 |
*/ |
|
524 |
public Type parseType(String expr, TypeElement scope) { |
|
525 |
if (expr == null || expr.equals("")) |
|
526 |
throw new IllegalArgumentException(); |
|
527 |
compiler = JavaCompiler.instance(context); |
|
528 |
JavaFileObject prev = compiler.log.useSource(null); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
529 |
ParserFactory parserFactory = ParserFactory.instance(context); |
10 | 530 |
Attr attr = Attr.instance(context); |
531 |
try { |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
532 |
CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length()); |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
533 |
Parser parser = parserFactory.newParser(buf, false, false, false); |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
864
diff
changeset
|
534 |
JCTree tree = parser.parseType(); |
10 | 535 |
return attr.attribType(tree, (Symbol.TypeSymbol)scope); |
536 |
} finally { |
|
537 |
compiler.log.useSource(prev); |
|
538 |
} |
|
539 |
} |
|
540 |
||
541 |
} |