001: /*
002: * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javadoc;
027:
028: import com.sun.tools.javac.util.Context;
029: import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
030: import com.sun.tools.javac.util.List;
031: import com.sun.tools.javac.code.Kinds;
032: import com.sun.tools.javac.code.Symbol.*;
033: import com.sun.tools.javac.comp.Enter;
034: import com.sun.tools.javac.tree.JCTree;
035: import com.sun.tools.javac.tree.JCTree.*;
036: import javax.tools.JavaFileObject;
037:
038: /**
039: * Javadoc's own enter phase does a few things above and beyond that
040: * done by javac.
041: * @author Neal Gafter
042: */
043: public class JavadocEnter extends Enter {
044: public static JavadocEnter instance0(Context context) {
045: Enter instance = context.get(enterKey);
046: if (instance == null)
047: instance = new JavadocEnter(context);
048: return (JavadocEnter) instance;
049: }
050:
051: public static void preRegister(final Context context) {
052: context.put(enterKey, new Context.Factory<Enter>() {
053: public Enter make() {
054: return new JavadocEnter(context);
055: }
056: });
057: }
058:
059: protected JavadocEnter(Context context) {
060: super (context);
061: messager = Messager.instance0(context);
062: docenv = DocEnv.instance(context);
063: }
064:
065: final Messager messager;
066: final DocEnv docenv;
067:
068: public void main(List<JCCompilationUnit> trees) {
069: // count all Enter errors as warnings.
070: int nerrors = messager.nerrors;
071: super .main(trees);
072: messager.nwarnings += (messager.nerrors - nerrors);
073: messager.nerrors = nerrors;
074: }
075:
076: public void visitTopLevel(JCCompilationUnit tree) {
077: super .visitTopLevel(tree);
078: if (tree.sourcefile.isNameCompatible("package-info",
079: JavaFileObject.Kind.SOURCE)) {
080: String comment = tree.docComments.get(tree);
081: docenv.makePackageDoc(tree.packge, comment, tree);
082: }
083: }
084:
085: public void visitClassDef(JCClassDecl tree) {
086: super .visitClassDef(tree);
087: if (tree.sym != null && tree.sym.kind == Kinds.TYP) {
088: if (tree.sym == null)
089: return;
090: String comment = env.toplevel.docComments.get(tree);
091: ClassSymbol c = (ClassSymbol) tree.sym;
092: docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap);
093: }
094: }
095:
096: /** Don't complain about a duplicate class. */
097: protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {
098: }
099:
100: }
|