langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
changeset 14050 9bfad4b4b6a2
parent 14044 0070e9c44020
child 14057 b4b0377b8dba
equal deleted inserted replaced
14049:3207422a0f9b 14050:9bfad4b4b6a2
    95 
    95 
    96     private final boolean printProcessorInfo;
    96     private final boolean printProcessorInfo;
    97     private final boolean printRounds;
    97     private final boolean printRounds;
    98     private final boolean verbose;
    98     private final boolean verbose;
    99     private final boolean lint;
    99     private final boolean lint;
   100     private final boolean procOnly;
       
   101     private final boolean fatalErrors;
   100     private final boolean fatalErrors;
   102     private final boolean werror;
   101     private final boolean werror;
   103     private final boolean showResolveErrors;
   102     private final boolean showResolveErrors;
   104     private boolean foundTypeProcessors;
       
   105 
   103 
   106     private final JavacFiler filer;
   104     private final JavacFiler filer;
   107     private final JavacMessager messager;
   105     private final JavacMessager messager;
   108     private final JavacElements elementUtils;
   106     private final JavacElements elementUtils;
   109     private final JavacTypes typeUtils;
   107     private final JavacTypes typeUtils;
   165         options = Options.instance(context);
   163         options = Options.instance(context);
   166         printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
   164         printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
   167         printRounds = options.isSet(XPRINTROUNDS);
   165         printRounds = options.isSet(XPRINTROUNDS);
   168         verbose = options.isSet(VERBOSE);
   166         verbose = options.isSet(VERBOSE);
   169         lint = Lint.instance(context).isEnabled(PROCESSING);
   167         lint = Lint.instance(context).isEnabled(PROCESSING);
   170         procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
   168         if (options.isSet(PROC, "only") || options.isSet(XPRINT)) {
       
   169             JavaCompiler compiler = JavaCompiler.instance(context);
       
   170             compiler.shouldStopPolicyIfNoError = CompileState.PROCESS;
       
   171         }
   171         fatalErrors = options.isSet("fatalEnterError");
   172         fatalErrors = options.isSet("fatalEnterError");
   172         showResolveErrors = options.isSet("showResolveErrors");
   173         showResolveErrors = options.isSet("showResolveErrors");
   173         werror = options.isSet(WERROR);
   174         werror = options.isSet(WERROR);
   174         platformAnnotations = initPlatformAnnotations();
   175         platformAnnotations = initPlatformAnnotations();
   175         foundTypeProcessors = false;
       
   176 
   176 
   177         // Initialize services before any processors are initialized
   177         // Initialize services before any processors are initialized
   178         // in case processors use them.
   178         // in case processors use them.
   179         filer = new JavacFiler(context);
   179         filer = new JavacFiler(context);
   180         messager = new JavacMessager(context, this);
   180         messager = new JavacMessager(context, this);
   460 
   460 
   461     /**
   461     /**
   462      * State about how a processor has been used by the tool.  If a
   462      * State about how a processor has been used by the tool.  If a
   463      * processor has been used on a prior round, its process method is
   463      * processor has been used on a prior round, its process method is
   464      * called on all subsequent rounds, perhaps with an empty set of
   464      * called on all subsequent rounds, perhaps with an empty set of
   465      * annotations to process.  The {@code annotatedSupported} method
   465      * annotations to process.  The {@code annotationSupported} method
   466      * caches the supported annotation information from the first (and
   466      * caches the supported annotation information from the first (and
   467      * only) getSupportedAnnotationTypes call to the processor.
   467      * only) getSupportedAnnotationTypes call to the processor.
   468      */
   468      */
   469     static class ProcessorState {
   469     static class ProcessorState {
   470         public Processor processor;
   470         public Processor processor;
   880         }
   880         }
   881 
   881 
   882         /** Create the compiler to be used for the final compilation. */
   882         /** Create the compiler to be used for the final compilation. */
   883         JavaCompiler finalCompiler(boolean errorStatus) {
   883         JavaCompiler finalCompiler(boolean errorStatus) {
   884             try {
   884             try {
   885                 JavaCompiler c = JavaCompiler.instance(nextContext());
   885                 Context nextCtx = nextContext();
       
   886                 JavacProcessingEnvironment.this.context = nextCtx;
       
   887                 JavaCompiler c = JavaCompiler.instance(nextCtx);
   886                 c.log.nwarnings += compiler.log.nwarnings;
   888                 c.log.nwarnings += compiler.log.nwarnings;
   887                 if (errorStatus) {
   889                 if (errorStatus) {
   888                     c.log.nerrors += compiler.log.nerrors;
   890                     c.log.nerrors += compiler.log.nerrors;
   889                 }
   891                 }
   890                 return c;
   892                 return c;
  1019                         lastRound);
  1021                         lastRound);
  1020             }
  1022             }
  1021         }
  1023         }
  1022 
  1024 
  1023         /** Get the context for the next round of processing.
  1025         /** Get the context for the next round of processing.
  1024          * Important values are propogated from round to round;
  1026          * Important values are propagated from round to round;
  1025          * other values are implicitly reset.
  1027          * other values are implicitly reset.
  1026          */
  1028          */
  1027         private Context nextContext() {
  1029         private Context nextContext() {
  1028             Context next = new Context(context);
  1030             Context next = new Context(context);
  1029 
  1031 
  1188             if (compiler.errorCount() == 0)
  1190             if (compiler.errorCount() == 0)
  1189                 compiler.log.nerrors++;
  1191                 compiler.log.nerrors++;
  1190             return compiler;
  1192             return compiler;
  1191         }
  1193         }
  1192 
  1194 
  1193         if (procOnly && !foundTypeProcessors) {
  1195         compiler.enterTreesIfNeeded(roots);
  1194             compiler.todo.clear();
       
  1195         } else {
       
  1196             if (procOnly && foundTypeProcessors)
       
  1197                 compiler.shouldStopPolicy = CompileState.FLOW;
       
  1198 
       
  1199             compiler.enterTrees(roots);
       
  1200         }
       
  1201 
  1196 
  1202         return compiler;
  1197         return compiler;
  1203     }
  1198     }
  1204 
  1199 
  1205     private void warnIfUnmatchedOptions() {
  1200     private void warnIfUnmatchedOptions() {