Path: blob/master/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocEnter.java
41161 views
/*1* Copyright (c) 2001, 2019, 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 jdk.javadoc.internal.tool;2627import javax.tools.JavaFileObject;2829import com.sun.source.util.TreePath;30import com.sun.tools.javac.code.Symbol.*;31import com.sun.tools.javac.comp.Enter;32import com.sun.tools.javac.tree.JCTree.*;33import com.sun.tools.javac.util.Context;34import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;35import com.sun.tools.javac.util.List;3637import static com.sun.tools.javac.code.Kinds.Kind.*;38import com.sun.tools.javac.main.JavaCompiler;3940/**41* Javadoc's own enter phase does a few things above and beyond that42* done by javac.43*44* <p><b>This is NOT part of any supported API.45* If you write code that depends on this, you do so at your own risk.46* This code and its internal interfaces are subject to change or47* deletion without notice.</b>48*/49public class JavadocEnter extends Enter {50public static JavadocEnter instance(Context context) {51Enter instance = context.get(enterKey);52if (instance == null)53instance = new JavadocEnter(context);54return (JavadocEnter)instance;55}5657public static void preRegister(Context context) {58context.put(enterKey, (Context.Factory<Enter>)JavadocEnter::new);59}6061protected JavadocEnter(Context context) {62super(context);63messager = Messager.instance0(context);64toolEnv = ToolEnvironment.instance(context);65compiler = JavaCompiler.instance(context);66}6768final Messager messager;69final ToolEnvironment toolEnv;70final JavaCompiler compiler;7172@Override73public void main(List<JCCompilationUnit> trees) {74// cache the error count if we need to convert Enter errors as warnings.75int nerrors = messager.nerrors;76super.main(trees);77compiler.enterDone();78if (toolEnv.ignoreSourceErrors) {79messager.nwarnings += (messager.nerrors - nerrors);80messager.nerrors = nerrors;81}82}8384@Override85public void visitTopLevel(JCCompilationUnit tree) {86super.visitTopLevel(tree);87if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {88JCPackageDecl pd = tree.getPackage();89TreePath tp = pd == null ? toolEnv.getTreePath(tree) : toolEnv.getTreePath(tree, pd);90toolEnv.setElementToTreePath(tree.packge, tp);91}92}9394@Override95public void visitClassDef(JCClassDecl tree) {96super.visitClassDef(tree);97if (tree.sym == null) return;98if (tree.sym.kind == TYP || tree.sym.kind == ERR) {99ClassSymbol c = tree.sym;100toolEnv.setElementToTreePath(c, toolEnv.getTreePath(env.toplevel, tree));101c.classfile = env.toplevel.sourcefile;102}103}104105/** Don't complain about a duplicate class. */106@Override107protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {}108109}110111112