langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocClassFinder.java
changeset 37938 42baa89d2156
parent 25874 83c19f00452c
child 38617 d93a7f64e231
equal deleted inserted replaced
37858:7c04fcb12bd4 37938:42baa89d2156
       
     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.main;
       
    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.code.ClassFinder;
       
    33 import com.sun.tools.javac.util.Context;
       
    34 
       
    35 /** Javadoc uses an extended class finder 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 JavadocClassFinder extends ClassFinder {
       
    45 
       
    46     public static JavadocClassFinder instance(Context context) {
       
    47         ClassFinder instance = context.get(classFinderKey);
       
    48         if (instance == null)
       
    49             instance = new JavadocClassFinder(context);
       
    50         return (JavadocClassFinder)instance;
       
    51     }
       
    52 
       
    53     public static void preRegister(Context context) {
       
    54         context.put(classFinderKey, new Context.Factory<ClassFinder>() {
       
    55             public ClassFinder make(Context c) {
       
    56                 return new JavadocClassFinder(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 JavadocClassFinder(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 }