Fri, 30 Nov 2012 15:14:48 +0000
8002099: Add support for intersection types in cast expression
Summary: Add parser and type-checking support for intersection types in cast expressions
Reviewed-by: jjg
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 *
41 * <p><b>This is NOT part of any supported API.
42 * If you write code that depends on this, you do so at your own risk.
43 * This code and its internal interfaces are subject to change or
44 * deletion without notice.</b>
45 *
46 * @author Neal Gafter
47 */
48 public class JavadocMemberEnter extends MemberEnter {
49 public static JavadocMemberEnter instance0(Context context) {
50 MemberEnter instance = context.get(memberEnterKey);
51 if (instance == null)
52 instance = new JavadocMemberEnter(context);
53 return (JavadocMemberEnter)instance;
54 }
56 public static void preRegister(Context context) {
57 context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
58 public MemberEnter make(Context c) {
59 return new JavadocMemberEnter(c);
60 }
61 });
62 }
64 final DocEnv docenv;
66 protected JavadocMemberEnter(Context context) {
67 super(context);
68 docenv = DocEnv.instance(context);
69 }
71 @Override
72 public void visitMethodDef(JCMethodDecl tree) {
73 super.visitMethodDef(tree);
74 MethodSymbol meth = tree.sym;
75 if (meth == null || meth.kind != Kinds.MTH) return;
76 String docComment = TreeInfo.getCommentText(env, tree);
77 Position.LineMap lineMap = env.toplevel.lineMap;
78 if (meth.isConstructor())
79 docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
80 else if (isAnnotationTypeElement(meth))
81 docenv.makeAnnotationTypeElementDoc(meth, docComment, tree, lineMap);
82 else
83 docenv.makeMethodDoc(meth, docComment, tree, lineMap);
85 // release resources
86 tree.body = null;
87 }
89 @Override
90 public void visitVarDef(JCVariableDecl tree) {
91 super.visitVarDef(tree);
92 if (tree.sym != null &&
93 tree.sym.kind == Kinds.VAR &&
94 !isParameter(tree.sym)) {
95 String docComment = TreeInfo.getCommentText(env, tree);
96 Position.LineMap lineMap = env.toplevel.lineMap;
97 docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
98 }
99 }
101 private static boolean isAnnotationTypeElement(MethodSymbol meth) {
102 return ClassDocImpl.isAnnotationType(meth.enclClass());
103 }
105 private static boolean isParameter(VarSymbol var) {
106 return (var.flags() & Flags.PARAMETER) != 0;
107 }
108 }