author | bpatel |
Sat, 29 Mar 2014 11:06:33 -0700 | |
changeset 23799 | daa645653200 |
parent 19666 | 01a225608c25 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15354 | 2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javadoc; |
|
27 |
||
14802 | 28 |
import com.sun.source.util.TreePath; |
10 | 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; |
|
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
33 |
import com.sun.tools.javac.tree.JCTree; |
10 | 34 |
import com.sun.tools.javac.tree.JCTree.*; |
13077 | 35 |
import com.sun.tools.javac.util.Context; |
10 | 36 |
|
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
37 |
import static com.sun.tools.javac.code.Flags.*; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
38 |
|
10 | 39 |
/** |
40 |
* Javadoc's own memberEnter phase does a few things above and beyond that |
|
41 |
* done by javac. |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
42 |
* |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
43 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
44 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
45 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
46 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
13077
diff
changeset
|
47 |
* |
10 | 48 |
* @author Neal Gafter |
49 |
*/ |
|
10189
57268b86d4da
7059905: (javadoc) promote method visibility for netbeans usage
ksrini
parents:
8614
diff
changeset
|
50 |
public class JavadocMemberEnter extends MemberEnter { |
10 | 51 |
public static JavadocMemberEnter instance0(Context context) { |
52 |
MemberEnter instance = context.get(memberEnterKey); |
|
53 |
if (instance == null) |
|
54 |
instance = new JavadocMemberEnter(context); |
|
55 |
return (JavadocMemberEnter)instance; |
|
56 |
} |
|
57 |
||
8614 | 58 |
public static void preRegister(Context context) { |
10 | 59 |
context.put(memberEnterKey, new Context.Factory<MemberEnter>() { |
8614 | 60 |
public MemberEnter make(Context c) { |
61 |
return new JavadocMemberEnter(c); |
|
10 | 62 |
} |
63 |
}); |
|
64 |
} |
|
65 |
||
66 |
final DocEnv docenv; |
|
67 |
||
68 |
protected JavadocMemberEnter(Context context) { |
|
69 |
super(context); |
|
70 |
docenv = DocEnv.instance(context); |
|
71 |
} |
|
72 |
||
13077 | 73 |
@Override |
10 | 74 |
public void visitMethodDef(JCMethodDecl tree) { |
75 |
super.visitMethodDef(tree); |
|
868 | 76 |
MethodSymbol meth = tree.sym; |
10 | 77 |
if (meth == null || meth.kind != Kinds.MTH) return; |
15354 | 78 |
TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree); |
10 | 79 |
if (meth.isConstructor()) |
14802 | 80 |
docenv.makeConstructorDoc(meth, treePath); |
10 | 81 |
else if (isAnnotationTypeElement(meth)) |
14802 | 82 |
docenv.makeAnnotationTypeElementDoc(meth, treePath); |
10 | 83 |
else |
14802 | 84 |
docenv.makeMethodDoc(meth, treePath); |
14441
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
85 |
|
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
86 |
// release resources |
6c066a762e05
8002146: javadoc doesn't release resources in a timely manner
jjg
parents:
14260
diff
changeset
|
87 |
tree.body = null; |
10 | 88 |
} |
89 |
||
13077 | 90 |
@Override |
10 | 91 |
public void visitVarDef(JCVariableDecl tree) { |
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
92 |
if (tree.init != null) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
93 |
boolean isFinal = (tree.mods.flags & FINAL) != 0 |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
94 |
|| (env.enclClass.mods.flags & INTERFACE) != 0; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
95 |
if (!isFinal || containsNonConstantExpression(tree.init)) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
96 |
// Avoid unnecessary analysis and release resources. |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
97 |
// In particular, remove non-constant expressions |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
98 |
// which may trigger Attr.attribClass, since |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
99 |
// method bodies are also removed, in visitMethodDef. |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
100 |
tree.init = null; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
101 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
102 |
} |
10 | 103 |
super.visitVarDef(tree); |
104 |
if (tree.sym != null && |
|
105 |
tree.sym.kind == Kinds.VAR && |
|
106 |
!isParameter(tree.sym)) { |
|
15354 | 107 |
docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree)); |
10 | 108 |
} |
109 |
} |
|
110 |
||
111 |
private static boolean isAnnotationTypeElement(MethodSymbol meth) { |
|
112 |
return ClassDocImpl.isAnnotationType(meth.enclClass()); |
|
113 |
} |
|
114 |
||
115 |
private static boolean isParameter(VarSymbol var) { |
|
116 |
return (var.flags() & Flags.PARAMETER) != 0; |
|
117 |
} |
|
19666
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
118 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
119 |
/** |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
120 |
* Simple analysis of an expression tree to see if it contains tree nodes |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
121 |
* for any non-constant expression. This does not include checking references |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
122 |
* to other fields which may or may not be constant. |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
123 |
*/ |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
124 |
private static boolean containsNonConstantExpression(JCExpression tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
125 |
return new MaybeConstantExpressionScanner().containsNonConstantExpression(tree); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
126 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
127 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
128 |
/** |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
129 |
* See JLS 15.18, Constant Expression |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
130 |
*/ |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
131 |
private static class MaybeConstantExpressionScanner extends JCTree.Visitor { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
132 |
boolean maybeConstantExpr = true; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
133 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
134 |
public boolean containsNonConstantExpression(JCExpression tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
135 |
scan(tree); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
136 |
return !maybeConstantExpr; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
137 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
138 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
139 |
public void scan(JCTree tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
140 |
// short circuit scan when end result is definitely false |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
141 |
if (maybeConstantExpr && tree != null) |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
142 |
tree.accept(this); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
143 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
144 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
145 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
146 |
/** default for any non-overridden visit method. */ |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
147 |
public void visitTree(JCTree tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
148 |
maybeConstantExpr = false; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
149 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
150 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
151 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
152 |
public void visitBinary(JCBinary tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
153 |
switch (tree.getTag()) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
154 |
case MUL: case DIV: case MOD: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
155 |
case PLUS: case MINUS: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
156 |
case SL: case SR: case USR: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
157 |
case LT: case LE: case GT: case GE: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
158 |
case EQ: case NE: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
159 |
case BITAND: case BITXOR: case BITOR: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
160 |
case AND: case OR: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
161 |
break; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
162 |
default: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
163 |
maybeConstantExpr = false; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
164 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
165 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
166 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
167 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
168 |
public void visitConditional(JCConditional tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
169 |
scan(tree.cond); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
170 |
scan(tree.truepart); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
171 |
scan(tree.falsepart); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
172 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
173 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
174 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
175 |
public void visitIdent(JCIdent tree) { } |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
176 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
177 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
178 |
public void visitLiteral(JCLiteral tree) { } |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
179 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
180 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
181 |
public void visitParens(JCParens tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
182 |
scan(tree.expr); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
183 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
184 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
185 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
186 |
public void visitSelect(JCTree.JCFieldAccess tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
187 |
scan(tree.selected); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
188 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
189 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
190 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
191 |
public void visitTypeCast(JCTypeCast tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
192 |
scan(tree.clazz); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
193 |
scan(tree.expr); |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
194 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
195 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
196 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
197 |
public void visitTypeIdent(JCPrimitiveTypeTree tree) { } |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
198 |
|
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
199 |
@Override |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
200 |
public void visitUnary(JCUnary tree) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
201 |
switch (tree.getTag()) { |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
202 |
case POS: case NEG: case COMPL: case NOT: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
203 |
break; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
204 |
default: |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
205 |
maybeConstantExpr = false; |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
206 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
207 |
} |
01a225608c25
8010310: [javadoc] Error processing sources with -private
jjg
parents:
15354
diff
changeset
|
208 |
} |
10 | 209 |
} |