1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,105 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.javadoc; 1.30 + 1.31 +import javax.tools.JavaFileObject; 1.32 + 1.33 +import com.sun.tools.javac.code.Kinds; 1.34 +import com.sun.tools.javac.code.Symbol.*; 1.35 +import com.sun.tools.javac.comp.Enter; 1.36 +import com.sun.tools.javac.tree.JCTree.*; 1.37 +import com.sun.tools.javac.util.Context; 1.38 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 1.39 +import com.sun.tools.javac.util.List; 1.40 + 1.41 +/** 1.42 + * Javadoc's own enter phase does a few things above and beyond that 1.43 + * done by javac. 1.44 + * 1.45 + * <p><b>This is NOT part of any supported API. 1.46 + * If you write code that depends on this, you do so at your own risk. 1.47 + * This code and its internal interfaces are subject to change or 1.48 + * deletion without notice.</b> 1.49 + * 1.50 + * @author Neal Gafter 1.51 + */ 1.52 +public class JavadocEnter extends Enter { 1.53 + public static JavadocEnter instance0(Context context) { 1.54 + Enter instance = context.get(enterKey); 1.55 + if (instance == null) 1.56 + instance = new JavadocEnter(context); 1.57 + return (JavadocEnter)instance; 1.58 + } 1.59 + 1.60 + public static void preRegister(Context context) { 1.61 + context.put(enterKey, new Context.Factory<Enter>() { 1.62 + public Enter make(Context c) { 1.63 + return new JavadocEnter(c); 1.64 + } 1.65 + }); 1.66 + } 1.67 + 1.68 + protected JavadocEnter(Context context) { 1.69 + super(context); 1.70 + messager = Messager.instance0(context); 1.71 + docenv = DocEnv.instance(context); 1.72 + } 1.73 + 1.74 + final Messager messager; 1.75 + final DocEnv docenv; 1.76 + 1.77 + @Override 1.78 + public void main(List<JCCompilationUnit> trees) { 1.79 + // count all Enter errors as warnings. 1.80 + int nerrors = messager.nerrors; 1.81 + super.main(trees); 1.82 + messager.nwarnings += (messager.nerrors - nerrors); 1.83 + messager.nerrors = nerrors; 1.84 + } 1.85 + 1.86 + @Override 1.87 + public void visitTopLevel(JCCompilationUnit tree) { 1.88 + super.visitTopLevel(tree); 1.89 + if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { 1.90 + docenv.makePackageDoc(tree.packge, docenv.getTreePath(tree)); 1.91 + } 1.92 + } 1.93 + 1.94 + @Override 1.95 + public void visitClassDef(JCClassDecl tree) { 1.96 + super.visitClassDef(tree); 1.97 + if (tree.sym == null) return; 1.98 + if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) { 1.99 + ClassSymbol c = tree.sym; 1.100 + docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree)); 1.101 + } 1.102 + } 1.103 + 1.104 + /** Don't complain about a duplicate class. */ 1.105 + @Override 1.106 + protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {} 1.107 + 1.108 +}