langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
changeset 6581 f58f0ce45802
parent 6355 f01ebbf5a5f7
child 6582 c7a4fb5a2f86
equal deleted inserted replaced
6580:d3d578d22cc7 6581:f58f0ce45802
    65 import com.sun.tools.javac.tree.*;
    65 import com.sun.tools.javac.tree.*;
    66 import com.sun.tools.javac.tree.JCTree.*;
    66 import com.sun.tools.javac.tree.JCTree.*;
    67 import com.sun.tools.javac.util.Abort;
    67 import com.sun.tools.javac.util.Abort;
    68 import com.sun.tools.javac.util.Context;
    68 import com.sun.tools.javac.util.Context;
    69 import com.sun.tools.javac.util.Convert;
    69 import com.sun.tools.javac.util.Convert;
       
    70 import com.sun.tools.javac.util.FatalError;
       
    71 import com.sun.tools.javac.util.JCDiagnostic;
    70 import com.sun.tools.javac.util.List;
    72 import com.sun.tools.javac.util.List;
    71 import com.sun.tools.javac.util.Log;
    73 import com.sun.tools.javac.util.Log;
    72 import com.sun.tools.javac.util.JavacMessages;
    74 import com.sun.tools.javac.util.JavacMessages;
    73 import com.sun.tools.javac.util.Name;
    75 import com.sun.tools.javac.util.Name;
    74 import com.sun.tools.javac.util.Names;
    76 import com.sun.tools.javac.util.Names;
   129 
   131 
   130     /** The log to be used for error reporting.
   132     /** The log to be used for error reporting.
   131      */
   133      */
   132     Log log;
   134     Log log;
   133 
   135 
       
   136     /** Diagnostic factory.
       
   137      */
       
   138     JCDiagnostic.Factory diags;
       
   139 
   134     /**
   140     /**
   135      * Source level of the compile.
   141      * Source level of the compile.
   136      */
   142      */
   137     Source source;
   143     Source source;
   138 
   144 
   144     private JavacMessages messages;
   150     private JavacMessages messages;
   145 
   151 
   146     private Context context;
   152     private Context context;
   147 
   153 
   148     public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
   154     public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
   149         options = Options.instance(context);
       
   150         this.context = context;
   155         this.context = context;
   151         log = Log.instance(context);
   156         log = Log.instance(context);
   152         source = Source.instance(context);
   157         source = Source.instance(context);
       
   158         diags = JCDiagnostic.Factory.instance(context);
       
   159         options = Options.instance(context);
   153         printProcessorInfo = options.get("-XprintProcessorInfo") != null;
   160         printProcessorInfo = options.get("-XprintProcessorInfo") != null;
   154         printRounds = options.get("-XprintRounds") != null;
   161         printRounds = options.get("-XprintRounds") != null;
   155         verbose = options.get("-verbose") != null;
   162         verbose = options.get("-verbose") != null;
   156         lint = options.lint("processing");
   163         lint = options.lint("processing");
   157         procOnly = options.get("-proc:only") != null ||
   164         procOnly = options.get("-proc:only") != null ||
   846             findAnnotationsPresent();
   853             findAnnotationsPresent();
   847         }
   854         }
   848 
   855 
   849         /** Create a new round. */
   856         /** Create a new round. */
   850         private Round(Round prev,
   857         private Round(Round prev,
   851                 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles)
   858                 Set<JavaFileObject> newSourceFiles, Map<String,JavaFileObject> newClassFiles) {
   852                 throws IOException {
       
   853             this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings);
   859             this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings);
   854             this.genClassFiles = prev.genClassFiles;
   860             this.genClassFiles = prev.genClassFiles;
   855 
   861 
   856             updateProcessingState();
   862             updateProcessingState();
   857 
   863 
   880 
   886 
   881             findAnnotationsPresent();
   887             findAnnotationsPresent();
   882         }
   888         }
   883 
   889 
   884         /** Create the next round to be used. */
   890         /** Create the next round to be used. */
   885         Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles)
   891         Round next(Set<JavaFileObject> newSourceFiles, Map<String, JavaFileObject> newClassFiles) {
   886                 throws IOException {
       
   887             try {
   892             try {
   888                 return new Round(this, newSourceFiles, newClassFiles);
   893                 return new Round(this, newSourceFiles, newClassFiles);
   889             } finally {
   894             } finally {
   890                 compiler.close(false);
   895                 compiler.close(false);
   891             }
   896             }
  1081     // TODO: internal catch clauses?; catch and rethrow an annotation
  1086     // TODO: internal catch clauses?; catch and rethrow an annotation
  1082     // processing error
  1087     // processing error
  1083     public JavaCompiler doProcessing(Context context,
  1088     public JavaCompiler doProcessing(Context context,
  1084                                      List<JCCompilationUnit> roots,
  1089                                      List<JCCompilationUnit> roots,
  1085                                      List<ClassSymbol> classSymbols,
  1090                                      List<ClassSymbol> classSymbols,
  1086                                      Iterable<? extends PackageSymbol> pckSymbols)
  1091                                      Iterable<? extends PackageSymbol> pckSymbols) {
  1087         throws IOException {
       
  1088 
  1092 
  1089         TaskListener taskListener = context.get(TaskListener.class);
  1093         TaskListener taskListener = context.get(TaskListener.class);
  1090         log = Log.instance(context);
  1094         log = Log.instance(context);
  1091 
  1095 
  1092         Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
  1096         Set<PackageSymbol> specifiedPackages = new LinkedHashSet<PackageSymbol>();
  1182     }
  1186     }
  1183 
  1187 
  1184     /**
  1188     /**
  1185      * Free resources related to annotation processing.
  1189      * Free resources related to annotation processing.
  1186      */
  1190      */
  1187     public void close() throws IOException {
  1191     public void close() {
  1188         filer.close();
  1192         filer.close();
  1189         if (discoveredProcs != null) // Make calling close idempotent
  1193         if (discoveredProcs != null) // Make calling close idempotent
  1190             discoveredProcs.close();
  1194             discoveredProcs.close();
  1191         discoveredProcs = null;
  1195         discoveredProcs = null;
  1192         if (processorClassLoader != null && processorClassLoader instanceof Closeable)
  1196         if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
  1193             ((Closeable) processorClassLoader).close();
  1197             try {
       
  1198                 ((Closeable) processorClassLoader).close();
       
  1199             } catch (IOException e) {
       
  1200                 JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader");
       
  1201                 throw new FatalError(msg, e);
       
  1202             }
       
  1203         }
  1194     }
  1204     }
  1195 
  1205 
  1196     private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
  1206     private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
  1197         List<ClassSymbol> classes = List.nil();
  1207         List<ClassSymbol> classes = List.nil();
  1198         for (JCCompilationUnit unit : units) {
  1208         for (JCCompilationUnit unit : units) {