782 return false; 783 } catch (Throwable t) { 784 throw new AnnotationProcessingError(t); 785 } 786 } 787 788 789 // TODO: internal catch clauses?; catch and rethrow an annotation 790 // processing error 791 public JavaCompiler doProcessing(Context context, 792 List<JCCompilationUnit> roots, 793 List<ClassSymbol> classSymbols, 794 Iterable<? extends PackageSymbol> pckSymbols) 795 throws IOException { 796 797 log = Log.instance(context); 798 // Writer for -XprintRounds and -XprintProcessorInfo data 799 PrintWriter xout = context.get(Log.outKey); 800 TaskListener taskListener = context.get(TaskListener.class); 801 802 803 AnnotationCollector collector = new AnnotationCollector(); 804 805 JavaCompiler compiler = JavaCompiler.instance(context); 806 compiler.todo.clear(); // free the compiler's resources 807 808 int round = 0; 809 810 // List<JCAnnotation> annotationsPresentInSource = collector.findAnnotations(roots); 811 List<ClassSymbol> topLevelClasses = getTopLevelClasses(roots); 812 813 for (ClassSymbol classSym : classSymbols) 814 topLevelClasses = topLevelClasses.prepend(classSym); 815 List<PackageSymbol> packageInfoFiles = 816 getPackageInfoFiles(roots); 817 818 Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>(); 819 for (PackageSymbol psym : pckSymbols) 820 specifiedPackages.add(psym); 821 this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); 822 823 // Use annotation processing to compute the set of annotations present 824 Set<TypeElement> annotationsPresent = new LinkedHashSet<TypeElement>(); 1203 1204 String procPath; 1205 URL[] urls = new URL[1]; 1206 for(File pathElement : workingpath) { 1207 try { 1208 urls[0] = pathElement.toURI().toURL(); 1209 if (ServiceProxy.hasService(Processor.class, urls)) 1210 return true; 1211 } catch (MalformedURLException ex) { 1212 throw new AssertionError(ex); 1213 } 1214 catch (ServiceProxy.ServiceConfigurationError e) { 1215 log.error("proc.bad.config.file", e.getLocalizedMessage()); 1216 return true; 1217 } 1218 } 1219 1220 return false; 1221 } 1222 1223 private static class AnnotationCollector extends TreeScanner { 1224 List<JCTree> path = List.nil(); 1225 static final boolean verbose = false; 1226 List<JCAnnotation> annotations = List.nil(); 1227 1228 public List<JCAnnotation> findAnnotations(List<? extends JCTree> nodes) { 1229 annotations = List.nil(); 1230 scan(nodes); 1231 List<JCAnnotation> found = annotations; 1232 annotations = List.nil(); 1233 return found.reverse(); 1234 } 1235 1236 public void scan(JCTree node) { 1237 if (node == null) 1238 return; 1239 Symbol sym = TreeInfo.symbolFor(node); 1240 if (sym != null) 1241 path = path.prepend(node); 1242 super.scan(node); 1243 if (sym != null) 1244 path = path.tail; 1245 } 1246 1247 public void visitAnnotation(JCAnnotation node) { 1248 annotations = annotations.prepend(node); 1249 if (verbose) { 1250 StringBuilder sb = new StringBuilder(); 1251 for (JCTree tree : path.reverse()) { 1252 System.err.print(sb); 1253 System.err.println(TreeInfo.symbolFor(tree)); 1254 sb.append(" "); 1255 } 1256 System.err.print(sb); 1257 System.err.println(node); 1258 } 1259 } 1260 } 1261 1262 private static <T extends JCTree> List<T> cleanTrees(List<T> nodes) { 1263 for (T node : nodes) 1264 treeCleaner.scan(node); 1265 return nodes; 1266 } 1267 1268 private static TreeScanner treeCleaner = new TreeScanner() { 1269 public void scan(JCTree node) { 1270 super.scan(node); 1271 if (node != null) 1272 node.type = null; 1273 } 1274 public void visitTopLevel(JCCompilationUnit node) { 1275 node.packge = null; 1276 super.visitTopLevel(node); 1277 } 1278 public void visitClassDef(JCClassDecl node) { 1279 node.sym = null; 1280 super.visitClassDef(node); 1281 } | 782 return false; 783 } catch (Throwable t) { 784 throw new AnnotationProcessingError(t); 785 } 786 } 787 788 789 // TODO: internal catch clauses?; catch and rethrow an annotation 790 // processing error 791 public JavaCompiler doProcessing(Context context, 792 List<JCCompilationUnit> roots, 793 List<ClassSymbol> classSymbols, 794 Iterable<? extends PackageSymbol> pckSymbols) 795 throws IOException { 796 797 log = Log.instance(context); 798 // Writer for -XprintRounds and -XprintProcessorInfo data 799 PrintWriter xout = context.get(Log.outKey); 800 TaskListener taskListener = context.get(TaskListener.class); 801 802 JavaCompiler compiler = JavaCompiler.instance(context); 803 compiler.todo.clear(); // free the compiler's resources 804 805 int round = 0; 806 807 // List<JCAnnotation> annotationsPresentInSource = collector.findAnnotations(roots); 808 List<ClassSymbol> topLevelClasses = getTopLevelClasses(roots); 809 810 for (ClassSymbol classSym : classSymbols) 811 topLevelClasses = topLevelClasses.prepend(classSym); 812 List<PackageSymbol> packageInfoFiles = 813 getPackageInfoFiles(roots); 814 815 Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>(); 816 for (PackageSymbol psym : pckSymbols) 817 specifiedPackages.add(psym); 818 this.specifiedPackages = Collections.unmodifiableSet(specifiedPackages); 819 820 // Use annotation processing to compute the set of annotations present 821 Set<TypeElement> annotationsPresent = new LinkedHashSet<TypeElement>(); 1200 1201 String procPath; 1202 URL[] urls = new URL[1]; 1203 for(File pathElement : workingpath) { 1204 try { 1205 urls[0] = pathElement.toURI().toURL(); 1206 if (ServiceProxy.hasService(Processor.class, urls)) 1207 return true; 1208 } catch (MalformedURLException ex) { 1209 throw new AssertionError(ex); 1210 } 1211 catch (ServiceProxy.ServiceConfigurationError e) { 1212 log.error("proc.bad.config.file", e.getLocalizedMessage()); 1213 return true; 1214 } 1215 } 1216 1217 return false; 1218 } 1219 1220 private static <T extends JCTree> List<T> cleanTrees(List<T> nodes) { 1221 for (T node : nodes) 1222 treeCleaner.scan(node); 1223 return nodes; 1224 } 1225 1226 private static TreeScanner treeCleaner = new TreeScanner() { 1227 public void scan(JCTree node) { 1228 super.scan(node); 1229 if (node != null) 1230 node.type = null; 1231 } 1232 public void visitTopLevel(JCCompilationUnit node) { 1233 node.packge = null; 1234 super.visitTopLevel(node); 1235 } 1236 public void visitClassDef(JCClassDecl node) { 1237 node.sym = null; 1238 super.visitClassDef(node); 1239 } |