Thu, 18 Sep 2008 18:39:44 -0700
6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel
1 /*
2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.javadoc;
28 import com.sun.tools.javac.code.Symbol.PackageSymbol;
29 import com.sun.tools.javac.file.JavacFileManager;
30 import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
31 import com.sun.tools.javac.file.Old199;
32 import com.sun.tools.javac.file.ZipFileIndexArchive;
33 import com.sun.tools.javac.jvm.ClassReader;
34 import com.sun.tools.javac.util.Context;
36 import java.io.File;
37 import java.util.EnumSet;
38 import javax.tools.JavaFileObject;
40 /** Javadoc uses an extended class reader that records package.html entries
41 * @author Neal Gafter
42 */
43 class JavadocClassReader extends ClassReader {
45 public static JavadocClassReader instance0(Context context) {
46 ClassReader instance = context.get(classReaderKey);
47 if (instance == null)
48 instance = new JavadocClassReader(context);
49 return (JavadocClassReader)instance;
50 }
52 public static void preRegister(final Context context) {
53 context.put(classReaderKey, new Context.Factory<ClassReader>() {
54 public ClassReader make() {
55 return new JavadocClassReader(context);
56 }
57 });
58 }
60 private DocEnv docenv;
61 private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,
62 JavaFileObject.Kind.SOURCE,
63 JavaFileObject.Kind.HTML);
64 private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS,
65 JavaFileObject.Kind.HTML);
67 private JavadocClassReader(Context context) {
68 super(context, true);
69 docenv = DocEnv.instance(context);
70 }
72 /**
73 * Override getPackageFileKinds to include search for package.html
74 */
75 @Override
76 protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
77 return docenv.docClasses ? noSource : all;
78 }
80 /**
81 * Override extraFileActions to check for package documentation
82 */
83 @Override
84 protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
85 CharSequence fileName = Old199.getName(fo);
86 if (docenv != null && fileName.equals("package.html")) {
87 if (fo instanceof ZipFileObject) {
88 ZipFileObject zfo = (ZipFileObject) fo;
89 String zipName = zfo.getZipName();
90 String entryName = zfo.getZipEntryName();
91 int lastSep = entryName.lastIndexOf("/");
92 String classPathName = entryName.substring(0, lastSep + 1);
93 docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
94 }
95 else if (fo instanceof ZipFileIndexArchive.ZipFileIndexFileObject) {
96 ZipFileIndexArchive.ZipFileIndexFileObject zfo = (ZipFileIndexArchive.ZipFileIndexFileObject) fo;
97 String zipName = zfo.getZipName();
98 String entryName = zfo.getZipEntryName();
99 if (File.separatorChar != '/') {
100 entryName = entryName.replace(File.separatorChar, '/');
101 }
103 int lastSep = entryName.lastIndexOf("/");
104 String classPathName = entryName.substring(0, lastSep + 1);
105 docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
106 }
107 else {
108 File fileDir = new File(Old199.getPath(fo)).getParentFile();
109 docenv.getPackageDoc(pack).setDocPath(fileDir.getAbsolutePath());
110 }
111 }
112 }
113 }