Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/tools/javadoc/JavadocClassReader.java
38899 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.javadoc;2627import java.util.EnumSet;28import javax.tools.JavaFileObject;2930import com.sun.tools.javac.code.Symbol.PackageSymbol;31import com.sun.tools.javac.jvm.ClassReader;32import com.sun.tools.javac.util.Context;3334/** Javadoc uses an extended class reader that records package.html entries35*36* <p><b>This is NOT part of any supported API.37* If you write code that depends on this, you do so at your own risk.38* This code and its internal interfaces are subject to change or39* deletion without notice.</b>40*41* @author Neal Gafter42*/43public class JavadocClassReader extends ClassReader {4445public static JavadocClassReader instance0(Context context) {46ClassReader instance = context.get(classReaderKey);47if (instance == null)48instance = new JavadocClassReader(context);49return (JavadocClassReader)instance;50}5152public static void preRegister(Context context) {53context.put(classReaderKey, new Context.Factory<ClassReader>() {54public ClassReader make(Context c) {55return new JavadocClassReader(c);56}57});58}5960private DocEnv docenv;61private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,62JavaFileObject.Kind.SOURCE,63JavaFileObject.Kind.HTML);64private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS,65JavaFileObject.Kind.HTML);6667public JavadocClassReader(Context context) {68super(context, true);69docenv = DocEnv.instance(context);70preferSource = true;71}7273/**74* Override getPackageFileKinds to include search for package.html75*/76@Override77protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {78return docenv.docClasses ? noSource : all;79}8081/**82* Override extraFileActions to check for package documentation83*/84@Override85protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {86if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))87docenv.getPackageDoc(pack).setDocPath(fo);88}89}909192