langtools/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java
changeset 24607 e6dff6ac377e
parent 24601 65de78d28a62
parent 24606 12c0ca21f8dc
child 24608 71f05b7d5c10
equal deleted inserted replaced
24601:65de78d28a62 24607:e6dff6ac377e
     1 /*
       
     2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.tools.javadoc;
       
    27 
       
    28 import java.util.EnumSet;
       
    29 import javax.tools.JavaFileObject;
       
    30 
       
    31 import com.sun.tools.javac.code.Symbol.PackageSymbol;
       
    32 import com.sun.tools.javac.jvm.ClassReader;
       
    33 import com.sun.tools.javac.util.Context;
       
    34 
       
    35 /** Javadoc uses an extended class reader that records package.html entries
       
    36  *
       
    37  *  <p><b>This is NOT part of any supported API.
       
    38  *  If you write code that depends on this, you do so at your own risk.
       
    39  *  This code and its internal interfaces are subject to change or
       
    40  *  deletion without notice.</b>
       
    41  *
       
    42  *  @author Neal Gafter
       
    43  */
       
    44 public class JavadocClassReader extends ClassReader {
       
    45 
       
    46     public static JavadocClassReader instance0(Context context) {
       
    47         ClassReader instance = context.get(classReaderKey);
       
    48         if (instance == null)
       
    49             instance = new JavadocClassReader(context);
       
    50         return (JavadocClassReader)instance;
       
    51     }
       
    52 
       
    53     public static void preRegister(Context context) {
       
    54         context.put(classReaderKey, new Context.Factory<ClassReader>() {
       
    55             public ClassReader make(Context c) {
       
    56                 return new JavadocClassReader(c);
       
    57             }
       
    58         });
       
    59     }
       
    60 
       
    61     private DocEnv docenv;
       
    62     private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,
       
    63                                                           JavaFileObject.Kind.SOURCE,
       
    64                                                           JavaFileObject.Kind.HTML);
       
    65     private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS,
       
    66                                                                JavaFileObject.Kind.HTML);
       
    67 
       
    68     public JavadocClassReader(Context context) {
       
    69         super(context);
       
    70         docenv = DocEnv.instance(context);
       
    71         preferSource = true;
       
    72     }
       
    73 
       
    74     /**
       
    75      * Override getPackageFileKinds to include search for package.html
       
    76      */
       
    77     @Override
       
    78     protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
       
    79         return docenv.docClasses ? noSource : all;
       
    80     }
       
    81 
       
    82     /**
       
    83      * Override extraFileActions to check for package documentation
       
    84      */
       
    85     @Override
       
    86     protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
       
    87         if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))
       
    88             docenv.getPackageDoc(pack).setDocPath(fo);
       
    89     }
       
    90 }