001: /*
002: * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import com.sun.tools.javac.code.Symbol.PackageSymbol;
029: import com.sun.tools.javac.jvm.ClassReader;
030: import com.sun.tools.javac.util.Context;
031: import com.sun.tools.javac.util.JavacFileManager;
032: import com.sun.tools.javac.util.Old199;
033:
034: import java.io.File;
035: import java.util.EnumSet;
036: import javax.tools.JavaFileObject;
037:
038: /** Javadoc uses an extended class reader that records package.html entries
039: * @author Neal Gafter
040: */
041: class JavadocClassReader extends ClassReader {
042:
043: public static JavadocClassReader instance0(Context context) {
044: ClassReader instance = context.get(classReaderKey);
045: if (instance == null)
046: instance = new JavadocClassReader(context);
047: return (JavadocClassReader) instance;
048: }
049:
050: public static void preRegister(final Context context) {
051: context.put(classReaderKey, new Context.Factory<ClassReader>() {
052: public ClassReader make() {
053: return new JavadocClassReader(context);
054: }
055: });
056: }
057:
058: private DocEnv docenv;
059: private EnumSet<JavaFileObject.Kind> all = EnumSet.of(
060: JavaFileObject.Kind.CLASS, JavaFileObject.Kind.SOURCE,
061: JavaFileObject.Kind.HTML);
062: private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(
063: JavaFileObject.Kind.CLASS, JavaFileObject.Kind.HTML);
064:
065: private JavadocClassReader(Context context) {
066: super (context, true);
067: docenv = DocEnv.instance(context);
068: }
069:
070: /**
071: * Override getPackageFileKinds to include search for package.html
072: */
073: @Override
074: protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
075: return docenv.docClasses ? noSource : all;
076: }
077:
078: /**
079: * Override extraFileActions to check for package documentation
080: */
081: @Override
082: protected void extraFileActions(PackageSymbol pack,
083: JavaFileObject fo) {
084: CharSequence fileName = Old199.getName(fo);
085: if (docenv != null && fileName.equals("package.html")) {
086: if (fo instanceof JavacFileManager.ZipFileObject) {
087: JavacFileManager.ZipFileObject zfo = (JavacFileManager.ZipFileObject) fo;
088: String zipName = zfo.getZipName();
089: String entryName = zfo.getZipEntryName();
090: int lastSep = entryName.lastIndexOf("/");
091: String classPathName = entryName.substring(0,
092: lastSep + 1);
093: docenv.getPackageDoc(pack).setDocPath(zipName,
094: classPathName);
095: } else {
096: File fileDir = new File(Old199.getPath(fo))
097: .getParentFile();
098: docenv.getPackageDoc(pack).setDocPath(
099: fileDir.getAbsolutePath());
100: }
101: }
102: }
103: }
|