Thu, 04 Oct 2012 13:04:53 +0100
7177387: Add target-typing support in method context
Summary: Add support for deferred types and speculative attribution
Reviewed-by: jjg, dlsmith
1 /*
2 * Copyright (c) 2003, 2012, 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.tools.javac.code.Flags;
29 import com.sun.tools.javac.code.Kinds;
30 import com.sun.tools.javac.code.Symbol.*;
31 import com.sun.tools.javac.comp.MemberEnter;
32 import com.sun.tools.javac.tree.JCTree.*;
33 import com.sun.tools.javac.tree.TreeInfo;
34 import com.sun.tools.javac.util.Context;
35 import com.sun.tools.javac.util.Position;
37 /**
38 * Javadoc's own memberEnter phase does a few things above and beyond that
39 * done by javac.
40 * @author Neal Gafter
41 */
42 public class JavadocMemberEnter extends MemberEnter {
43 public static JavadocMemberEnter instance0(Context context) {
44 MemberEnter instance = context.get(memberEnterKey);
45 if (instance == null)
46 instance = new JavadocMemberEnter(context);
47 return (JavadocMemberEnter)instance;
48 }
50 public static void preRegister(Context context) {
51 context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
52 public MemberEnter make(Context c) {
53 return new JavadocMemberEnter(c);
54 }
55 });
56 }
58 final DocEnv docenv;
60 protected JavadocMemberEnter(Context context) {
61 super(context);
62 docenv = DocEnv.instance(context);
63 }
65 @Override
66 public void visitMethodDef(JCMethodDecl tree) {
67 super.visitMethodDef(tree);
68 MethodSymbol meth = tree.sym;
69 if (meth == null || meth.kind != Kinds.MTH) return;
70 String docComment = TreeInfo.getCommentText(env, tree);
71 Position.LineMap lineMap = env.toplevel.lineMap;
72 if (meth.isConstructor())
73 docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
74 else if (isAnnotationTypeElement(meth))
75 docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap);
76 else
77 docenv.makeMethodDoc(meth, docComment, tree, lineMap);
78 }
80 @Override
81 public void visitVarDef(JCVariableDecl tree) {
82 super.visitVarDef(tree);
83 if (tree.sym != null &&
84 tree.sym.kind == Kinds.VAR &&
85 !isParameter(tree.sym)) {
86 String docComment = TreeInfo.getCommentText(env, tree);
87 Position.LineMap lineMap = env.toplevel.lineMap;
88 docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
89 }
90 }
92 private static boolean isAnnotationTypeElement(MethodSymbol meth) {
93 return ClassDocImpl.isAnnotationType(meth.enclClass());
94 }
96 private static boolean isParameter(VarSymbol var) {
97 return (var.flags() & Flags.PARAMETER) != 0;
98 }
99 }