6794582: javadoc should read files using a FileManager
authorjjg
Tue, 20 Jan 2009 15:17:45 -0800
changeset 1869 0e193a8f3520
parent 1868 391ba14d071e
child 1870 57a1138dffc8
6794582: javadoc should read files using a FileManager Reviewed-by: darcy, bpatel
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/SourceToHTMLConverter.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java
langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java
langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java
langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java
langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java
langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,12 +25,11 @@
 
 package com.sun.tools.doclets.formats.html.markup;
 
-import com.sun.tools.doclets.internal.toolkit.*;
+import java.io.*;
+import java.util.*;
 
 import com.sun.javadoc.*;
-import java.io.*;
-import java.util.*;
-import com.sun.tools.doclets.internal.toolkit.util.*;
+import com.sun.tools.doclets.internal.toolkit.*;
 
 
 /**
@@ -56,8 +55,9 @@
         super(configuration,
               null, configuration.destDirName + filename,
               configuration.docencoding);
+        // use File to normalize file separators
         configuration.message.notice("doclet.Generating_0",
-                                     configuration.destDirName + filename);
+            new File(configuration.destDirName, filename));
     }
 
     public HtmlDocWriter(Configuration configuration,
@@ -65,10 +65,10 @@
         super(configuration,
               configuration.destDirName + path, filename,
               configuration.docencoding);
+        // use File to normalize file separators
         configuration.message.notice("doclet.Generating_0",
-                                     configuration.destDirName +
-                                         ((path.length() > 0)?
-                                              path + File.separator: "") + filename);
+            new File(configuration.destDirName,
+                    ((path.length() > 0)? path + File.separator: "") + filename));
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/SourceToHTMLConverter.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/SourceToHTMLConverter.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,10 +25,12 @@
 
 package com.sun.tools.doclets.internal.toolkit.util;
 
-import com.sun.tools.doclets.internal.toolkit.*;
-import com.sun.javadoc.*;
 import java.io.*;
 import java.util.*;
+import javax.tools.FileObject;
+
+import com.sun.javadoc.*;
+import com.sun.tools.doclets.internal.toolkit.*;
 
 /**
  * Converts Java Source Code to HTML.
@@ -123,16 +125,27 @@
         if (cd == null || outputdir == null) {
             return;
         }
-        File file;
-        SourcePosition sp = cd.position();
-        if (sp == null || (file = sp.file()) == null) {
-            return;
-        }
         try {
+            SourcePosition sp = cd.position();
+            if (sp == null)
+                return;
+            Reader r;
+            // temp hack until we can update SourcePosition API.
+            if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
+                FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
+                if (fo == null)
+                    return;
+                r = fo.openReader(true);
+            } else {
+                File file = sp.file();
+                if (file == null)
+                    return;
+                r = new FileReader(file);
+            }
+            LineNumberReader reader = new LineNumberReader(r);
             int lineno = 1;
             String line;
             StringBuffer output = new StringBuffer();
-            LineNumberReader reader = new LineNumberReader(new FileReader(file));
             try {
                 while ((line = reader.readLine()) != null) {
                     output.append(formatLine(line, configuration.sourcetab, lineno));
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,10 +25,11 @@
 
 package com.sun.tools.doclets.internal.toolkit.util;
 
+import java.io.*;
+import java.util.*;
+
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.internal.toolkit.*;
-import java.util.*;
-import java.io.*;
 
 /**
  * Utilities Class for Doclets.
@@ -579,7 +580,7 @@
      * @param docencoding Encoding to be used for this file.
      * @exception IOException Exception raised by the FileWriter is passed on
      * to next level.
-     * @exception UnSupportedEncodingException Exception raised by the
+     * @exception UnsupportedEncodingException Exception raised by the
      * OutputStreamWriter is passed on to next level.
      * @return Writer Writer for the file getting generated.
      * @see java.io.FileOutputStream
@@ -598,8 +599,7 @@
             fos = new FileOutputStream(filename);
         }
         if (docencoding == null) {
-            OutputStreamWriter oswriter = new OutputStreamWriter(fos);
-            return oswriter;
+            return new OutputStreamWriter(fos);
         } else {
             return new OutputStreamWriter(fos, docencoding);
         }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,42 +25,48 @@
 
 package com.sun.tools.javadoc;
 
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+import javax.tools.FileObject;
+import javax.tools.JavaFileManager.Location;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+
 import com.sun.javadoc.*;
 
 import static com.sun.javadoc.LanguageVersion.*;
 
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.Position;
-
 import com.sun.tools.javac.code.Flags;
 import com.sun.tools.javac.code.Kinds;
-import com.sun.tools.javac.code.TypeTags;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.code.Type.ClassType;
 import com.sun.tools.javac.code.Scope;
 import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.ClassType;
+import com.sun.tools.javac.code.TypeTags;
 
 import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Env;
 
 import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
 import com.sun.tools.javac.tree.JCTree.JCImport;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.TreeInfo;
 
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Name;
 import com.sun.tools.javac.util.Names;
+import com.sun.tools.javac.util.Position;
+
 import static com.sun.tools.javac.code.Flags.*;
 import static com.sun.tools.javac.code.Kinds.*;
 
-import java.io.File;
-import java.util.Set;
-import java.util.HashSet;
-import java.lang.reflect.Modifier;
-
 /**
  * Represents a java class and provides access to information
  * about the class, the class' comment and tags, and the
@@ -271,16 +277,41 @@
      */
     public PackageDoc containingPackage() {
         PackageDocImpl p = env.getPackageDoc(tsym.packge());
-        SourcePosition po = position();
-        if (po != null && p.setDocPath == false && p.zipDocPath == null) {
-            //Set the package path if possible
-            File packageDir = po.file().getParentFile();
-            if (packageDir != null
-                && (new File(packageDir, "package.html")).exists()) {
-                p.setDocPath(packageDir.getPath());
-            } else {
-                p.setDocPath(null);
+        if (p.setDocPath == false) {
+            FileObject docPath;
+            try {
+                Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
+                    ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
+
+                docPath = env.fileManager.getFileForInput(
+                        location, p.qualifiedName(), "package.html");
+            } catch (IOException e) {
+                docPath = null;
             }
+
+            if (docPath == null) {
+                // fall back on older semantics of looking in same directory as
+                // source file for this class
+                SourcePosition po = position();
+                if (env.fileManager instanceof StandardJavaFileManager &&
+                        po instanceof SourcePositionImpl) {
+                    URI uri = ((SourcePositionImpl) po).filename.toUri();
+                    if ("file".equals(uri.getScheme())) {
+                        File f = new File(uri.getPath());
+                        File dir = f.getParentFile();
+                        if (dir != null) {
+                            File pf = new File(dir, "package.html");
+                            if (pf.exists()) {
+                                StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
+                                docPath = sfm.getJavaFileObjects(pf).iterator().next();
+                            }
+                        }
+
+                    }
+                }
+            }
+
+            p.setDocPath(docPath);
         }
         return p;
     }
@@ -1251,7 +1282,7 @@
      */
     public SourcePosition position() {
         if (tsym.sourcefile == null) return null;
-        return SourcePositionImpl.make(tsym.sourcefile.toString(),
+        return SourcePositionImpl.make(tsym.sourcefile,
                                        (tree==null) ? Position.NOPOS : tree.pos,
                                        lineMap);
     }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,8 +25,9 @@
 
 package com.sun.tools.javadoc;
 
+import java.lang.reflect.Modifier;
 import java.util.*;
-import java.lang.reflect.Modifier;
+import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
 
@@ -40,7 +41,6 @@
 import com.sun.tools.javac.util.Names;
 import com.sun.tools.javac.util.Position;
 
-
 /**
  * Holds the environment for a run of javadoc.
  * Holds only the information needed throughout the
@@ -103,6 +103,7 @@
 
     Check chk;
     Types types;
+    JavaFileManager fileManager;
 
     /** Allow documenting from class files? */
     boolean docClasses = false;
@@ -133,6 +134,7 @@
         externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
         chk = Check.instance(context);
         types = Types.instance(context);
+        fileManager = context.get(JavaFileManager.class);
 
         // Default.  Should normally be reset with setLocale.
         this.doclocale = new DocLocale(this, "", breakiterator);
--- a/langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,11 +25,13 @@
 
 package com.sun.tools.javadoc;
 
-import com.sun.javadoc.*;
-
 import java.io.InputStream;
 import java.io.IOException;
 import java.text.CollationKey;
+import javax.tools.FileObject;
+
+import com.sun.javadoc.*;
+
 import com.sun.tools.javac.util.Position;
 
 /**
@@ -43,7 +45,7 @@
  * @author Atul M Dambalkar
  * @author Neal Gafter (rewrite)
  */
-abstract class DocImpl implements Doc, Comparable<Object> {
+public abstract class DocImpl implements Doc, Comparable<Object> {
 
     /**
      * Doc environment
@@ -163,7 +165,7 @@
     /**
      * Utility for subclasses which read HTML documentation files.
      */
-    String readHTMLDocumentation(InputStream input, String filename) throws IOException {
+    String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException {
         int filesize = input.available();
         byte[] filecontents = new byte[filesize];
         input.read(filecontents, 0, filesize);
--- a/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,20 +25,18 @@
 
 package com.sun.tools.javadoc;
 
+import java.lang.reflect.Modifier;
+import java.text.CollationKey;
+
 import com.sun.javadoc.*;
 
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Position;
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
-
-import java.text.CollationKey;
-
-import java.lang.reflect.Modifier;
 
 /**
  * Represents a method or constructor of a java class.
@@ -267,7 +265,7 @@
      */
     public SourcePosition position() {
         if (sym.enclClass().sourcefile == null) return null;
-        return SourcePositionImpl.make(sym.enclClass().sourcefile.toString(),
+        return SourcePositionImpl.make(sym.enclClass().sourcefile,
                                        (tree==null) ? 0 : tree.pos,
                                        lineMap);
     }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,6 +25,8 @@
 
 package com.sun.tools.javadoc;
 
+import java.lang.reflect.Modifier;
+
 import com.sun.javadoc.*;
 
 import static com.sun.javadoc.LanguageVersion.*;
@@ -38,9 +40,6 @@
 
 import com.sun.tools.javac.util.Position;
 
-import java.lang.reflect.Modifier;
-
-
 /**
  * Represents a field in a java class.
  *
@@ -260,7 +259,7 @@
      */
     public SourcePosition position() {
         if (sym.enclClass().sourcefile == null) return null;
-        return SourcePositionImpl.make(sym.enclClass().sourcefile.toString(),
+        return SourcePositionImpl.make(sym.enclClass().sourcefile,
                                        (tree==null) ? 0 : tree.pos,
                                        lineMap);
     }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,18 +25,13 @@
 
 package com.sun.tools.javadoc;
 
+import java.util.EnumSet;
+import javax.tools.JavaFileObject;
+
 import com.sun.tools.javac.code.Symbol.PackageSymbol;
-import com.sun.tools.javac.file.JavacFileManager;
-import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
-import com.sun.tools.javac.file.Old199;
-import com.sun.tools.javac.file.ZipFileIndexArchive;
 import com.sun.tools.javac.jvm.ClassReader;
 import com.sun.tools.javac.util.Context;
 
-import java.io.File;
-import java.util.EnumSet;
-import javax.tools.JavaFileObject;
-
 /** Javadoc uses an extended class reader that records package.html entries
  *  @author Neal Gafter
  */
@@ -82,32 +77,7 @@
      */
     @Override
     protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
-        CharSequence fileName = Old199.getName(fo);
-        if (docenv != null && fileName.equals("package.html")) {
-            if (fo instanceof ZipFileObject) {
-                ZipFileObject zfo = (ZipFileObject) fo;
-                String zipName = zfo.getZipName();
-                String entryName = zfo.getZipEntryName();
-                int lastSep = entryName.lastIndexOf("/");
-                String classPathName = entryName.substring(0, lastSep + 1);
-                docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
-            }
-            else if (fo instanceof ZipFileIndexArchive.ZipFileIndexFileObject) {
-                ZipFileIndexArchive.ZipFileIndexFileObject zfo = (ZipFileIndexArchive.ZipFileIndexFileObject) fo;
-                String zipName = zfo.getZipName();
-                String entryName = zfo.getZipEntryName();
-                if (File.separatorChar != '/') {
-                    entryName = entryName.replace(File.separatorChar, '/');
-                }
-
-                int lastSep = entryName.lastIndexOf("/");
-                String classPathName = entryName.substring(0, lastSep + 1);
-                docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
-            }
-            else {
-                File fileDir = new File(Old199.getPath(fo)).getParentFile();
-                docenv.getPackageDoc(pack).setDocPath(fileDir.getAbsolutePath());
-            }
-        }
+        if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))
+            docenv.getPackageDoc(pack).setDocPath(fo);
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,17 +25,29 @@
 
 package com.sun.tools.javadoc;
 
-import java.io.*;
-
+import java.io.File;
+import java.io.IOException;
 import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.tools.JavaFileManager.Location;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
 
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.comp.*;
-import com.sun.tools.javac.file.Paths;
+import com.sun.tools.javac.code.Symbol.CompletionFailure;
+import com.sun.tools.javac.comp.Annotate;
 import com.sun.tools.javac.parser.DocCommentScanner;
-import com.sun.tools.javac.tree.*;
-import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.util.*;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.util.Abort;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Position;
 
 
 /**
@@ -53,7 +65,6 @@
     final JavadocClassReader reader;
     final JavadocEnter enter;
     final Annotate annotate;
-    private final Paths paths;
 
     /**
      * Construct a new JavaCompiler processor, using appropriately
@@ -66,7 +77,6 @@
         reader = JavadocClassReader.instance0(context);
         enter = JavadocEnter.instance0(context);
         annotate = Annotate.instance(context);
-        paths = Paths.instance(context);
     }
 
     /**
@@ -120,7 +130,7 @@
                       boolean quiet) throws IOException {
         docenv = DocEnv.instance(context);
         docenv.showAccess = filter;
-    docenv.quiet = quiet;
+        docenv.quiet = quiet;
         docenv.breakiterator = breakiterator;
         docenv.setLocale(doclocale);
         docenv.setEncoding(encoding);
@@ -133,12 +143,14 @@
         ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
 
         try {
+            StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
             for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
                 String name = it.head;
                 if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
+                    JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
                     docenv.notice("main.Loading_source_file", name);
-                        JCCompilationUnit tree = parse(name);
-                        classTrees.append(tree);
+                    JCCompilationUnit tree = parse(fo);
+                    classTrees.append(tree);
                 } else if (isValidPackageName(name)) {
                     names = names.append(name);
                 } else if (name.endsWith(".java")) {
@@ -151,12 +163,14 @@
             if (!docClasses) {
                 // Recursively search given subpackages.  If any packages
                 //are found, add them to the list.
-                searchSubPackages(subPackages, names, excludedPackages);
+                Map<String,List<JavaFileObject>> packageFiles =
+                        searchSubPackages(subPackages, names, excludedPackages);
 
                 // Parse the packages
                 for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
                     // Parse sources ostensibly belonging to package.
-                    parsePackageClasses(packs.head, packTrees, excludedPackages);
+                    String packageName = packs.head;
+                    parsePackageClasses(packageName, packageFiles.get(packageName), packTrees, excludedPackages);
                 }
 
                 if (messager.nerrors() != 0) return null;
@@ -167,7 +181,8 @@
             }
         } catch (Abort ex) {}
 
-        if (messager.nerrors() != 0) return null;
+        if (messager.nerrors() != 0)
+            return null;
 
         if (docClasses)
             return new RootDocImpl(docenv, javaNames, options);
@@ -185,66 +200,129 @@
         return isValidClassName(s);
     }
 
-
-    private final static char pathSep = File.pathSeparatorChar;
-
     /**
      * search all directories in path for subdirectory name. Add all
      * .java files found in such a directory to args.
      */
     private void parsePackageClasses(String name,
-                                     ListBuffer<JCCompilationUnit> trees,
-                                     List<String> excludedPackages)
-        throws IOException {
+            Iterable<JavaFileObject> files,
+            ListBuffer<JCCompilationUnit> trees,
+            List<String> excludedPackages)
+            throws IOException {
         if (excludedPackages.contains(name)) {
             return;
         }
+
         boolean hasFiles = false;
         docenv.notice("main.Loading_source_files_for_package", name);
-        name = name.replace('.', File.separatorChar);
-        for (File pathname : paths.sourceSearchPath()) {
-            File f = new File(pathname, name);
-            String names[] = f.list();
-            // if names not null, then found directory with source files
-            if (names != null) {
-                String dir = f.getAbsolutePath();
-                if (!dir.endsWith(File.separator))
-                    dir = dir + File.separator;
-                for (int j = 0; j < names.length; j++) {
-                    if (isValidJavaSourceFile(names[j])) {
-                        String fn = dir + names[j];
-                        // messager.notice("main.Loading_source_file", fn);
-                            trees.append(parse(fn));
-                        hasFiles = true;
-                    }
+
+        if (files == null) {
+            Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
+                    ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
+            ListBuffer<JavaFileObject> lb = new ListBuffer<JavaFileObject>();
+            for (JavaFileObject fo: docenv.fileManager.list(
+                    location, name, EnumSet.of(JavaFileObject.Kind.SOURCE), false)) {
+                String binaryName = docenv.fileManager.inferBinaryName(location, fo);
+                String simpleName = getSimpleName(binaryName);
+                if (isValidClassName(simpleName)) {
+                    lb.append(fo);
                 }
             }
+            files = lb.toList();
         }
-        if (!hasFiles)
+
+        for (JavaFileObject fo : files) {
+            // messager.notice("main.Loading_source_file", fn);
+            trees.append(parse(fo));
+            hasFiles = true;
+        }
+
+        if (!hasFiles) {
             messager.warning(null, "main.no_source_files_for_package",
-                             name.replace(File.separatorChar, '.'));
+                    name.replace(File.separatorChar, '.'));
+        }
     }
 
     /**
      * Recursively search all directories in path for subdirectory name.
      * Add all packages found in such a directory to packages list.
      */
+    private Map<String,List<JavaFileObject>> searchSubPackages(
+            List<String> subPackages,
+            ListBuffer<String> packages,
+            List<String> excludedPackages)
+            throws IOException {
+        Map<String,List<JavaFileObject>> packageFiles =
+                new HashMap<String,List<JavaFileObject>>();
+
+        Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
+        includedPackages.put("", true);
+        for (String p: excludedPackages)
+            includedPackages.put(p, false);
+
+        if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
+            searchSubPackages(subPackages,
+                    includedPackages,
+                    packages, packageFiles,
+                    StandardLocation.SOURCE_PATH,
+                    EnumSet.of(JavaFileObject.Kind.SOURCE));
+            searchSubPackages(subPackages,
+                    includedPackages,
+                    packages, packageFiles,
+                    StandardLocation.CLASS_PATH,
+                    EnumSet.of(JavaFileObject.Kind.CLASS));
+        } else {
+            searchSubPackages(subPackages,
+                    includedPackages,
+                    packages, packageFiles,
+                    StandardLocation.CLASS_PATH,
+                    EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS));
+        }
+        return packageFiles;
+    }
+
     private void searchSubPackages(List<String> subPackages,
-                                   ListBuffer<String> packages,
-                                   List<String> excludedPackages) {
-        // FIXME: This search path is bogus.
-        // Only the effective source path should be searched for sources.
-        // Only the effective class path should be searched for classes.
-        // Should the bootclasspath/extdirs also be searched for classes?
-        java.util.List<File> pathnames = new java.util.ArrayList<File>();
-        if (paths.sourcePath() != null)
-            for (File elt : paths.sourcePath())
-                pathnames.add(elt);
-        for (File elt : paths.userClassPath())
-            pathnames.add(elt);
+            Map<String,Boolean> includedPackages,
+            ListBuffer<String> packages,
+            Map<String, List<JavaFileObject>> packageFiles,
+            StandardLocation location, Set<JavaFileObject.Kind> kinds)
+            throws IOException {
+        for (String subPackage: subPackages) {
+            if (!isIncluded(subPackage, includedPackages))
+                continue;
 
-        for (String subPackage : subPackages)
-            searchSubPackage(subPackage, packages, excludedPackages, pathnames);
+            for (JavaFileObject fo: docenv.fileManager.list(location, subPackage, kinds, true)) {
+                String binaryName = docenv.fileManager.inferBinaryName(location, fo);
+                String packageName = getPackageName(binaryName);
+                String simpleName = getSimpleName(binaryName);
+                if (isIncluded(packageName, includedPackages) && isValidClassName(simpleName)) {
+                    List<JavaFileObject> list = packageFiles.get(packageName);
+                    list = (list == null ? List.of(fo) : list.prepend(fo));
+                    packageFiles.put(packageName, list);
+                    if (!packages.contains(packageName))
+                        packages.add(packageName);
+                }
+            }
+        }
+    }
+
+    private String getPackageName(String name) {
+        int lastDot = name.lastIndexOf(".");
+        return (lastDot == -1 ? "" : name.substring(0, lastDot));
+    }
+
+    private String getSimpleName(String name) {
+        int lastDot = name.lastIndexOf(".");
+        return (lastDot == -1 ? name : name.substring(lastDot + 1));
+    }
+
+    private boolean isIncluded(String packageName, Map<String,Boolean> includedPackages) {
+        Boolean b = includedPackages.get(packageName);
+        if (b == null) {
+            b = isIncluded(getPackageName(packageName), includedPackages);
+            includedPackages.put(packageName, b);
+        }
+        return b;
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,30 +25,23 @@
 
 package com.sun.tools.javadoc;
 
-import com.sun.javadoc.*;
+import java.io.InputStream;
+import java.io.IOException;
+import javax.tools.FileObject;
 
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipEntry;
+import com.sun.javadoc.*;
 
 import com.sun.tools.javac.code.Attribute;
 import com.sun.tools.javac.code.Scope;
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import com.sun.tools.javac.code.Symbol.PackageSymbol;
-import com.sun.tools.javac.comp.AttrContext;
-import com.sun.tools.javac.comp.Env;
 import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Name;
 import com.sun.tools.javac.util.Position;
 
-import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-
-
 /**
  * Represents a java package.  Provides access to information
  * about the package, the package's comment and tags, and the
@@ -63,14 +56,10 @@
 
 public class PackageDocImpl extends DocImpl implements PackageDoc {
 
-    private static final String PACKAGE_HTML_FILE_NAME = "package.html";
-
     protected PackageSymbol sym;
     private JCCompilationUnit tree = null;    // for source position
 
-    public String docPath = null;
-    public String zipDocPath = null;
-    public String zipDocEntry = null;
+    public FileObject docPath = null;
     private boolean foundDoc;   // found a doc comment in either
                                 // package.html or package-info.java
 
@@ -108,30 +97,16 @@
      * Do lazy initialization of "documentation" string.
      */
     String documentation() {
-        if (documentation != null) return documentation;
-        if (zipDocPath != null) {
-            try {
-                ZipFile f = new ZipFile(zipDocPath);
-                ZipEntry entry = f.getEntry(zipDocEntry);
-                if (entry != null) {
-                    InputStream s = f.getInputStream(entry);
-                    return (documentation = readHTMLDocumentation(s,
-                        zipDocPath + File.separatorChar + zipDocEntry));
-                }
-            } catch (IOException exc) {
-                documentation = "";
-                env.error(null, "javadoc.File_Read_Error",
-                          zipDocPath + File.separatorChar + zipDocEntry);
-            }
-        }
+        if (documentation != null)
+            return documentation;
         if (docPath != null) {
             // read from file
             try {
-                InputStream s = new FileInputStream(docPath);
+                InputStream s = docPath.openInputStream();
                 documentation = readHTMLDocumentation(s, docPath);
             } catch (IOException exc) {
                 documentation = "";
-                env.error(null, "javadoc.File_Read_Error", docPath);
+                env.error(null, "javadoc.File_Read_Error", docPath.getName());
             }
         } else {
             // no doc file to be had
@@ -363,24 +338,12 @@
     /**
      * set doc path for an unzipped directory
      */
-    public void setDocPath(String path) {
+    public void setDocPath(FileObject path) {
         setDocPath = true;
         if (path == null)
             return;
-        String newDocPath = path + File.separatorChar + PACKAGE_HTML_FILE_NAME;
-        if (!newDocPath.equals(docPath)) {
-            docPath = newDocPath;
-            checkDoc();
-        }
-    }
-
-    /**
-     * set the doc path for zipped directory
-     */
-    public void setDocPath(String path, String entry) {
-        if (!path.equals(zipDocPath)) {
-            zipDocPath = path;
-            zipDocEntry = entry + PACKAGE_HTML_FILE_NAME;
+        if (!path.equals(docPath)) {
+            docPath = path;
             checkDoc();
         }
     }
@@ -409,7 +372,7 @@
      */
     public SourcePosition position() {
         return (tree != null)
-                ? SourcePositionImpl.make(tree.sourcefile + "", tree.pos, tree.lineMap)
+                ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
                 : SourcePositionImpl.make(docPath, Position.NOPOS, null);
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/RootDocImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -26,17 +26,16 @@
 package com.sun.tools.javadoc;
 
 import java.io.IOException;
-import java.io.FileInputStream;
-import java.io.File;
+import java.util.Locale;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
 
 import com.sun.javadoc.*;
 
 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
-import com.sun.tools.javac.code.Symbol;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Position;
-import java.util.Locale;
 
 /**
  * This class holds the information from one run of javadoc.
@@ -308,10 +307,13 @@
      * Return the path of the overview file and null if it does not exist.
      * @return the path of the overview file and null if it does not exist.
      */
-    private String getOverviewPath() {
+    private JavaFileObject getOverviewPath() {
         for (String[] opt : options) {
             if (opt[0].equals("-overview")) {
-                return opt[1];
+                if (env.fileManager instanceof StandardJavaFileManager) {
+                    StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
+                    return fm.getJavaFileObjects(opt[1]).iterator().next();
+                }
             }
         }
         return null;
@@ -323,7 +325,7 @@
     protected String documentation() {
         if (documentation == null) {
             int cnt = options.length();
-            String overviewPath = getOverviewPath();
+            JavaFileObject overviewPath = getOverviewPath();
             if (overviewPath == null) {
                 // no doc file to be had
                 documentation = "";
@@ -331,11 +333,11 @@
                 // read from file
                 try {
                     documentation = readHTMLDocumentation(
-                        new FileInputStream(overviewPath),
+                        overviewPath.openInputStream(),
                         overviewPath);
                 } catch (IOException exc) {
                     documentation = "";
-                    env.error(null, "javadoc.File_Read_Error", overviewPath);
+                    env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
                 }
             }
         }
@@ -347,7 +349,7 @@
      * no position is available.
      */
     public SourcePosition position() {
-        String path;
+        JavaFileObject path;
         return ((path = getOverviewPath()) == null) ?
             null :
             SourcePositionImpl.make(path, Position.NOPOS, null);
--- a/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Tue Jan 20 17:49:49 2009 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java	Tue Jan 20 15:17:45 2009 -0800
@@ -25,11 +25,12 @@
 
 package com.sun.tools.javadoc;
 
+import java.io.File;
+import javax.tools.FileObject;
+
 import com.sun.javadoc.SourcePosition;
 import com.sun.tools.javac.util.Position;
 
-import java.io.File;
-
 /**
  * A source position: filename, line number, and column number.
  *
@@ -37,15 +38,21 @@
  * @author Neal M Gafter
  * @author Michael Van De Vanter (position representation changed to char offsets)
  */
-class SourcePositionImpl implements SourcePosition {
-    String filename;
+public class SourcePositionImpl implements SourcePosition {
+    FileObject filename;
     int position;
     Position.LineMap lineMap;
 
     /** The source file. Returns null if no file information is
      *  available. */
     public File file() {
-        return (filename == null) ? null : new File(filename);
+        return (filename == null) ? null : new File(filename.getName());
+    }
+
+    /** The source file. Returns null if no file information is
+     *  available. */
+    public FileObject fileObject() {
+        return filename;
     }
 
     /** The line in the source file. The first line is numbered 1;
@@ -71,7 +78,7 @@
         }
     }
 
-    private SourcePositionImpl(String file, int position,
+    private SourcePositionImpl(FileObject file, int position,
                                Position.LineMap lineMap) {
         super();
         this.filename = file;
@@ -79,16 +86,27 @@
         this.lineMap = lineMap;
     }
 
-    public static SourcePosition make(String file, int pos,
+    public static SourcePosition make(FileObject file, int pos,
                                       Position.LineMap lineMap) {
         if (file == null) return null;
         return new SourcePositionImpl(file, pos, lineMap);
     }
 
     public String toString() {
+        // Backwards compatibility hack. ZipFileObjects use the format
+        // zipfile(zipentry) but javadoc has been using zipfile/zipentry
+        String fn = filename.toString();
+        if (fn.endsWith(")")) {
+            int paren = fn.lastIndexOf("(");
+            if (paren != -1)
+                fn = fn.substring(0, paren)
+                        + File.separatorChar
+                        + fn.substring(paren + 1, fn.length() - 1);
+        }
+
         if (position == Position.NOPOS)
-            return filename;
+            return fn;
         else
-            return filename + ":" + line();
+            return fn + ":" + line();
     }
 }