JavadocClassFinder.java revision 3255:7a0c34355149
150477Speter/* 22729Sdfr * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. 32729Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42729Sdfr * 52729Sdfr * This code is free software; you can redistribute it and/or modify it 62729Sdfr * under the terms of the GNU General Public License version 2 only, as 72729Sdfr * published by the Free Software Foundation. Oracle designates this 82729Sdfr * particular file as subject to the "Classpath" exception as provided 92729Sdfr * by Oracle in the LICENSE file that accompanied this code. 102729Sdfr * 112729Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 122729Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 132729Sdfr * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 142729Sdfr * version 2 for more details (a copy is included in the LICENSE file that 15163506Sjhb * accompanied this code). 16163506Sjhb * 17163506Sjhb * You should have received a copy of the GNU General Public License version 18163506Sjhb * 2 along with this work; if not, write to the Free Software Foundation, 19163506Sjhb * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20163506Sjhb * 21163506Sjhb * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22163506Sjhb * or visit www.oracle.com if you need additional information or have any 23163506Sjhb * questions. 24163506Sjhb */ 25163506Sjhb 26163506Sjhbpackage jdk.javadoc.internal.tool; 27163506Sjhb 28163506Sjhbimport java.util.EnumSet; 29163506Sjhb 30194910Sjhbimport javax.tools.JavaFileObject; 31194910Sjhb 32194910Sjhbimport com.sun.tools.javac.api.JavacTrees; 33194910Sjhbimport com.sun.tools.javac.code.Symbol.PackageSymbol; 34115708Sschweikhimport com.sun.tools.javac.code.ClassFinder; 35115708Sschweikhimport com.sun.tools.javac.util.Context; 36115708Sschweikh 37115708Sschweikh/** Javadoc uses an extended class finder that records package.html entries 38115708Sschweikh * 39115708Sschweikh * <p><b>This is NOT part of any supported API. 40115708Sschweikh * If you write code that depends on this, you do so at your own risk. 41115708Sschweikh * This code and its internal interfaces are subject to change or 42115708Sschweikh * deletion without notice.</b> 432729Sdfr * 44194910Sjhb * @author Neal Gafter 452729Sdfr */ 46194910Sjhbpublic class JavadocClassFinder extends ClassFinder { 47194910Sjhb 48194910Sjhb public static JavadocClassFinder instance(Context context) { 49194910Sjhb ClassFinder instance = context.get(classFinderKey); 50194910Sjhb if (instance == null) 51194910Sjhb instance = new JavadocClassFinder(context); 52194910Sjhb return (JavadocClassFinder)instance; 53194910Sjhb } 54194910Sjhb 55194910Sjhb public static void preRegister(Context context) { 562729Sdfr context.put(classFinderKey, new Context.Factory<ClassFinder>() { 572729Sdfr public ClassFinder make(Context c) { 582729Sdfr return new JavadocClassFinder(c); 592729Sdfr } 60115708Sschweikh }); 61115708Sschweikh } 62115708Sschweikh 632729Sdfr private DocEnv docenv; 642729Sdfr private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS, 652729Sdfr JavaFileObject.Kind.SOURCE, 66194910Sjhb JavaFileObject.Kind.HTML); 67194910Sjhb private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS, 68194910Sjhb JavaFileObject.Kind.HTML); 69194910Sjhb 70194910Sjhb private final JavacTrees trees; 71194910Sjhb 72194910Sjhb public JavadocClassFinder(Context context) { 73194910Sjhb super(context); 74194910Sjhb docenv = DocEnv.instance(context); 75194910Sjhb preferSource = true; 762729Sdfr trees = JavacTrees.instance(context); 772729Sdfr } 782729Sdfr 792729Sdfr /** 80115708Sschweikh * Override getPackageFileKinds to include search for package.html 81115708Sschweikh */ 82115708Sschweikh @Override 832729Sdfr protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() { 842729Sdfr return docenv.docClasses ? noSource : all; 852729Sdfr } 862729Sdfr 872729Sdfr /** 882729Sdfr * Override extraFileActions to check for package documentation 892729Sdfr */ 902729Sdfr @Override 912729Sdfr protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) { 922729Sdfr if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML)) { 932729Sdfr docenv.pkgToJavaFOMap.put(pack, fo); 942729Sdfr trees.putJavaFileObject(pack, fo); 9583414Smr } 96115708Sschweikh } 972729Sdfr} 989444Sjoerg