src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

changeset 1521
71f35e4b93a5
parent 1442
fcf89720ae71
child 1690
76537856a54e
equal deleted inserted replaced
1520:5c956be64b9e 1521:71f35e4b93a5
1 /* 1 /*
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
815 /** The set of top level classes to be processed this round. */ 815 /** The set of top level classes to be processed this round. */
816 List<ClassSymbol> topLevelClasses; 816 List<ClassSymbol> topLevelClasses;
817 /** The set of package-info files to be processed this round. */ 817 /** The set of package-info files to be processed this round. */
818 List<PackageSymbol> packageInfoFiles; 818 List<PackageSymbol> packageInfoFiles;
819 819
820 /** The number of Messager errors generated in this round. */
821 int nMessagerErrors;
822
823 /** Create a round (common code). */ 820 /** Create a round (common code). */
824 private Round(Context context, int number, int priorErrors, int priorWarnings, 821 private Round(Context context, int number, int priorErrors, int priorWarnings,
825 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) { 822 Log.DeferredDiagnosticHandler deferredDiagnosticHandler) {
826 this.context = context; 823 this.context = context;
827 this.number = number; 824 this.number = number;
828 825
829 compiler = JavaCompiler.instance(context); 826 compiler = JavaCompiler.instance(context);
830 log = Log.instance(context); 827 log = Log.instance(context);
831 log.nerrors = priorErrors; 828 log.nerrors = priorErrors;
832 log.nwarnings += priorWarnings; 829 log.nwarnings = priorWarnings;
833 if (number == 1) { 830 if (number == 1) {
834 Assert.checkNonNull(deferredDiagnosticHandler); 831 Assert.checkNonNull(deferredDiagnosticHandler);
835 this.deferredDiagnosticHandler = deferredDiagnosticHandler; 832 this.deferredDiagnosticHandler = deferredDiagnosticHandler;
836 } else { 833 } else {
837 this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); 834 this.deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log);
868 /** Create a new round. */ 865 /** Create a new round. */
869 private Round(Round prev, 866 private Round(Round prev,
870 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) { 867 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) {
871 this(prev.nextContext(), 868 this(prev.nextContext(),
872 prev.number+1, 869 prev.number+1,
873 prev.nMessagerErrors, 870 prev.compiler.log.nerrors,
874 prev.compiler.log.nwarnings, 871 prev.compiler.log.nwarnings,
875 null); 872 null);
876 this.genClassFiles = prev.genClassFiles; 873 this.genClassFiles = prev.genClassFiles;
877 874
878 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); 875 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles);
909 compiler.close(false); 906 compiler.close(false);
910 } 907 }
911 } 908 }
912 909
913 /** Create the compiler to be used for the final compilation. */ 910 /** Create the compiler to be used for the final compilation. */
914 JavaCompiler finalCompiler(boolean errorStatus) { 911 JavaCompiler finalCompiler() {
915 try { 912 try {
916 Context nextCtx = nextContext(); 913 Context nextCtx = nextContext();
917 JavacProcessingEnvironment.this.context = nextCtx; 914 JavacProcessingEnvironment.this.context = nextCtx;
918 JavaCompiler c = JavaCompiler.instance(nextCtx); 915 JavaCompiler c = JavaCompiler.instance(nextCtx);
919 c.log.nwarnings += compiler.log.nwarnings; 916 c.log.initRound(compiler.log);
920 if (errorStatus) {
921 c.log.nerrors += compiler.log.nerrors;
922 }
923 return c; 917 return c;
924 } finally { 918 } finally {
925 compiler.close(false); 919 compiler.close(false);
926 } 920 }
927 } 921 }
1025 } 1019 }
1026 } finally { 1020 } finally {
1027 if (!taskListener.isEmpty()) 1021 if (!taskListener.isEmpty())
1028 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); 1022 taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
1029 } 1023 }
1030
1031 nMessagerErrors = messager.errorCount();
1032 } 1024 }
1033 1025
1034 void showDiagnostics(boolean showAll) { 1026 void showDiagnostics(boolean showAll) {
1035 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class); 1027 Set<JCDiagnostic.Kind> kinds = EnumSet.allOf(JCDiagnostic.Kind.class);
1036 if (!showAll) { 1028 if (!showAll) {
1105 Tokens tokens = Tokens.instance(context); 1097 Tokens tokens = Tokens.instance(context);
1106 Assert.checkNonNull(tokens); 1098 Assert.checkNonNull(tokens);
1107 next.put(Tokens.tokensKey, tokens); 1099 next.put(Tokens.tokensKey, tokens);
1108 1100
1109 Log nextLog = Log.instance(next); 1101 Log nextLog = Log.instance(next);
1110 // propogate the log's writers directly, instead of going through context 1102 nextLog.initRound(log);
1111 nextLog.setWriters(log);
1112 nextLog.setSourceMap(log);
1113 1103
1114 JavaCompiler oldCompiler = JavaCompiler.instance(context); 1104 JavaCompiler oldCompiler = JavaCompiler.instance(context);
1115 JavaCompiler nextCompiler = JavaCompiler.instance(next); 1105 JavaCompiler nextCompiler = JavaCompiler.instance(next);
1116 nextCompiler.initRound(oldCompiler); 1106 nextCompiler.initRound(oldCompiler);
1117 1107
1204 1194
1205 Set<JavaFileObject> newSourceFiles = 1195 Set<JavaFileObject> newSourceFiles =
1206 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects()); 1196 new LinkedHashSet<JavaFileObject>(filer.getGeneratedSourceFileObjects());
1207 roots = cleanTrees(round.roots); 1197 roots = cleanTrees(round.roots);
1208 1198
1209 JavaCompiler compiler = round.finalCompiler(errorStatus); 1199 JavaCompiler compiler = round.finalCompiler();
1210 1200
1211 if (newSourceFiles.size() > 0) 1201 if (newSourceFiles.size() > 0)
1212 roots = roots.appendList(compiler.parseFiles(newSourceFiles)); 1202 roots = roots.appendList(compiler.parseFiles(newSourceFiles));
1213 1203
1214 errorStatus = errorStatus || (compiler.errorCount() > 0); 1204 errorStatus = errorStatus || (compiler.errorCount() > 0);
1309 */ 1299 */
1310 private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) { 1300 private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
1311 if (procNames != null) 1301 if (procNames != null)
1312 return true; 1302 return true;
1313 1303
1314 String procPath;
1315 URL[] urls = new URL[1]; 1304 URL[] urls = new URL[1];
1316 for(File pathElement : workingpath) { 1305 for(File pathElement : workingpath) {
1317 try { 1306 try {
1318 urls[0] = pathElement.toURI().toURL(); 1307 urls[0] = pathElement.toURI().toURL();
1319 if (ServiceProxy.hasService(Processor.class, urls)) 1308 if (ServiceProxy.hasService(Processor.class, urls))
1379 super.visitSelect(node); 1368 super.visitSelect(node);
1380 } 1369 }
1381 public void visitIdent(JCIdent node) { 1370 public void visitIdent(JCIdent node) {
1382 node.sym = null; 1371 node.sym = null;
1383 super.visitIdent(node); 1372 super.visitIdent(node);
1373 }
1374 public void visitAnnotation(JCAnnotation node) {
1375 node.attribute = null;
1376 super.visitAnnotation(node);
1384 } 1377 }
1385 }; 1378 };
1386 1379
1387 1380
1388 private boolean moreToDo() { 1381 private boolean moreToDo() {

mercurial