308 roots.append((JCCompilationUnit)cu);
309 notYetEntered.remove(cu.getSourceFile());
310 }
311 else
312 throw new IllegalArgumentException(cu.toString());
313 }
314 }
315
316 if (roots == null)
317 return List.nil();
318
319 try {
320 List<JCCompilationUnit> units = compiler.enterTrees(roots.toList());
321
322 if (notYetEntered.isEmpty())
323 compiler = compiler.processAnnotations(units);
324
325 ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
326 for (JCCompilationUnit unit : units) {
327 for (JCTree node : unit.defs) {
328 if (node.getTag() == JCTree.CLASSDEF) {
329 JCClassDecl cdef = (JCClassDecl) node;
330 if (cdef.sym != null) // maybe null if errors in anno processing
331 elements.append(cdef.sym);
332 }
333 }
334 }
335 return elements.toList();
336 }
337 finally {
338 compiler.log.flush();
339 }
340 }
341
342 /**
343 * Complete all analysis.
344 * @throws IOException TODO
345 */
346 @Override
347 public Iterable<? extends Element> analyze() throws IOException {
348 return analyze(null);
366 try {
367 if (classes == null) {
368 handleFlowResults(compiler.flow(compiler.attribute(compiler.todo)), results);
369 } else {
370 Filter f = new Filter() {
371 public void process(Env<AttrContext> env) {
372 handleFlowResults(compiler.flow(compiler.attribute(env)), results);
373 }
374 };
375 f.run(compiler.todo, classes);
376 }
377 } finally {
378 compiler.log.flush();
379 }
380 return results;
381 }
382 // where
383 private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
384 for (Env<AttrContext> env: queue) {
385 switch (env.tree.getTag()) {
386 case JCTree.CLASSDEF:
387 JCClassDecl cdef = (JCClassDecl) env.tree;
388 if (cdef.sym != null)
389 elems.append(cdef.sym);
390 break;
391 case JCTree.TOPLEVEL:
392 JCCompilationUnit unit = (JCCompilationUnit) env.tree;
393 if (unit.packge != null)
394 elems.append(unit.packge);
395 break;
396 }
397 }
398 genList.addAll(queue);
399 }
400
401
402 /**
403 * Generate code.
404 * @throws IOException TODO
405 */
406 @Override
407 public Iterable<? extends JavaFileObject> generate() throws IOException {
408 return generate(null);
409 }
410
411 /**
|
308 roots.append((JCCompilationUnit)cu);
309 notYetEntered.remove(cu.getSourceFile());
310 }
311 else
312 throw new IllegalArgumentException(cu.toString());
313 }
314 }
315
316 if (roots == null)
317 return List.nil();
318
319 try {
320 List<JCCompilationUnit> units = compiler.enterTrees(roots.toList());
321
322 if (notYetEntered.isEmpty())
323 compiler = compiler.processAnnotations(units);
324
325 ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
326 for (JCCompilationUnit unit : units) {
327 for (JCTree node : unit.defs) {
328 if (node.getTag() == JCTree.Tag.CLASSDEF) {
329 JCClassDecl cdef = (JCClassDecl) node;
330 if (cdef.sym != null) // maybe null if errors in anno processing
331 elements.append(cdef.sym);
332 }
333 }
334 }
335 return elements.toList();
336 }
337 finally {
338 compiler.log.flush();
339 }
340 }
341
342 /**
343 * Complete all analysis.
344 * @throws IOException TODO
345 */
346 @Override
347 public Iterable<? extends Element> analyze() throws IOException {
348 return analyze(null);
366 try {
367 if (classes == null) {
368 handleFlowResults(compiler.flow(compiler.attribute(compiler.todo)), results);
369 } else {
370 Filter f = new Filter() {
371 public void process(Env<AttrContext> env) {
372 handleFlowResults(compiler.flow(compiler.attribute(env)), results);
373 }
374 };
375 f.run(compiler.todo, classes);
376 }
377 } finally {
378 compiler.log.flush();
379 }
380 return results;
381 }
382 // where
383 private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
384 for (Env<AttrContext> env: queue) {
385 switch (env.tree.getTag()) {
386 case CLASSDEF:
387 JCClassDecl cdef = (JCClassDecl) env.tree;
388 if (cdef.sym != null)
389 elems.append(cdef.sym);
390 break;
391 case TOPLEVEL:
392 JCCompilationUnit unit = (JCCompilationUnit) env.tree;
393 if (unit.packge != null)
394 elems.append(unit.packge);
395 break;
396 }
397 }
398 genList.addAll(queue);
399 }
400
401
402 /**
403 * Generate code.
404 * @throws IOException TODO
405 */
406 @Override
407 public Iterable<? extends JavaFileObject> generate() throws IOException {
408 return generate(null);
409 }
410
411 /**
|