author | jjg |
Mon, 19 Nov 2012 11:38:49 -0800 | |
changeset 14548 | aa687b312c97 |
parent 14541 | 36f9d11fc9aa |
child 14952 | d0022ae20516 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
12016 | 2 |
* Copyright (c) 2005, 2012, 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.javac.api; |
|
27 |
||
28 |
import java.io.IOException; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
29 |
import java.util.HashSet; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
30 |
import java.util.Set; |
12016 | 31 |
|
10 | 32 |
import javax.annotation.processing.ProcessingEnvironment; |
33 |
import javax.lang.model.element.AnnotationMirror; |
|
34 |
import javax.lang.model.element.AnnotationValue; |
|
35 |
import javax.lang.model.element.Element; |
|
36 |
import javax.lang.model.element.ExecutableElement; |
|
37 |
import javax.lang.model.element.TypeElement; |
|
38 |
import javax.lang.model.type.DeclaredType; |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
39 |
import javax.lang.model.type.TypeKind; |
10 | 40 |
import javax.lang.model.type.TypeMirror; |
3149 | 41 |
import javax.tools.Diagnostic; |
10 | 42 |
import javax.tools.JavaCompiler; |
43 |
import javax.tools.JavaFileObject; |
|
44 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
45 |
import com.sun.source.doctree.DocCommentTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
46 |
import com.sun.source.doctree.ReferenceTree; |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
47 |
import com.sun.source.tree.CatchTree; |
10 | 48 |
import com.sun.source.tree.CompilationUnitTree; |
49 |
import com.sun.source.tree.Scope; |
|
50 |
import com.sun.source.tree.Tree; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
51 |
import com.sun.source.util.DocTrees; |
12016 | 52 |
import com.sun.source.util.JavacTask; |
10 | 53 |
import com.sun.source.util.SourcePositions; |
54 |
import com.sun.source.util.TreePath; |
|
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
55 |
import com.sun.tools.javac.code.Flags; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
56 |
import com.sun.tools.javac.code.Kinds; |
12016 | 57 |
import com.sun.tools.javac.code.Symbol; |
10 | 58 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
59 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
60 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
10 | 61 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
62 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
63 |
import com.sun.tools.javac.code.Type; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
64 |
import com.sun.tools.javac.code.Type.ArrayType; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
65 |
import com.sun.tools.javac.code.Type.ClassType; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
66 |
import com.sun.tools.javac.code.Type.ErrorType; |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
67 |
import com.sun.tools.javac.code.Type.UnionClassType; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
68 |
import com.sun.tools.javac.code.Types; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
69 |
import com.sun.tools.javac.code.Types.TypeRelation; |
10 | 70 |
import com.sun.tools.javac.comp.Attr; |
71 |
import com.sun.tools.javac.comp.AttrContext; |
|
72 |
import com.sun.tools.javac.comp.Enter; |
|
73 |
import com.sun.tools.javac.comp.Env; |
|
74 |
import com.sun.tools.javac.comp.MemberEnter; |
|
75 |
import com.sun.tools.javac.comp.Resolve; |
|
76 |
import com.sun.tools.javac.model.JavacElements; |
|
14258 | 77 |
import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
78 |
import com.sun.tools.javac.tree.DCTree; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
79 |
import com.sun.tools.javac.tree.DCTree.DCDocComment; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
80 |
import com.sun.tools.javac.tree.DCTree.DCReference; |
13077 | 81 |
import com.sun.tools.javac.tree.EndPosTable; |
12016 | 82 |
import com.sun.tools.javac.tree.JCTree; |
10 | 83 |
import com.sun.tools.javac.tree.JCTree.*; |
84 |
import com.sun.tools.javac.tree.TreeCopier; |
|
85 |
import com.sun.tools.javac.tree.TreeInfo; |
|
86 |
import com.sun.tools.javac.tree.TreeMaker; |
|
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
87 |
import com.sun.tools.javac.util.Assert; |
10 | 88 |
import com.sun.tools.javac.util.Context; |
3149 | 89 |
import com.sun.tools.javac.util.JCDiagnostic; |
10 | 90 |
import com.sun.tools.javac.util.List; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
91 |
import com.sun.tools.javac.util.ListBuffer; |
10 | 92 |
import com.sun.tools.javac.util.Log; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
93 |
import com.sun.tools.javac.util.Name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
94 |
import com.sun.tools.javac.util.Names; |
10 | 95 |
import com.sun.tools.javac.util.Pair; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
96 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 97 |
|
98 |
/** |
|
99 |
* Provides an implementation of Trees. |
|
100 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
101 |
* <p><b>This is NOT part of any supported API. |
10 | 102 |
* If you write code that depends on this, you do so at your own |
103 |
* risk. This code and its internal interfaces are subject to change |
|
104 |
* or deletion without notice.</b></p> |
|
105 |
* |
|
106 |
* @author Peter von der Ahé |
|
107 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
108 |
public class JavacTrees extends DocTrees { |
10 | 109 |
|
6717 | 110 |
// in a world of a single context per compilation, these would all be final |
111 |
private Resolve resolve; |
|
112 |
private Enter enter; |
|
113 |
private Log log; |
|
114 |
private MemberEnter memberEnter; |
|
115 |
private Attr attr; |
|
116 |
private TreeMaker treeMaker; |
|
117 |
private JavacElements elements; |
|
118 |
private JavacTaskImpl javacTaskImpl; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
119 |
private Names names; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
120 |
private Types types; |
10 | 121 |
|
12016 | 122 |
// called reflectively from Trees.instance(CompilationTask task) |
10 | 123 |
public static JavacTrees instance(JavaCompiler.CompilationTask task) { |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14541
diff
changeset
|
124 |
if (!(task instanceof BasicJavacTask)) |
10 | 125 |
throw new IllegalArgumentException(); |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14541
diff
changeset
|
126 |
return instance(((BasicJavacTask)task).getContext()); |
10 | 127 |
} |
128 |
||
12016 | 129 |
// called reflectively from Trees.instance(ProcessingEnvironment env) |
10 | 130 |
public static JavacTrees instance(ProcessingEnvironment env) { |
131 |
if (!(env instanceof JavacProcessingEnvironment)) |
|
132 |
throw new IllegalArgumentException(); |
|
133 |
return instance(((JavacProcessingEnvironment)env).getContext()); |
|
134 |
} |
|
135 |
||
136 |
public static JavacTrees instance(Context context) { |
|
137 |
JavacTrees instance = context.get(JavacTrees.class); |
|
138 |
if (instance == null) |
|
139 |
instance = new JavacTrees(context); |
|
140 |
return instance; |
|
141 |
} |
|
142 |
||
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
143 |
protected JavacTrees(Context context) { |
10 | 144 |
context.put(JavacTrees.class, this); |
6717 | 145 |
init(context); |
146 |
} |
|
147 |
||
148 |
public void updateContext(Context context) { |
|
149 |
init(context); |
|
150 |
} |
|
151 |
||
152 |
private void init(Context context) { |
|
10 | 153 |
attr = Attr.instance(context); |
154 |
enter = Enter.instance(context); |
|
155 |
elements = JavacElements.instance(context); |
|
156 |
log = Log.instance(context); |
|
157 |
resolve = Resolve.instance(context); |
|
158 |
treeMaker = TreeMaker.instance(context); |
|
159 |
memberEnter = MemberEnter.instance(context); |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
160 |
names = Names.instance(context); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
161 |
types = Types.instance(context); |
12016 | 162 |
|
163 |
JavacTask t = context.get(JavacTask.class); |
|
164 |
if (t instanceof JavacTaskImpl) |
|
165 |
javacTaskImpl = (JavacTaskImpl) t; |
|
10 | 166 |
} |
167 |
||
168 |
public SourcePositions getSourcePositions() { |
|
169 |
return new SourcePositions() { |
|
170 |
public long getStartPosition(CompilationUnitTree file, Tree tree) { |
|
171 |
return TreeInfo.getStartPos((JCTree) tree); |
|
172 |
} |
|
173 |
||
174 |
public long getEndPosition(CompilationUnitTree file, Tree tree) { |
|
11055 | 175 |
EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions; |
176 |
return TreeInfo.getEndPos((JCTree) tree, endPosTable); |
|
10 | 177 |
} |
178 |
}; |
|
179 |
} |
|
180 |
||
181 |
public JCClassDecl getTree(TypeElement element) { |
|
182 |
return (JCClassDecl) getTree((Element) element); |
|
183 |
} |
|
184 |
||
185 |
public JCMethodDecl getTree(ExecutableElement method) { |
|
186 |
return (JCMethodDecl) getTree((Element) method); |
|
187 |
} |
|
188 |
||
189 |
public JCTree getTree(Element element) { |
|
190 |
Symbol symbol = (Symbol) element; |
|
191 |
TypeSymbol enclosing = symbol.enclClass(); |
|
192 |
Env<AttrContext> env = enter.getEnv(enclosing); |
|
193 |
if (env == null) |
|
194 |
return null; |
|
195 |
JCClassDecl classNode = env.enclClass; |
|
196 |
if (classNode != null) { |
|
197 |
if (TreeInfo.symbolFor(classNode) == element) |
|
198 |
return classNode; |
|
199 |
for (JCTree node : classNode.getMembers()) |
|
200 |
if (TreeInfo.symbolFor(node) == element) |
|
201 |
return node; |
|
202 |
} |
|
203 |
return null; |
|
204 |
} |
|
205 |
||
206 |
public JCTree getTree(Element e, AnnotationMirror a) { |
|
207 |
return getTree(e, a, null); |
|
208 |
} |
|
209 |
||
210 |
public JCTree getTree(Element e, AnnotationMirror a, AnnotationValue v) { |
|
211 |
Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v); |
|
212 |
if (treeTopLevel == null) |
|
213 |
return null; |
|
214 |
return treeTopLevel.fst; |
|
215 |
} |
|
216 |
||
217 |
public TreePath getPath(CompilationUnitTree unit, Tree node) { |
|
218 |
return TreePath.getPath(unit, node); |
|
219 |
} |
|
220 |
||
221 |
public TreePath getPath(Element e) { |
|
222 |
return getPath(e, null, null); |
|
223 |
} |
|
224 |
||
225 |
public TreePath getPath(Element e, AnnotationMirror a) { |
|
226 |
return getPath(e, a, null); |
|
227 |
} |
|
228 |
||
229 |
public TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v) { |
|
230 |
final Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v); |
|
231 |
if (treeTopLevel == null) |
|
232 |
return null; |
|
233 |
return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst); |
|
234 |
} |
|
235 |
||
236 |
public Element getElement(TreePath path) { |
|
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
237 |
JCTree tree = (JCTree) path.getLeaf(); |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
238 |
Symbol sym = TreeInfo.symbolFor(tree); |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
239 |
if (sym == null && TreeInfo.isDeclaration(tree)) { |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
240 |
for (TreePath p = path; p != null; p = p.getParentPath()) { |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
241 |
JCTree t = (JCTree) p.getLeaf(); |
10950 | 242 |
if (t.hasTag(JCTree.Tag.CLASSDEF)) { |
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
243 |
JCClassDecl ct = (JCClassDecl) t; |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
244 |
if (ct.sym != null) { |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
245 |
if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
246 |
attr.attribClass(ct.pos(), ct.sym); |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
247 |
sym = TreeInfo.symbolFor(tree); |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
248 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
249 |
break; |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
250 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
251 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
252 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
253 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
254 |
return sym; |
10 | 255 |
} |
256 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
257 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
258 |
public Element getElement(TreePath path, ReferenceTree reference) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
259 |
if (!(reference instanceof DCReference)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
260 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
261 |
DCReference ref = (DCReference) reference; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
262 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
263 |
Env<AttrContext> env = getAttrContext(path); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
264 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
265 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler = |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
266 |
new Log.DeferredDiagnosticHandler(log); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
267 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
268 |
final ClassSymbol tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
269 |
final Name memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
270 |
if (ref.qualifierExpression == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
271 |
tsym = env.enclClass.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
272 |
memberName = ref.memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
273 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
274 |
// See if the qualifierExpression is a type or package name. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
275 |
// javac does not provide the exact method required, so |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
276 |
// we first check if qualifierExpression identifies a type, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
277 |
// and if not, then we check to see if it identifies a package. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
278 |
Type t = attr.attribType(ref.qualifierExpression, env); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
279 |
if (t.isErroneous()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
280 |
if (ref.memberName == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
281 |
// Attr/Resolve assume packages exist and create symbols as needed |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
282 |
// so use getPackageElement to restrict search to existing packages |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
283 |
PackageSymbol pck = elements.getPackageElement(ref.qualifierExpression.toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
284 |
if (pck != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
285 |
return pck; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
286 |
} else if (ref.qualifierExpression.hasTag(JCTree.Tag.IDENT)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
287 |
// fixup: allow "identifier" instead of "#identifier" |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
288 |
// for compatibility with javadoc |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
289 |
tsym = env.enclClass.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
290 |
memberName = ((JCIdent) ref.qualifierExpression).name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
291 |
} else |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
292 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
293 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
294 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
295 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
296 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
297 |
tsym = (ClassSymbol) t.tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
298 |
memberName = ref.memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
299 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
300 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
301 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
302 |
if (memberName == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
303 |
return tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
304 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
305 |
final List<Type> paramTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
306 |
if (ref.paramTypes == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
307 |
paramTypes = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
308 |
else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
309 |
ListBuffer<Type> lb = new ListBuffer<Type>(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
310 |
for (List<JCTree> l = ref.paramTypes; l.nonEmpty(); l = l.tail) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
311 |
JCTree tree = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
312 |
Type t = attr.attribType(tree, env); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
313 |
lb.add(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
314 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
315 |
paramTypes = lb.toList(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
316 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
317 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
318 |
Symbol msym = (memberName == tsym.name) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
319 |
? findConstructor(tsym, paramTypes) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
320 |
: findMethod(tsym, memberName, paramTypes); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
321 |
if (paramTypes != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
322 |
// explicit (possibly empty) arg list given, so cannot be a field |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
323 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
324 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
325 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
326 |
VarSymbol vsym = (ref.paramTypes != null) ? null : findField(tsym, memberName); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
327 |
// prefer a field over a method with no parameters |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
328 |
if (vsym != null && |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
329 |
(msym == null || |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
330 |
types.isSubtypeUnchecked(vsym.enclClass().asType(), msym.enclClass().asType()))) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
331 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
332 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
333 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
334 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
335 |
} finally { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
336 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
337 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
338 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
339 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
340 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findField */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
341 |
private VarSymbol findField(ClassSymbol tsym, Name fieldName) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
342 |
return searchField(tsym, fieldName, new HashSet<ClassSymbol>()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
343 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
344 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
345 |
/** @see com.sun.tools.javadoc.ClassDocImpl#searchField */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
346 |
private VarSymbol searchField(ClassSymbol tsym, Name fieldName, Set<ClassSymbol> searched) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
347 |
if (searched.contains(tsym)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
348 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
349 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
350 |
searched.add(tsym); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
351 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
352 |
for (com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(fieldName); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
353 |
e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
354 |
if (e.sym.kind == Kinds.VAR) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
355 |
return (VarSymbol)e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
356 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
357 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
358 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
359 |
//### If we found a VarSymbol above, but which did not pass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
360 |
//### the modifier filter, we should return failure here! |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
361 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
362 |
ClassSymbol encl = tsym.owner.enclClass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
363 |
if (encl != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
364 |
VarSymbol vsym = searchField(encl, fieldName, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
365 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
366 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
367 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
368 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
369 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
370 |
// search superclass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
371 |
Type superclass = tsym.getSuperclass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
372 |
if (superclass.tsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
373 |
VarSymbol vsym = searchField((ClassSymbol) superclass.tsym, fieldName, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
374 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
375 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
376 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
377 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
378 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
379 |
// search interfaces |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
380 |
List<Type> intfs = tsym.getInterfaces(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
381 |
for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
382 |
Type intf = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
383 |
if (intf.isErroneous()) continue; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
384 |
VarSymbol vsym = searchField((ClassSymbol) intf.tsym, fieldName, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
385 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
386 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
387 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
388 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
389 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
390 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
391 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
392 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
393 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findConstructor */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
394 |
MethodSymbol findConstructor(ClassSymbol tsym, List<Type> paramTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
395 |
for (com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(names.init); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
396 |
e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
397 |
if (e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
398 |
if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
399 |
return (MethodSymbol) e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
400 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
401 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
402 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
403 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
404 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
405 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
406 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findMethod */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
407 |
private MethodSymbol findMethod(ClassSymbol tsym, Name methodName, List<Type> paramTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
408 |
return searchMethod(tsym, methodName, paramTypes, new HashSet<ClassSymbol>()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
409 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
410 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
411 |
/** @see com.sun.tools.javadoc.ClassDocImpl#searchMethod */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
412 |
private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
413 |
List<Type> paramTypes, Set<ClassSymbol> searched) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
414 |
//### Note that this search is not necessarily what the compiler would do! |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
415 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
416 |
// do not match constructors |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
417 |
if (methodName == names.init) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
418 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
419 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
420 |
if (searched.contains(tsym)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
421 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
422 |
searched.add(tsym); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
423 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
424 |
// search current class |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
425 |
com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(methodName); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
426 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
427 |
//### Using modifier filter here isn't really correct, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
428 |
//### but emulates the old behavior. Instead, we should |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
429 |
//### apply the normal rules of visibility and inheritance. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
430 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
431 |
if (paramTypes == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
432 |
// If no parameters specified, we are allowed to return |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
433 |
// any method with a matching name. In practice, the old |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
434 |
// code returned the first method, which is now the last! |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
435 |
// In order to provide textually identical results, we |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
436 |
// attempt to emulate the old behavior. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
437 |
MethodSymbol lastFound = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
438 |
for (; e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
439 |
if (e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
440 |
if (e.sym.name == methodName) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
441 |
lastFound = (MethodSymbol)e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
442 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
443 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
444 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
445 |
if (lastFound != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
446 |
return lastFound; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
447 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
448 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
449 |
for (; e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
450 |
if (e.sym != null && |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
451 |
e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
452 |
if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
453 |
return (MethodSymbol) e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
454 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
455 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
456 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
457 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
458 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
459 |
//### If we found a MethodSymbol above, but which did not pass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
460 |
//### the modifier filter, we should return failure here! |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
461 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
462 |
// search superclass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
463 |
Type superclass = tsym.getSuperclass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
464 |
if (superclass.tsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
465 |
MethodSymbol msym = searchMethod((ClassSymbol) superclass.tsym, methodName, paramTypes, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
466 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
467 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
468 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
469 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
470 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
471 |
// search interfaces |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
472 |
List<Type> intfs = tsym.getInterfaces(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
473 |
for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
474 |
Type intf = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
475 |
if (intf.isErroneous()) continue; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
476 |
MethodSymbol msym = searchMethod((ClassSymbol) intf.tsym, methodName, paramTypes, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
477 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
478 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
479 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
480 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
481 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
482 |
// search enclosing class |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
483 |
ClassSymbol encl = tsym.owner.enclClass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
484 |
if (encl != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
485 |
MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
486 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
487 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
488 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
489 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
490 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
491 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
492 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
493 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
494 |
/** @see com.sun.tools.javadoc.ClassDocImpl */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
495 |
private boolean hasParameterTypes(MethodSymbol method, List<Type> paramTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
496 |
if (paramTypes == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
497 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
498 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
499 |
if (method.params().size() != paramTypes.size()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
500 |
return false; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
501 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
502 |
List<Type> methodParamTypes = types.erasureRecursive(method.asType()).getParameterTypes(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
503 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
504 |
return (Type.isErroneous(paramTypes)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
505 |
? fuzzyMatch(paramTypes, methodParamTypes) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
506 |
: types.isSameTypes(paramTypes, methodParamTypes); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
507 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
508 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
509 |
boolean fuzzyMatch(List<Type> paramTypes, List<Type> methodParamTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
510 |
List<Type> l1 = paramTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
511 |
List<Type> l2 = methodParamTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
512 |
while (l1.nonEmpty()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
513 |
if (!fuzzyMatch(l1.head, l2.head)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
514 |
return false; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
515 |
l1 = l1.tail; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
516 |
l2 = l2.tail; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
517 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
518 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
519 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
520 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
521 |
boolean fuzzyMatch(Type paramType, Type methodParamType) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
522 |
Boolean b = fuzzyMatcher.visit(paramType, methodParamType); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
523 |
return (b == Boolean.TRUE); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
524 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
525 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
526 |
TypeRelation fuzzyMatcher = new TypeRelation() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
527 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
528 |
public Boolean visitType(Type t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
529 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
530 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
531 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
532 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
533 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
534 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
535 |
switch (t.getTag()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
536 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
537 |
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
538 |
return t.getTag() == s.getTag(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
539 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
540 |
default: |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
541 |
throw new AssertionError("fuzzyMatcher " + t.getTag()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
542 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
543 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
544 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
545 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
546 |
public Boolean visitArrayType(ArrayType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
547 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
548 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
549 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
550 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
551 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
552 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
553 |
return s.getTag() == ARRAY |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
554 |
&& visit(t.elemtype, types.elemtype(s)); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
555 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
556 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
557 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
558 |
public Boolean visitClassType(ClassType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
559 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
560 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
561 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
562 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
563 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
564 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
565 |
return t.tsym == s.tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
566 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
567 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
568 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
569 |
public Boolean visitErrorType(ErrorType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
570 |
return s.getTag() == CLASS |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
571 |
&& t.tsym.name == ((ClassType) s).tsym.name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
572 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
573 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
574 |
|
10 | 575 |
public TypeMirror getTypeMirror(TreePath path) { |
576 |
Tree t = path.getLeaf(); |
|
577 |
return ((JCTree)t).type; |
|
578 |
} |
|
579 |
||
580 |
public JavacScope getScope(TreePath path) { |
|
581 |
return new JavacScope(getAttrContext(path)); |
|
582 |
} |
|
583 |
||
7631 | 584 |
public String getDocComment(TreePath path) { |
585 |
CompilationUnitTree t = path.getCompilationUnit(); |
|
13077 | 586 |
Tree leaf = path.getLeaf(); |
587 |
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { |
|
7631 | 588 |
JCCompilationUnit cu = (JCCompilationUnit) t; |
589 |
if (cu.docComments != null) { |
|
13077 | 590 |
return cu.docComments.getCommentText((JCTree) leaf); |
7631 | 591 |
} |
592 |
} |
|
593 |
return null; |
|
594 |
} |
|
595 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
596 |
public DocCommentTree getDocCommentTree(TreePath path) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
597 |
CompilationUnitTree t = path.getCompilationUnit(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
598 |
Tree leaf = path.getLeaf(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
599 |
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
600 |
JCCompilationUnit cu = (JCCompilationUnit) t; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
601 |
if (cu.docComments != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
602 |
return cu.docComments.getCommentTree((JCTree) leaf); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
603 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
604 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
605 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
606 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
607 |
|
10 | 608 |
public boolean isAccessible(Scope scope, TypeElement type) { |
609 |
if (scope instanceof JavacScope && type instanceof ClassSymbol) { |
|
610 |
Env<AttrContext> env = ((JavacScope) scope).env; |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
7077
diff
changeset
|
611 |
return resolve.isAccessible(env, (ClassSymbol)type, true); |
10 | 612 |
} else |
613 |
return false; |
|
614 |
} |
|
615 |
||
616 |
public boolean isAccessible(Scope scope, Element member, DeclaredType type) { |
|
617 |
if (scope instanceof JavacScope |
|
618 |
&& member instanceof Symbol |
|
619 |
&& type instanceof com.sun.tools.javac.code.Type) { |
|
620 |
Env<AttrContext> env = ((JavacScope) scope).env; |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
7077
diff
changeset
|
621 |
return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true); |
10 | 622 |
} else |
623 |
return false; |
|
624 |
} |
|
625 |
||
626 |
private Env<AttrContext> getAttrContext(TreePath path) { |
|
627 |
if (!(path.getLeaf() instanceof JCTree)) // implicit null-check |
|
628 |
throw new IllegalArgumentException(); |
|
629 |
||
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
630 |
// if we're being invoked from a Tree API client via parse/enter/analyze, |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
631 |
// we need to make sure all the classes have been entered; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
632 |
// if we're being invoked from JSR 199 or JSR 269, then the classes |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
633 |
// will already have been entered. |
10 | 634 |
if (javacTaskImpl != null) { |
635 |
try { |
|
636 |
javacTaskImpl.enter(null); |
|
637 |
} catch (IOException e) { |
|
638 |
throw new Error("unexpected error while entering symbols: " + e); |
|
639 |
} |
|
640 |
} |
|
641 |
||
642 |
||
643 |
JCCompilationUnit unit = (JCCompilationUnit) path.getCompilationUnit(); |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
644 |
Copier copier = createCopier(treeMaker.forToplevel(unit)); |
10 | 645 |
|
646 |
Env<AttrContext> env = null; |
|
647 |
JCMethodDecl method = null; |
|
648 |
JCVariableDecl field = null; |
|
649 |
||
650 |
List<Tree> l = List.nil(); |
|
651 |
TreePath p = path; |
|
652 |
while (p != null) { |
|
653 |
l = l.prepend(p.getLeaf()); |
|
654 |
p = p.getParentPath(); |
|
655 |
} |
|
656 |
||
657 |
for ( ; l.nonEmpty(); l = l.tail) { |
|
658 |
Tree tree = l.head; |
|
659 |
switch (tree.getKind()) { |
|
660 |
case COMPILATION_UNIT: |
|
661 |
// System.err.println("COMP: " + ((JCCompilationUnit)tree).sourcefile); |
|
662 |
env = enter.getTopLevelEnv((JCCompilationUnit)tree); |
|
663 |
break; |
|
7077
55689b828dc5
6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents:
6717
diff
changeset
|
664 |
case ANNOTATION_TYPE: |
10 | 665 |
case CLASS: |
7077
55689b828dc5
6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents:
6717
diff
changeset
|
666 |
case ENUM: |
6600 | 667 |
case INTERFACE: |
10 | 668 |
// System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); |
669 |
env = enter.getClassEnv(((JCClassDecl)tree).sym); |
|
670 |
break; |
|
671 |
case METHOD: |
|
672 |
// System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); |
|
673 |
method = (JCMethodDecl)tree; |
|
674 |
break; |
|
675 |
case VARIABLE: |
|
676 |
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); |
|
677 |
field = (JCVariableDecl)tree; |
|
678 |
break; |
|
679 |
case BLOCK: { |
|
680 |
// System.err.println("BLOCK: "); |
|
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
681 |
if (method != null) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
682 |
try { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
683 |
Assert.check(method.body == tree); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
684 |
method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
685 |
env = memberEnter.getMethodEnv(method, env); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
686 |
env = attribStatToTree(method.body, env, copier.leafCopy); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
687 |
} finally { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
688 |
method.body = (JCBlock) tree; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
689 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
690 |
} else { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
691 |
JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
692 |
env = attribStatToTree(body, env, copier.leafCopy); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
693 |
} |
10 | 694 |
return env; |
695 |
} |
|
696 |
default: |
|
697 |
// System.err.println("DEFAULT: " + tree.getKind()); |
|
698 |
if (field != null && field.getInitializer() == tree) { |
|
699 |
env = memberEnter.getInitEnv(field, env); |
|
700 |
JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); |
|
701 |
env = attribExprToTree(expr, env, copier.leafCopy); |
|
702 |
return env; |
|
703 |
} |
|
704 |
} |
|
705 |
} |
|
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
706 |
return (field != null) ? memberEnter.getInitEnv(field, env) : env; |
10 | 707 |
} |
708 |
||
709 |
private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) { |
|
710 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
711 |
try { |
|
712 |
return attr.attribStatToTree(stat, env, tree); |
|
713 |
} finally { |
|
714 |
log.useSource(prev); |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
private Env<AttrContext> attribExprToTree(JCExpression expr, Env<AttrContext>env, JCTree tree) { |
|
719 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
720 |
try { |
|
721 |
return attr.attribExprToTree(expr, env, tree); |
|
722 |
} finally { |
|
723 |
log.useSource(prev); |
|
724 |
} |
|
725 |
} |
|
726 |
||
727 |
/** |
|
728 |
* Makes a copy of a tree, noting the value resulting from copying a particular leaf. |
|
729 |
**/ |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
730 |
protected static class Copier extends TreeCopier<JCTree> { |
10 | 731 |
JCTree leafCopy = null; |
732 |
||
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
733 |
protected Copier(TreeMaker M) { |
10 | 734 |
super(M); |
735 |
} |
|
736 |
||
6717 | 737 |
@Override |
10 | 738 |
public <T extends JCTree> T copy(T t, JCTree leaf) { |
739 |
T t2 = super.copy(t, leaf); |
|
740 |
if (t == leaf) |
|
741 |
leafCopy = t2; |
|
742 |
return t2; |
|
743 |
} |
|
744 |
} |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
745 |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
746 |
protected Copier createCopier(TreeMaker maker) { |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
747 |
return new Copier(maker); |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
748 |
} |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
749 |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
750 |
/** |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
751 |
* Gets the original type from the ErrorType object. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
752 |
* @param errorType The errorType for which we want to get the original type. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
753 |
* @returns TypeMirror corresponding to the original type, replaced by the ErrorType. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
754 |
* noType (type.tag == NONE) is returned if there is no original type. |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
755 |
*/ |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
756 |
public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
757 |
if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
758 |
return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType(); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
759 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
760 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
761 |
return com.sun.tools.javac.code.Type.noType; |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
762 |
} |
3149 | 763 |
|
764 |
/** |
|
765 |
* Prints a message of the specified kind at the location of the |
|
766 |
* tree within the provided compilation unit |
|
767 |
* |
|
768 |
* @param kind the kind of message |
|
769 |
* @param msg the message, or an empty string if none |
|
770 |
* @param t the tree to use as a position hint |
|
771 |
* @param root the compilation unit that contains tree |
|
772 |
*/ |
|
773 |
public void printMessage(Diagnostic.Kind kind, CharSequence msg, |
|
774 |
com.sun.source.tree.Tree t, |
|
775 |
com.sun.source.tree.CompilationUnitTree root) { |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
776 |
printMessage(kind, msg, ((JCTree) t).pos(), root); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
777 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
778 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
779 |
public void printMessage(Diagnostic.Kind kind, CharSequence msg, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
780 |
com.sun.source.doctree.DocTree t, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
781 |
com.sun.source.doctree.DocCommentTree c, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
782 |
com.sun.source.tree.CompilationUnitTree root) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
783 |
printMessage(kind, msg, ((DCTree) t).pos((DCDocComment) c), root); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
784 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
785 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
786 |
private void printMessage(Diagnostic.Kind kind, CharSequence msg, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
787 |
JCDiagnostic.DiagnosticPosition pos, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
788 |
com.sun.source.tree.CompilationUnitTree root) { |
3149 | 789 |
JavaFileObject oldSource = null; |
790 |
JavaFileObject newSource = null; |
|
791 |
||
792 |
newSource = root.getSourceFile(); |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
793 |
if (newSource == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
794 |
pos = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
795 |
} else { |
3149 | 796 |
oldSource = log.useSource(newSource); |
797 |
} |
|
798 |
||
799 |
try { |
|
800 |
switch (kind) { |
|
801 |
case ERROR: |
|
802 |
boolean prev = log.multipleErrors; |
|
803 |
try { |
|
804 |
log.error(pos, "proc.messager", msg.toString()); |
|
805 |
} finally { |
|
806 |
log.multipleErrors = prev; |
|
807 |
} |
|
808 |
break; |
|
809 |
||
810 |
case WARNING: |
|
811 |
log.warning(pos, "proc.messager", msg.toString()); |
|
812 |
break; |
|
813 |
||
814 |
case MANDATORY_WARNING: |
|
815 |
log.mandatoryWarning(pos, "proc.messager", msg.toString()); |
|
816 |
break; |
|
817 |
||
818 |
default: |
|
819 |
log.note(pos, "proc.messager", msg.toString()); |
|
820 |
} |
|
821 |
} finally { |
|
822 |
if (oldSource != null) |
|
823 |
log.useSource(oldSource); |
|
824 |
} |
|
825 |
} |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
826 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
827 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
828 |
public TypeMirror getLub(CatchTree tree) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
829 |
JCCatch ct = (JCCatch) tree; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
830 |
JCVariableDecl v = ct.param; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
831 |
if (v.type != null && v.type.getKind() == TypeKind.UNION) { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
832 |
UnionClassType ut = (UnionClassType) v.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
833 |
return ut.getLub(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
834 |
} else { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
835 |
return v.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
836 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
837 |
} |
10 | 838 |
} |