langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
changeset 24604 7f68545b5128
parent 24392 aca305440fb9
child 24897 655b72d7b96e
equal deleted inserted replaced
24603:43e7e44d63da 24604:7f68545b5128
   217 
   217 
   218     /** The tree factory module.
   218     /** The tree factory module.
   219      */
   219      */
   220     protected TreeMaker make;
   220     protected TreeMaker make;
   221 
   221 
       
   222     /** The class finder.
       
   223      */
       
   224     protected ClassFinder finder;
       
   225 
   222     /** The class reader.
   226     /** The class reader.
   223      */
   227      */
   224     protected ClassReader reader;
   228     protected ClassReader reader;
   225 
   229 
   226     /** The class writer.
   230     /** The class writer.
   294     /** Broadcasting listener for progress events
   298     /** Broadcasting listener for progress events
   295      */
   299      */
   296     protected MultiTaskListener taskListener;
   300     protected MultiTaskListener taskListener;
   297 
   301 
   298     /**
   302     /**
   299      * SourceCompleter that delegates to the complete-method of this class.
   303      * SourceCompleter that delegates to the readSourceFile method of this class.
   300      */
   304      */
   301     protected final ClassReader.SourceCompleter thisCompleter =
   305     protected final Symbol.Completer sourceCompleter =
   302             new ClassReader.SourceCompleter() {
   306             new Symbol.Completer() {
   303                 @Override
   307                 @Override
   304                 public void complete(ClassSymbol sym) throws CompletionFailure {
   308                 public void complete(Symbol sym) throws CompletionFailure {
   305                     JavaCompiler.this.complete(sym);
   309                     readSourceFile((ClassSymbol) sym);
   306                 }
   310                 }
   307             };
   311             };
   308 
   312 
   309     /**
   313     /**
   310      * Command line options.
   314      * Command line options.
   336             JavacFileManager.preRegister(context);
   340             JavacFileManager.preRegister(context);
   337 
   341 
   338         names = Names.instance(context);
   342         names = Names.instance(context);
   339         log = Log.instance(context);
   343         log = Log.instance(context);
   340         diagFactory = JCDiagnostic.Factory.instance(context);
   344         diagFactory = JCDiagnostic.Factory.instance(context);
       
   345         finder = ClassFinder.instance(context);
   341         reader = ClassReader.instance(context);
   346         reader = ClassReader.instance(context);
   342         make = TreeMaker.instance(context);
   347         make = TreeMaker.instance(context);
   343         writer = ClassWriter.instance(context);
   348         writer = ClassWriter.instance(context);
   344         jniWriter = JNIWriter.instance(context);
   349         jniWriter = JNIWriter.instance(context);
   345         enter = Enter.instance(context);
   350         enter = Enter.instance(context);
   353             // catch completion problems with predefineds
   358             // catch completion problems with predefineds
   354             syms = Symtab.instance(context);
   359             syms = Symtab.instance(context);
   355         } catch (CompletionFailure ex) {
   360         } catch (CompletionFailure ex) {
   356             // inlined Check.completionError as it is not initialized yet
   361             // inlined Check.completionError as it is not initialized yet
   357             log.error("cant.access", ex.sym, ex.getDetailValue());
   362             log.error("cant.access", ex.sym, ex.getDetailValue());
   358             if (ex instanceof ClassReader.BadClassFile)
   363             if (ex instanceof ClassFinder.BadClassFile)
   359                 throw new Abort();
   364                 throw new Abort();
   360         }
   365         }
   361         source = Source.instance(context);
   366         source = Source.instance(context);
   362         Target target = Target.instance(context);
   367         Target target = Target.instance(context);
   363         attr = Attr.instance(context);
   368         attr = Attr.instance(context);
   368         lower = Lower.instance(context);
   373         lower = Lower.instance(context);
   369         annotate = Annotate.instance(context);
   374         annotate = Annotate.instance(context);
   370         types = Types.instance(context);
   375         types = Types.instance(context);
   371         taskListener = MultiTaskListener.instance(context);
   376         taskListener = MultiTaskListener.instance(context);
   372 
   377 
   373         reader.sourceCompleter = thisCompleter;
   378         finder.sourceCompleter = sourceCompleter;
   374 
   379 
   375         options = Options.instance(context);
   380         options = Options.instance(context);
   376 
   381 
   377         verbose       = options.isSet(VERBOSE);
   382         verbose       = options.isSet(VERBOSE);
   378         sourceOutput  = options.isSet(PRINTSOURCE); // used to be -s
   383         sourceOutput  = options.isSet(PRINTSOURCE); // used to be -s
   661      * @param name      The name to resolve
   666      * @param name      The name to resolve
   662      */
   667      */
   663     public Symbol resolveBinaryNameOrIdent(String name) {
   668     public Symbol resolveBinaryNameOrIdent(String name) {
   664         try {
   669         try {
   665             Name flatname = names.fromString(name.replace("/", "."));
   670             Name flatname = names.fromString(name.replace("/", "."));
   666             return reader.loadClass(flatname);
   671             return finder.loadClass(flatname);
   667         } catch (CompletionFailure ignore) {
   672         } catch (CompletionFailure ignore) {
   668             return resolveIdent(name);
   673             return resolveIdent(name);
   669         }
   674         }
   670     }
   675     }
   671 
   676 
   735             chk.completionError(cdef.pos(), ex);
   740             chk.completionError(cdef.pos(), ex);
   736         }
   741         }
   737         return null;
   742         return null;
   738     }
   743     }
   739 
   744 
   740     /** Complete compiling a source file that has been accessed
   745     /** Compile a source file that has been accessed by the class finder.
   741      *  by the class file reader.
       
   742      *  @param c          The class the source file of which needs to be compiled.
   746      *  @param c          The class the source file of which needs to be compiled.
   743      */
   747      */
   744     public void complete(ClassSymbol c) throws CompletionFailure {
   748     private void readSourceFile(ClassSymbol c) throws CompletionFailure {
   745         complete(null, c);
   749         readSourceFile(null, c);
   746     }
   750     }
   747 
   751 
   748     /** Complete a ClassSymbol from source, optionally using the given compilation unit as
   752     /** Compile a ClassSymbol from source, optionally using the given compilation unit as
   749      *  the source tree.
   753      *  the source tree.
   750      *  @param tree the compilation unit int which the given ClassSymbol resides,
   754      *  @param tree the compilation unit in which the given ClassSymbol resides,
   751      *              or null if should be parsed from source
   755      *              or null if should be parsed from source
   752      *  @param c    the ClassSymbol to complete
   756      *  @param c    the ClassSymbol to complete
   753      */
   757      */
   754     public void complete(JCCompilationUnit tree, ClassSymbol c) throws CompletionFailure {
   758     public void readSourceFile(JCCompilationUnit tree, ClassSymbol c) throws CompletionFailure {
   755 //      System.err.println("completing " + c);//DEBUG
       
   756         if (completionFailureName == c.fullname) {
   759         if (completionFailureName == c.fullname) {
   757             throw new CompletionFailure(c, "user-selected completion failure by class name");
   760             throw new CompletionFailure(c, "user-selected completion failure by class name");
   758         }
   761         }
   759         JavaFileObject filename = c.classfile;
   762         JavaFileObject filename = c.classfile;
   760         JavaFileObject prev = log.useSource(filename);
   763         JavaFileObject prev = log.useSource(filename);
   789             if (isPkgInfo) {
   792             if (isPkgInfo) {
   790                 if (enter.getEnv(tree.packge) == null) {
   793                 if (enter.getEnv(tree.packge) == null) {
   791                     JCDiagnostic diag =
   794                     JCDiagnostic diag =
   792                         diagFactory.fragment("file.does.not.contain.package",
   795                         diagFactory.fragment("file.does.not.contain.package",
   793                                                  c.location());
   796                                                  c.location());
   794                     throw reader.new BadClassFile(c, filename, diag);
   797                     throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
   795                 }
   798                 }
   796             } else {
   799             } else {
   797                 JCDiagnostic diag =
   800                 JCDiagnostic diag =
   798                         diagFactory.fragment("file.doesnt.contain.class",
   801                         diagFactory.fragment("file.doesnt.contain.class",
   799                                             c.getQualifiedName());
   802                                             c.getQualifiedName());
   800                 throw reader.new BadClassFile(c, filename, diag);
   803                 throw new ClassFinder.BadClassFile(c, filename, diag, diagFactory);
   801             }
   804             }
   802         }
   805         }
   803 
   806 
   804         implicitSourceFilesRead = true;
   807         implicitSourceFilesRead = true;
   805     }
   808     }
  1661 
  1664 
  1662     /** Close the compiler, flushing the logs
  1665     /** Close the compiler, flushing the logs
  1663      */
  1666      */
  1664     public void close() {
  1667     public void close() {
  1665         rootClasses = null;
  1668         rootClasses = null;
       
  1669         finder = null;
  1666         reader = null;
  1670         reader = null;
  1667         make = null;
  1671         make = null;
  1668         writer = null;
  1672         writer = null;
  1669         enter = null;
  1673         enter = null;
  1670         if (todo != null)
  1674         if (todo != null)