01: /*
02: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.tools.javadoc;
27:
28: import com.sun.tools.javac.util.Context;
29: import com.sun.tools.javac.util.Position;
30: import com.sun.tools.javac.code.Flags;
31: import com.sun.tools.javac.code.Kinds;
32: import com.sun.tools.javac.code.Symbol.*;
33: import com.sun.tools.javac.comp.MemberEnter;
34: import com.sun.tools.javac.tree.JCTree.*;
35:
36: /**
37: * Javadoc's own memberEnter phase does a few things above and beyond that
38: * done by javac.
39: * @author Neal Gafter
40: */
41: class JavadocMemberEnter extends MemberEnter {
42: public static JavadocMemberEnter instance0(Context context) {
43: MemberEnter instance = context.get(memberEnterKey);
44: if (instance == null)
45: instance = new JavadocMemberEnter(context);
46: return (JavadocMemberEnter) instance;
47: }
48:
49: public static void preRegister(final Context context) {
50: context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
51: public MemberEnter make() {
52: return new JavadocMemberEnter(context);
53: }
54: });
55: }
56:
57: final DocEnv docenv;
58:
59: protected JavadocMemberEnter(Context context) {
60: super (context);
61: docenv = DocEnv.instance(context);
62: }
63:
64: public void visitMethodDef(JCMethodDecl tree) {
65: super .visitMethodDef(tree);
66: MethodSymbol meth = (MethodSymbol) tree.sym;
67: if (meth == null || meth.kind != Kinds.MTH)
68: return;
69: String docComment = env.toplevel.docComments.get(tree);
70: Position.LineMap lineMap = env.toplevel.lineMap;
71: if (meth.isConstructor())
72: docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
73: else if (isAnnotationTypeElement(meth))
74: docenv.makeAnnotationTypeElementDoc(meth, docComment, tree,
75: lineMap);
76: else
77: docenv.makeMethodDoc(meth, docComment, tree, lineMap);
78: }
79:
80: public void visitVarDef(JCVariableDecl tree) {
81: super .visitVarDef(tree);
82: if (tree.sym != null && tree.sym.kind == Kinds.VAR
83: && !isParameter(tree.sym)) {
84: String docComment = env.toplevel.docComments.get(tree);
85: Position.LineMap lineMap = env.toplevel.lineMap;
86: docenv.makeFieldDoc((VarSymbol) tree.sym, docComment, tree,
87: lineMap);
88: }
89: }
90:
91: private static boolean isAnnotationTypeElement(MethodSymbol meth) {
92: return ClassDocImpl.isAnnotationType(meth.enclClass());
93: }
94:
95: private static boolean isParameter(VarSymbol var) {
96: return (var.flags() & Flags.PARAMETER) != 0;
97: }
98: }
|