Thu, 18 Apr 2013 20:00:14 -0700
8012656: cache frequently used name strings for DocImpl classes
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javadoc;
28 import com.sun.source.util.TreePath;
29 import com.sun.tools.javac.code.Flags;
30 import com.sun.tools.javac.code.Kinds;
31 import com.sun.tools.javac.code.Symbol.*;
32 import com.sun.tools.javac.comp.MemberEnter;
33 import com.sun.tools.javac.tree.JCTree.*;
34 import com.sun.tools.javac.util.Context;
36 /**
37 * Javadoc's own memberEnter phase does a few things above and beyond that
38 * done by javac.
39 *
40 * <p><b>This is NOT part of any supported API.
41 * If you write code that depends on this, you do so at your own risk.
42 * This code and its internal interfaces are subject to change or
43 * deletion without notice.</b>
44 *
45 * @author Neal Gafter
46 */
47 public class JavadocMemberEnter extends MemberEnter {
48 public static JavadocMemberEnter instance0(Context context) {
49 MemberEnter instance = context.get(memberEnterKey);
50 if (instance == null)
51 instance = new JavadocMemberEnter(context);
52 return (JavadocMemberEnter)instance;
53 }
55 public static void preRegister(Context context) {
56 context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
57 public MemberEnter make(Context c) {
58 return new JavadocMemberEnter(c);
59 }
60 });
61 }
63 final DocEnv docenv;
65 protected JavadocMemberEnter(Context context) {
66 super(context);
67 docenv = DocEnv.instance(context);
68 }
70 @Override
71 public void visitMethodDef(JCMethodDecl tree) {
72 super.visitMethodDef(tree);
73 MethodSymbol meth = tree.sym;
74 if (meth == null || meth.kind != Kinds.MTH) return;
75 TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree);
76 if (meth.isConstructor())
77 docenv.makeConstructorDoc(meth, treePath);
78 else if (isAnnotationTypeElement(meth))
79 docenv.makeAnnotationTypeElementDoc(meth, treePath);
80 else
81 docenv.makeMethodDoc(meth, treePath);
83 // release resources
84 tree.body = null;
85 }
87 @Override
88 public void visitVarDef(JCVariableDecl tree) {
89 super.visitVarDef(tree);
90 if (tree.sym != null &&
91 tree.sym.kind == Kinds.VAR &&
92 !isParameter(tree.sym)) {
93 docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree));
94 }
95 }
97 private static boolean isAnnotationTypeElement(MethodSymbol meth) {
98 return ClassDocImpl.isAnnotationType(meth.enclClass());
99 }
101 private static boolean isParameter(VarSymbol var) {
102 return (var.flags() & Flags.PARAMETER) != 0;
103 }
104 }