langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
changeset 6721 d92073844278
parent 6717 0103d76cfe48
child 6924 ef7a9281ad2f
equal deleted inserted replaced
6720:f16f91662ad8 6721:d92073844278
    77 import com.sun.tools.javac.util.Names;
    77 import com.sun.tools.javac.util.Names;
    78 import com.sun.tools.javac.util.Options;
    78 import com.sun.tools.javac.util.Options;
    79 
    79 
    80 import static javax.tools.StandardLocation.*;
    80 import static javax.tools.StandardLocation.*;
    81 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
    81 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*;
       
    82 import static com.sun.tools.javac.main.OptionName.*;
       
    83 import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
    82 
    84 
    83 /**
    85 /**
    84  * Objects of this class hold and manage the state needed to support
    86  * Objects of this class hold and manage the state needed to support
    85  * annotation processing.
    87  * annotation processing.
    86  *
    88  *
   158         this.context = context;
   160         this.context = context;
   159         log = Log.instance(context);
   161         log = Log.instance(context);
   160         source = Source.instance(context);
   162         source = Source.instance(context);
   161         diags = JCDiagnostic.Factory.instance(context);
   163         diags = JCDiagnostic.Factory.instance(context);
   162         options = Options.instance(context);
   164         options = Options.instance(context);
   163         printProcessorInfo = options.get("-XprintProcessorInfo") != null;
   165         printProcessorInfo = options.isSet(XPRINTPROCESSORINFO);
   164         printRounds = options.get("-XprintRounds") != null;
   166         printRounds = options.isSet(XPRINTROUNDS);
   165         verbose = options.get("-verbose") != null;
   167         verbose = options.isSet(VERBOSE);
   166         lint = options.lint("processing");
   168         lint = Lint.instance(context).isEnabled(PROCESSING);
   167         procOnly = options.get("-proc:only") != null ||
   169         procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT);
   168             options.get("-Xprint") != null;
   170         fatalErrors = options.isSet("fatalEnterError");
   169         fatalErrors = options.get("fatalEnterError") != null;
   171         showResolveErrors = options.isSet("showResolveErrors");
   170         showResolveErrors = options.get("showResolveErrors") != null;
   172         werror = options.isSet(WERROR);
   171         werror = options.get("-Werror") != null;
       
   172         platformAnnotations = initPlatformAnnotations();
   173         platformAnnotations = initPlatformAnnotations();
   173         foundTypeProcessors = false;
   174         foundTypeProcessors = false;
   174 
   175 
   175         // Initialize services before any processors are initialzied
   176         // Initialize services before any processors are initialzied
   176         // in case processors use them.
   177         // in case processors use them.
   198 
   199 
   199     private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
   200     private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
   200         Log   log   = Log.instance(context);
   201         Log   log   = Log.instance(context);
   201         Iterator<? extends Processor> processorIterator;
   202         Iterator<? extends Processor> processorIterator;
   202 
   203 
   203         if (options.get("-Xprint") != null) {
   204         if (options.isSet(XPRINT)) {
   204             try {
   205             try {
   205                 Processor processor = PrintingProcessor.class.newInstance();
   206                 Processor processor = PrintingProcessor.class.newInstance();
   206                 processorIterator = List.of(processor).iterator();
   207                 processorIterator = List.of(processor).iterator();
   207             } catch (Throwable t) {
   208             } catch (Throwable t) {
   208                 AssertionError assertError =
   209                 AssertionError assertError =
   211                 throw assertError;
   212                 throw assertError;
   212             }
   213             }
   213         } else if (processors != null) {
   214         } else if (processors != null) {
   214             processorIterator = processors.iterator();
   215             processorIterator = processors.iterator();
   215         } else {
   216         } else {
   216             String processorNames = options.get("-processor");
   217             String processorNames = options.get(PROCESSOR);
   217             JavaFileManager fileManager = context.get(JavaFileManager.class);
   218             JavaFileManager fileManager = context.get(JavaFileManager.class);
   218             try {
   219             try {
   219                 // If processorpath is not explicitly set, use the classpath.
   220                 // If processorpath is not explicitly set, use the classpath.
   220                 processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
   221                 processorClassLoader = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
   221                     ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
   222                     ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
   262             StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
   263             StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
   263             Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
   264             Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
   264                 ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
   265                 ? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
   265                 : standardFileManager.getLocation(CLASS_PATH);
   266                 : standardFileManager.getLocation(CLASS_PATH);
   266 
   267 
   267             if (needClassLoader(options.get("-processor"), workingPath) )
   268             if (needClassLoader(options.get(PROCESSOR), workingPath) )
   268                 handleException(key, e);
   269                 handleException(key, e);
   269 
   270 
   270         } else {
   271         } else {
   271             handleException(key, e);
   272             handleException(key, e);
   272         }
   273         }
   743 
   744 
   744         // Run contributing processors that haven't run yet
   745         // Run contributing processors that haven't run yet
   745         psi.runContributingProcs(renv);
   746         psi.runContributingProcs(renv);
   746 
   747 
   747         // Debugging
   748         // Debugging
   748         if (options.get("displayFilerState") != null)
   749         if (options.isSet("displayFilerState"))
   749             filer.displayState();
   750             filer.displayState();
   750     }
   751     }
   751 
   752 
   752     /**
   753     /**
   753      * Computes the set of annotations on the symbol in question.
   754      * Computes the set of annotations on the symbol in question.