src/share/classes/com/sun/tools/javac/main/JavaCompiler.java

changeset 664
4124840b35fe
parent 663
eb7c263aab73
child 676
bfdfc13fe641
equal deleted inserted replaced
663:eb7c263aab73 664:4124840b35fe
57 57
58 import com.sun.tools.javac.processing.*; 58 import com.sun.tools.javac.processing.*;
59 import javax.annotation.processing.Processor; 59 import javax.annotation.processing.Processor;
60 60
61 import static javax.tools.StandardLocation.CLASS_OUTPUT; 61 import static javax.tools.StandardLocation.CLASS_OUTPUT;
62 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
62 import static com.sun.tools.javac.util.ListBuffer.lb; 63 import static com.sun.tools.javac.util.ListBuffer.lb;
63 64
64 // TEMP, until we have a more efficient way to save doc comment info 65 // TEMP, until we have a more efficient way to save doc comment info
65 import com.sun.tools.javac.parser.DocCommentScanner; 66 import com.sun.tools.javac.parser.DocCommentScanner;
66 67
577 } 578 }
578 if (taskListener != null) { 579 if (taskListener != null) {
579 TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); 580 TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
580 taskListener.started(e); 581 taskListener.started(e);
581 } 582 }
582 int initialErrorCount = log.nerrors;
583 Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo); 583 Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
584 tree = parser.parseCompilationUnit(); 584 tree = parser.parseCompilationUnit();
585 log.unrecoverableError |= (log.nerrors > initialErrorCount);
586 if (verbose) { 585 if (verbose) {
587 printVerbose("parsing.done", Long.toString(elapsed(msec))); 586 printVerbose("parsing.done", Long.toString(elapsed(msec)));
588 } 587 }
589 } 588 }
590 589
965 options.put("save-parameter-names", "save-parameter-names"); 964 options.put("save-parameter-names", "save-parameter-names");
966 reader.saveParameterNames = true; 965 reader.saveParameterNames = true;
967 keepComments = true; 966 keepComments = true;
968 if (taskListener != null) 967 if (taskListener != null)
969 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); 968 taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING));
970 969 log.deferDiagnostics = true;
971
972 } else { // free resources 970 } else { // free resources
973 procEnvImpl.close(); 971 procEnvImpl.close();
974 } 972 }
975 } 973 }
976 } 974 }
983 /** 981 /**
984 * Process any anotations found in the specifed compilation units. 982 * Process any anotations found in the specifed compilation units.
985 * @param roots a list of compilation units 983 * @param roots a list of compilation units
986 * @return an instance of the compiler in which to complete the compilation 984 * @return an instance of the compiler in which to complete the compilation
987 */ 985 */
986 // Implementation note: when this method is called, log.deferredDiagnostics
987 // will have been set true by initProcessAnnotations, meaning that any diagnostics
988 // that are reported will go into the log.deferredDiagnostics queue.
989 // By the time this method exits, log.deferDiagnostics must be set back to false,
990 // and all deferredDiagnostics must have been handled: i.e. either reported
991 // or determined to be transient, and therefore suppressed.
988 public JavaCompiler processAnnotations(List<JCCompilationUnit> roots, 992 public JavaCompiler processAnnotations(List<JCCompilationUnit> roots,
989 List<String> classnames) { 993 List<String> classnames) {
990 if (shouldStop(CompileState.PROCESS)) { 994 if (shouldStop(CompileState.PROCESS)) {
991 // Errors were encountered. 995 // Errors were encountered.
992 // If log.unrecoverableError is set, the errors were parse errors 996 // Unless all the errors are resolve errors, the errors were parse errors
993 // or other errors during enter which cannot be fixed by running 997 // or other errors during enter which cannot be fixed by running
994 // any annotation processors. 998 // any annotation processors.
995 if (log.unrecoverableError) 999 if (unrecoverableError()) {
1000 log.reportDeferredDiagnostics();
996 return this; 1001 return this;
1002 }
997 } 1003 }
998 1004
999 // ASSERT: processAnnotations and procEnvImpl should have been set up by 1005 // ASSERT: processAnnotations and procEnvImpl should have been set up by
1000 // by initProcessAnnotations 1006 // by initProcessAnnotations
1001 1007
1013 // If not processing annotations, classnames must be empty 1019 // If not processing annotations, classnames must be empty
1014 if (!classnames.isEmpty()) { 1020 if (!classnames.isEmpty()) {
1015 log.error("proc.no.explicit.annotation.processing.requested", 1021 log.error("proc.no.explicit.annotation.processing.requested",
1016 classnames); 1022 classnames);
1017 } 1023 }
1024 log.reportDeferredDiagnostics();
1018 return this; // continue regular compilation 1025 return this; // continue regular compilation
1019 } 1026 }
1020 1027
1021 try { 1028 try {
1022 List<ClassSymbol> classSymbols = List.nil(); 1029 List<ClassSymbol> classSymbols = List.nil();
1025 // Check for explicit request for annotation 1032 // Check for explicit request for annotation
1026 // processing 1033 // processing
1027 if (!explicitAnnotationProcessingRequested()) { 1034 if (!explicitAnnotationProcessingRequested()) {
1028 log.error("proc.no.explicit.annotation.processing.requested", 1035 log.error("proc.no.explicit.annotation.processing.requested",
1029 classnames); 1036 classnames);
1037 log.reportDeferredDiagnostics();
1030 return this; // TODO: Will this halt compilation? 1038 return this; // TODO: Will this halt compilation?
1031 } else { 1039 } else {
1032 boolean errors = false; 1040 boolean errors = false;
1033 for (String nameStr : classnames) { 1041 for (String nameStr : classnames) {
1034 Symbol sym = resolveIdent(nameStr); 1042 Symbol sym = resolveIdent(nameStr);
1039 } 1047 }
1040 try { 1048 try {
1041 if (sym.kind == Kinds.PCK) 1049 if (sym.kind == Kinds.PCK)
1042 sym.complete(); 1050 sym.complete();
1043 if (sym.exists()) { 1051 if (sym.exists()) {
1044 Name name = names.fromString(nameStr);
1045 if (sym.kind == Kinds.PCK) 1052 if (sym.kind == Kinds.PCK)
1046 pckSymbols = pckSymbols.prepend((PackageSymbol)sym); 1053 pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
1047 else 1054 else
1048 classSymbols = classSymbols.prepend((ClassSymbol)sym); 1055 classSymbols = classSymbols.prepend((ClassSymbol)sym);
1049 continue; 1056 continue;
1055 log.error("proc.cant.find.class", nameStr); 1062 log.error("proc.cant.find.class", nameStr);
1056 errors = true; 1063 errors = true;
1057 continue; 1064 continue;
1058 } 1065 }
1059 } 1066 }
1060 if (errors) 1067 if (errors) {
1068 log.reportDeferredDiagnostics();
1061 return this; 1069 return this;
1070 }
1062 } 1071 }
1063 } 1072 }
1064 try { 1073 try {
1065 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols); 1074 JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols);
1066 if (c != this) 1075 if (c != this)
1067 annotationProcessingOccurred = c.annotationProcessingOccurred = true; 1076 annotationProcessingOccurred = c.annotationProcessingOccurred = true;
1077 // doProcessing will have handled deferred diagnostics
1078 assert c.log.deferDiagnostics == false;
1079 assert c.log.deferredDiagnostics.size() == 0;
1068 return c; 1080 return c;
1069 } finally { 1081 } finally {
1070 procEnvImpl.close(); 1082 procEnvImpl.close();
1071 } 1083 }
1072 } catch (CompletionFailure ex) { 1084 } catch (CompletionFailure ex) {
1073 log.error("cant.access", ex.sym, ex.getDetailValue()); 1085 log.error("cant.access", ex.sym, ex.getDetailValue());
1086 log.reportDeferredDiagnostics();
1074 return this; 1087 return this;
1075 1088 }
1076 } 1089 }
1090
1091 private boolean unrecoverableError() {
1092 for (JCDiagnostic d: log.deferredDiagnostics) {
1093 if (d.getKind() == JCDiagnostic.Kind.ERROR && !d.isFlagSet(RESOLVE_ERROR))
1094 return true;
1095 }
1096 return false;
1077 } 1097 }
1078 1098
1079 boolean explicitAnnotationProcessingRequested() { 1099 boolean explicitAnnotationProcessingRequested() {
1080 Options options = Options.instance(context); 1100 Options options = Options.instance(context);
1081 return 1101 return

mercurial