src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java

changeset 1
9a66ca7c79fa
child 74
5a9172b251dd
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * 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) return;
68 String docComment = env.toplevel.docComments.get(tree);
69 Position.LineMap lineMap = env.toplevel.lineMap;
70 if (meth.isConstructor())
71 docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
72 else if (isAnnotationTypeElement(meth))
73 docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap);
74 else
75 docenv.makeMethodDoc(meth, docComment, tree, lineMap);
76 }
77
78 public void visitVarDef(JCVariableDecl tree) {
79 super.visitVarDef(tree);
80 if (tree.sym != null &&
81 tree.sym.kind == Kinds.VAR &&
82 !isParameter(tree.sym)) {
83 String docComment = env.toplevel.docComments.get(tree);
84 Position.LineMap lineMap = env.toplevel.lineMap;
85 docenv.makeFieldDoc((VarSymbol)tree.sym, docComment, tree, lineMap);
86 }
87 }
88
89 private static boolean isAnnotationTypeElement(MethodSymbol meth) {
90 return ClassDocImpl.isAnnotationType(meth.enclClass());
91 }
92
93 private static boolean isParameter(VarSymbol var) {
94 return (var.flags() & Flags.PARAMETER) != 0;
95 }
96 }

mercurial