author | jlahoda |
Mon, 06 May 2013 16:22:45 +0200 | |
changeset 17549 | 65ea6f3b72d9 |
parent 17273 | d7ec6654aac9 |
child 17557 | 9c6ace1881fe |
permissions | -rw-r--r-- |
10 | 1 |
/* |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
2 |
* Copyright (c) 2005, 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.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; |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
36 |
import javax.lang.model.element.ElementKind; |
10 | 37 |
import javax.lang.model.element.ExecutableElement; |
38 |
import javax.lang.model.element.TypeElement; |
|
39 |
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
|
40 |
import javax.lang.model.type.TypeKind; |
10 | 41 |
import javax.lang.model.type.TypeMirror; |
3149 | 42 |
import javax.tools.Diagnostic; |
10 | 43 |
import javax.tools.JavaCompiler; |
44 |
import javax.tools.JavaFileObject; |
|
45 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
46 |
import com.sun.source.doctree.DocCommentTree; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
47 |
import com.sun.source.doctree.DocTree; |
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
48 |
import com.sun.source.tree.CatchTree; |
10 | 49 |
import com.sun.source.tree.CompilationUnitTree; |
50 |
import com.sun.source.tree.Scope; |
|
51 |
import com.sun.source.tree.Tree; |
|
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
52 |
import com.sun.source.util.DocSourcePositions; |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
53 |
import com.sun.source.util.DocTreePath; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
54 |
import com.sun.source.util.DocTreeScanner; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
55 |
import com.sun.source.util.DocTrees; |
12016 | 56 |
import com.sun.source.util.JavacTask; |
10 | 57 |
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
|
58 |
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
|
59 |
import com.sun.tools.javac.code.Kinds; |
12016 | 60 |
import com.sun.tools.javac.code.Symbol; |
10 | 61 |
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
|
62 |
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
|
63 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
10 | 64 |
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
|
65 |
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
|
66 |
import com.sun.tools.javac.code.Type; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
import com.sun.tools.javac.code.Types; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
72 |
import com.sun.tools.javac.code.Types.TypeRelation; |
10 | 73 |
import com.sun.tools.javac.comp.Attr; |
74 |
import com.sun.tools.javac.comp.AttrContext; |
|
75 |
import com.sun.tools.javac.comp.Enter; |
|
76 |
import com.sun.tools.javac.comp.Env; |
|
77 |
import com.sun.tools.javac.comp.MemberEnter; |
|
78 |
import com.sun.tools.javac.comp.Resolve; |
|
79 |
import com.sun.tools.javac.model.JavacElements; |
|
14258 | 80 |
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
|
81 |
import com.sun.tools.javac.tree.DCTree; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
82 |
import com.sun.tools.javac.tree.DCTree.DCBlockTag; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
83 |
import com.sun.tools.javac.tree.DCTree.DCDocComment; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
84 |
import com.sun.tools.javac.tree.DCTree.DCEndPosTree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
85 |
import com.sun.tools.javac.tree.DCTree.DCErroneous; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
86 |
import com.sun.tools.javac.tree.DCTree.DCIdentifier; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
87 |
import com.sun.tools.javac.tree.DCTree.DCParam; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
88 |
import com.sun.tools.javac.tree.DCTree.DCReference; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
89 |
import com.sun.tools.javac.tree.DCTree.DCText; |
13077 | 90 |
import com.sun.tools.javac.tree.EndPosTable; |
12016 | 91 |
import com.sun.tools.javac.tree.JCTree; |
10 | 92 |
import com.sun.tools.javac.tree.JCTree.*; |
93 |
import com.sun.tools.javac.tree.TreeCopier; |
|
94 |
import com.sun.tools.javac.tree.TreeInfo; |
|
95 |
import com.sun.tools.javac.tree.TreeMaker; |
|
14952 | 96 |
import com.sun.tools.javac.util.Abort; |
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
97 |
import com.sun.tools.javac.util.Assert; |
10 | 98 |
import com.sun.tools.javac.util.Context; |
3149 | 99 |
import com.sun.tools.javac.util.JCDiagnostic; |
10 | 100 |
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
|
101 |
import com.sun.tools.javac.util.ListBuffer; |
10 | 102 |
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
|
103 |
import com.sun.tools.javac.util.Name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
104 |
import com.sun.tools.javac.util.Names; |
10 | 105 |
import com.sun.tools.javac.util.Pair; |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
106 |
import com.sun.tools.javac.util.Position; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
107 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 108 |
|
109 |
/** |
|
110 |
* Provides an implementation of Trees. |
|
111 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
112 |
* <p><b>This is NOT part of any supported API. |
10 | 113 |
* If you write code that depends on this, you do so at your own |
114 |
* risk. This code and its internal interfaces are subject to change |
|
115 |
* or deletion without notice.</b></p> |
|
116 |
* |
|
117 |
* @author Peter von der Ahé |
|
118 |
*/ |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
119 |
public class JavacTrees extends DocTrees { |
10 | 120 |
|
6717 | 121 |
// in a world of a single context per compilation, these would all be final |
122 |
private Resolve resolve; |
|
123 |
private Enter enter; |
|
124 |
private Log log; |
|
125 |
private MemberEnter memberEnter; |
|
126 |
private Attr attr; |
|
127 |
private TreeMaker treeMaker; |
|
128 |
private JavacElements elements; |
|
129 |
private JavacTaskImpl javacTaskImpl; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
130 |
private Names names; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
131 |
private Types types; |
10 | 132 |
|
12016 | 133 |
// called reflectively from Trees.instance(CompilationTask task) |
10 | 134 |
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
|
135 |
if (!(task instanceof BasicJavacTask)) |
10 | 136 |
throw new IllegalArgumentException(); |
14548
aa687b312c97
8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents:
14541
diff
changeset
|
137 |
return instance(((BasicJavacTask)task).getContext()); |
10 | 138 |
} |
139 |
||
12016 | 140 |
// called reflectively from Trees.instance(ProcessingEnvironment env) |
10 | 141 |
public static JavacTrees instance(ProcessingEnvironment env) { |
142 |
if (!(env instanceof JavacProcessingEnvironment)) |
|
143 |
throw new IllegalArgumentException(); |
|
144 |
return instance(((JavacProcessingEnvironment)env).getContext()); |
|
145 |
} |
|
146 |
||
147 |
public static JavacTrees instance(Context context) { |
|
148 |
JavacTrees instance = context.get(JavacTrees.class); |
|
149 |
if (instance == null) |
|
150 |
instance = new JavacTrees(context); |
|
151 |
return instance; |
|
152 |
} |
|
153 |
||
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
154 |
protected JavacTrees(Context context) { |
10 | 155 |
context.put(JavacTrees.class, this); |
6717 | 156 |
init(context); |
157 |
} |
|
158 |
||
159 |
public void updateContext(Context context) { |
|
160 |
init(context); |
|
161 |
} |
|
162 |
||
163 |
private void init(Context context) { |
|
10 | 164 |
attr = Attr.instance(context); |
165 |
enter = Enter.instance(context); |
|
166 |
elements = JavacElements.instance(context); |
|
167 |
log = Log.instance(context); |
|
168 |
resolve = Resolve.instance(context); |
|
169 |
treeMaker = TreeMaker.instance(context); |
|
170 |
memberEnter = MemberEnter.instance(context); |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
171 |
names = Names.instance(context); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
172 |
types = Types.instance(context); |
12016 | 173 |
|
174 |
JavacTask t = context.get(JavacTask.class); |
|
175 |
if (t instanceof JavacTaskImpl) |
|
176 |
javacTaskImpl = (JavacTaskImpl) t; |
|
10 | 177 |
} |
178 |
||
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
179 |
public DocSourcePositions getSourcePositions() { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
180 |
return new DocSourcePositions() { |
10 | 181 |
public long getStartPosition(CompilationUnitTree file, Tree tree) { |
182 |
return TreeInfo.getStartPos((JCTree) tree); |
|
183 |
} |
|
184 |
||
185 |
public long getEndPosition(CompilationUnitTree file, Tree tree) { |
|
11055 | 186 |
EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions; |
187 |
return TreeInfo.getEndPos((JCTree) tree, endPosTable); |
|
10 | 188 |
} |
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
189 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
190 |
public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
191 |
return ((DCTree) tree).getSourcePosition((DCDocComment) comment); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
192 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
193 |
@SuppressWarnings("fallthrough") |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
194 |
public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
195 |
DCDocComment dcComment = (DCDocComment) comment; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
196 |
if (tree instanceof DCEndPosTree) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
197 |
int endPos = ((DCEndPosTree) tree).getEndPos(dcComment); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
198 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
199 |
if (endPos != Position.NOPOS) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
200 |
return endPos; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
201 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
202 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
203 |
int correction = 0; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
204 |
switch (tree.getKind()) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
205 |
case TEXT: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
206 |
DCText text = (DCText) tree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
207 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
208 |
return dcComment.comment.getSourcePos(text.pos + text.text.length()); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
209 |
case ERRONEOUS: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
210 |
DCErroneous err = (DCErroneous) tree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
211 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
212 |
return dcComment.comment.getSourcePos(err.pos + err.body.length()); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
213 |
case IDENTIFIER: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
214 |
DCIdentifier ident = (DCIdentifier) tree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
215 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
216 |
return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0)); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
217 |
case PARAM: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
218 |
DCParam param = (DCParam) tree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
219 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
220 |
if (param.isTypeParameter && param.getDescription().isEmpty()) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
221 |
correction = 1; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
222 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
223 |
case AUTHOR: case DEPRECATED: case RETURN: case SEE: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
224 |
case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
225 |
case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
226 |
DocTree last = getLastChild(tree); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
227 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
228 |
if (last != null) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
229 |
return getEndPosition(file, comment, last) + correction; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
230 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
231 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
232 |
DCBlockTag block = (DCBlockTag) tree; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
233 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
234 |
return dcComment.comment.getSourcePos(block.pos + block.getTagName().length() + 1); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
235 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
236 |
default: |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
237 |
DocTree last = getLastChild(tree); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
238 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
239 |
if (last != null) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
240 |
return getEndPosition(file, comment, last); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
241 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
242 |
break; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
243 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
244 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
245 |
return Position.NOPOS; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
246 |
} |
10 | 247 |
}; |
248 |
} |
|
249 |
||
17273
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
250 |
private DocTree getLastChild(DocTree tree) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
251 |
final DocTree[] last = new DocTree[] {null}; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
252 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
253 |
tree.accept(new DocTreeScanner<Void, Void>() { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
254 |
@Override public Void scan(DocTree node, Void p) { |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
255 |
if (node != null) last[0] = node; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
256 |
return null; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
257 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
258 |
}, null); |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
259 |
|
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
260 |
return last[0]; |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
261 |
} |
d7ec6654aac9
8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents:
14952
diff
changeset
|
262 |
|
10 | 263 |
public JCClassDecl getTree(TypeElement element) { |
264 |
return (JCClassDecl) getTree((Element) element); |
|
265 |
} |
|
266 |
||
267 |
public JCMethodDecl getTree(ExecutableElement method) { |
|
268 |
return (JCMethodDecl) getTree((Element) method); |
|
269 |
} |
|
270 |
||
271 |
public JCTree getTree(Element element) { |
|
272 |
Symbol symbol = (Symbol) element; |
|
273 |
TypeSymbol enclosing = symbol.enclClass(); |
|
274 |
Env<AttrContext> env = enter.getEnv(enclosing); |
|
275 |
if (env == null) |
|
276 |
return null; |
|
277 |
JCClassDecl classNode = env.enclClass; |
|
278 |
if (classNode != null) { |
|
279 |
if (TreeInfo.symbolFor(classNode) == element) |
|
280 |
return classNode; |
|
281 |
for (JCTree node : classNode.getMembers()) |
|
282 |
if (TreeInfo.symbolFor(node) == element) |
|
283 |
return node; |
|
284 |
} |
|
285 |
return null; |
|
286 |
} |
|
287 |
||
288 |
public JCTree getTree(Element e, AnnotationMirror a) { |
|
289 |
return getTree(e, a, null); |
|
290 |
} |
|
291 |
||
292 |
public JCTree getTree(Element e, AnnotationMirror a, AnnotationValue v) { |
|
293 |
Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v); |
|
294 |
if (treeTopLevel == null) |
|
295 |
return null; |
|
296 |
return treeTopLevel.fst; |
|
297 |
} |
|
298 |
||
299 |
public TreePath getPath(CompilationUnitTree unit, Tree node) { |
|
300 |
return TreePath.getPath(unit, node); |
|
301 |
} |
|
302 |
||
303 |
public TreePath getPath(Element e) { |
|
304 |
return getPath(e, null, null); |
|
305 |
} |
|
306 |
||
307 |
public TreePath getPath(Element e, AnnotationMirror a) { |
|
308 |
return getPath(e, a, null); |
|
309 |
} |
|
310 |
||
311 |
public TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v) { |
|
312 |
final Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v); |
|
313 |
if (treeTopLevel == null) |
|
314 |
return null; |
|
315 |
return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst); |
|
316 |
} |
|
317 |
||
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
318 |
public Symbol 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
|
319 |
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
|
320 |
Symbol sym = TreeInfo.symbolFor(tree); |
14952 | 321 |
if (sym == null) { |
322 |
if (TreeInfo.isDeclaration(tree)) { |
|
323 |
for (TreePath p = path; p != null; p = p.getParentPath()) { |
|
324 |
JCTree t = (JCTree) p.getLeaf(); |
|
325 |
if (t.hasTag(JCTree.Tag.CLASSDEF)) { |
|
326 |
JCClassDecl ct = (JCClassDecl) t; |
|
327 |
if (ct.sym != null) { |
|
328 |
if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { |
|
329 |
attr.attribClass(ct.pos(), ct.sym); |
|
330 |
sym = TreeInfo.symbolFor(tree); |
|
331 |
} |
|
332 |
break; |
|
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
333 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
334 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
335 |
} |
14952 | 336 |
} else if (tree.hasTag(Tag.TOPLEVEL)) { |
337 |
JCCompilationUnit cu = (JCCompilationUnit) tree; |
|
338 |
if (cu.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { |
|
339 |
sym = cu.packge; |
|
340 |
} |
|
6590
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
341 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
342 |
} |
f745e683da2c
6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents:
5847
diff
changeset
|
343 |
return sym; |
10 | 344 |
} |
345 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
346 |
@Override |
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
347 |
public Element getElement(DocTreePath path) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
348 |
DocTree forTree = path.getLeaf(); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
349 |
if (forTree instanceof DCReference) |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
350 |
return attributeDocReference(path.getTreePath(), ((DCReference) forTree)); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
351 |
if (forTree instanceof DCIdentifier) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
352 |
if (path.getParentPath().getLeaf() instanceof DCParam) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
353 |
return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf()); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
354 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
355 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
356 |
return null; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
357 |
} |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
358 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
359 |
private Symbol attributeDocReference(TreePath path, DCReference ref) { |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
360 |
Env<AttrContext> env = getAttrContext(path); |
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 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler = |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
363 |
new Log.DeferredDiagnosticHandler(log); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
364 |
try { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
365 |
final ClassSymbol tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
366 |
final Name memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
367 |
if (ref.qualifierExpression == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
368 |
tsym = env.enclClass.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
369 |
memberName = ref.memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
370 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
371 |
// 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
|
372 |
// 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
|
373 |
// 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
|
374 |
// 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
|
375 |
Type t = attr.attribType(ref.qualifierExpression, env); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
376 |
if (t.isErroneous()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
377 |
if (ref.memberName == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
378 |
// 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
|
379 |
// 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
|
380 |
PackageSymbol pck = elements.getPackageElement(ref.qualifierExpression.toString()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
381 |
if (pck != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
382 |
return pck; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
383 |
} 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
|
384 |
// fixup: allow "identifier" instead of "#identifier" |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
385 |
// for compatibility with javadoc |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
386 |
tsym = env.enclClass.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
387 |
memberName = ((JCIdent) ref.qualifierExpression).name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
388 |
} else |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
389 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
390 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
391 |
return null; |
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 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
394 |
tsym = (ClassSymbol) t.tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
395 |
memberName = ref.memberName; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
396 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
397 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
398 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
399 |
if (memberName == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
400 |
return tsym; |
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 |
final List<Type> paramTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
403 |
if (ref.paramTypes == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
404 |
paramTypes = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
405 |
else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
406 |
ListBuffer<Type> lb = new ListBuffer<Type>(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
407 |
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
|
408 |
JCTree tree = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
409 |
Type t = attr.attribType(tree, env); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
410 |
lb.add(t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
411 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
412 |
paramTypes = lb.toList(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
413 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
414 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
415 |
Symbol msym = (memberName == tsym.name) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
416 |
? findConstructor(tsym, paramTypes) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
417 |
: findMethod(tsym, memberName, paramTypes); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
418 |
if (paramTypes != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
419 |
// 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
|
420 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
421 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
422 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
423 |
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
|
424 |
// 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
|
425 |
if (vsym != null && |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
426 |
(msym == null || |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
427 |
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
|
428 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
429 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
430 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
431 |
} |
14952 | 432 |
} catch (Abort e) { // may be thrown by Check.completionError in case of bad class file |
433 |
return null; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
434 |
} finally { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
435 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
436 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
437 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
438 |
|
17549
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
439 |
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
440 |
Symbol javadocSymbol = getElement(path); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
441 |
if (javadocSymbol == null) |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
442 |
return null; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
443 |
ElementKind kind = javadocSymbol.getKind(); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
444 |
List<? extends Symbol> params = List.nil(); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
445 |
if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
446 |
MethodSymbol ee = (MethodSymbol) javadocSymbol; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
447 |
params = ptag.isTypeParameter() |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
448 |
? ee.getTypeParameters() |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
449 |
: ee.getParameters(); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
450 |
} else if (kind.isClass() || kind.isInterface()) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
451 |
ClassSymbol te = (ClassSymbol) javadocSymbol; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
452 |
params = te.getTypeParameters(); |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
453 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
454 |
|
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
455 |
for (Symbol param : params) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
456 |
if (param.getSimpleName() == ptag.getName().getName()) { |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
457 |
return param; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
458 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
459 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
460 |
return null; |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
461 |
} |
65ea6f3b72d9
8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents:
17273
diff
changeset
|
462 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
463 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findField */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
464 |
private VarSymbol findField(ClassSymbol tsym, Name fieldName) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
465 |
return searchField(tsym, fieldName, new HashSet<ClassSymbol>()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
466 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
467 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
468 |
/** @see com.sun.tools.javadoc.ClassDocImpl#searchField */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
469 |
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
|
470 |
if (searched.contains(tsym)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
471 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
472 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
473 |
searched.add(tsym); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
474 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
475 |
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
|
476 |
e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
477 |
if (e.sym.kind == Kinds.VAR) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
478 |
return (VarSymbol)e.sym; |
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 |
//### 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
|
483 |
//### 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
|
484 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
485 |
ClassSymbol encl = tsym.owner.enclClass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
486 |
if (encl != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
487 |
VarSymbol vsym = searchField(encl, fieldName, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
488 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
489 |
return vsym; |
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 |
} |
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 |
// search superclass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
494 |
Type superclass = tsym.getSuperclass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
495 |
if (superclass.tsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
496 |
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
|
497 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
498 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
499 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
500 |
} |
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 |
// search interfaces |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
503 |
List<Type> intfs = tsym.getInterfaces(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
504 |
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
|
505 |
Type intf = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
506 |
if (intf.isErroneous()) continue; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
507 |
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
|
508 |
if (vsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
509 |
return vsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
510 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
511 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
512 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
513 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
514 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
515 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
516 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findConstructor */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
517 |
MethodSymbol findConstructor(ClassSymbol tsym, List<Type> paramTypes) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
518 |
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
|
519 |
e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
520 |
if (e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
521 |
if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
522 |
return (MethodSymbol) e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
523 |
} |
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 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
527 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
528 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
529 |
/** @see com.sun.tools.javadoc.ClassDocImpl#findMethod */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
530 |
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
|
531 |
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
|
532 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
533 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
534 |
/** @see com.sun.tools.javadoc.ClassDocImpl#searchMethod */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
535 |
private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
536 |
List<Type> paramTypes, Set<ClassSymbol> searched) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
537 |
//### 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
|
538 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
539 |
// do not match constructors |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
540 |
if (methodName == names.init) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
541 |
return null; |
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 |
if (searched.contains(tsym)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
544 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
545 |
searched.add(tsym); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
546 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
547 |
// search current class |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
548 |
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
|
549 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
550 |
//### 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
|
551 |
//### 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
|
552 |
//### 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
|
553 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
554 |
if (paramTypes == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
555 |
// 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
|
556 |
// 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
|
557 |
// 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
|
558 |
// 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
|
559 |
// attempt to emulate the old behavior. |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
560 |
MethodSymbol lastFound = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
561 |
for (; e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
562 |
if (e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
563 |
if (e.sym.name == methodName) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
564 |
lastFound = (MethodSymbol)e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
565 |
} |
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 |
if (lastFound != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
569 |
return lastFound; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
570 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
571 |
} else { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
572 |
for (; e.scope != null; e = e.next()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
573 |
if (e.sym != null && |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
574 |
e.sym.kind == Kinds.MTH) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
575 |
if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
576 |
return (MethodSymbol) e.sym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
577 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
578 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
579 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
580 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
581 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
582 |
//### 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
|
583 |
//### 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
|
584 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
585 |
// search superclass |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
586 |
Type superclass = tsym.getSuperclass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
587 |
if (superclass.tsym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
588 |
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
|
589 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
590 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
591 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
592 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
593 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
594 |
// search interfaces |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
595 |
List<Type> intfs = tsym.getInterfaces(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
596 |
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
|
597 |
Type intf = l.head; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
598 |
if (intf.isErroneous()) continue; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
599 |
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
|
600 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
601 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
602 |
} |
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 |
// search enclosing class |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
606 |
ClassSymbol encl = tsym.owner.enclClass(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
607 |
if (encl != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
608 |
MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
609 |
if (msym != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
610 |
return msym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
611 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
612 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
613 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
614 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
615 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
616 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
617 |
/** @see com.sun.tools.javadoc.ClassDocImpl */ |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
618 |
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
|
619 |
if (paramTypes == null) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
620 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
621 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
622 |
if (method.params().size() != paramTypes.size()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
623 |
return false; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
624 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
625 |
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
|
626 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
627 |
return (Type.isErroneous(paramTypes)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
628 |
? fuzzyMatch(paramTypes, methodParamTypes) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
629 |
: types.isSameTypes(paramTypes, methodParamTypes); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
630 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
631 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
632 |
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
|
633 |
List<Type> l1 = paramTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
634 |
List<Type> l2 = methodParamTypes; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
635 |
while (l1.nonEmpty()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
636 |
if (!fuzzyMatch(l1.head, l2.head)) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
637 |
return false; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
638 |
l1 = l1.tail; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
639 |
l2 = l2.tail; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
640 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
641 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
642 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
643 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
644 |
boolean fuzzyMatch(Type paramType, Type methodParamType) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
645 |
Boolean b = fuzzyMatcher.visit(paramType, methodParamType); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
646 |
return (b == Boolean.TRUE); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
647 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
648 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
649 |
TypeRelation fuzzyMatcher = new TypeRelation() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
650 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
651 |
public Boolean visitType(Type t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
652 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
653 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
654 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
655 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
656 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
657 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
658 |
switch (t.getTag()) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
659 |
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
|
660 |
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
|
661 |
return t.getTag() == s.getTag(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
662 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
663 |
default: |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
664 |
throw new AssertionError("fuzzyMatcher " + t.getTag()); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
665 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
666 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
667 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
668 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
669 |
public Boolean visitArrayType(ArrayType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
670 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
671 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
672 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
673 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
674 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
675 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
676 |
return s.getTag() == ARRAY |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
677 |
&& visit(t.elemtype, types.elemtype(s)); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
678 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
679 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
680 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
681 |
public Boolean visitClassType(ClassType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
682 |
if (t == s) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
683 |
return true; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
684 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
685 |
if (s.isPartial()) |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
686 |
return visit(s, t); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
687 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
688 |
return t.tsym == s.tsym; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
689 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
690 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
691 |
@Override |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
692 |
public Boolean visitErrorType(ErrorType t, Type s) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
693 |
return s.getTag() == CLASS |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
694 |
&& t.tsym.name == ((ClassType) s).tsym.name; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
695 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
696 |
}; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
697 |
|
10 | 698 |
public TypeMirror getTypeMirror(TreePath path) { |
699 |
Tree t = path.getLeaf(); |
|
700 |
return ((JCTree)t).type; |
|
701 |
} |
|
702 |
||
703 |
public JavacScope getScope(TreePath path) { |
|
704 |
return new JavacScope(getAttrContext(path)); |
|
705 |
} |
|
706 |
||
7631 | 707 |
public String getDocComment(TreePath path) { |
708 |
CompilationUnitTree t = path.getCompilationUnit(); |
|
13077 | 709 |
Tree leaf = path.getLeaf(); |
710 |
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { |
|
7631 | 711 |
JCCompilationUnit cu = (JCCompilationUnit) t; |
712 |
if (cu.docComments != null) { |
|
13077 | 713 |
return cu.docComments.getCommentText((JCTree) leaf); |
7631 | 714 |
} |
715 |
} |
|
716 |
return null; |
|
717 |
} |
|
718 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
719 |
public DocCommentTree getDocCommentTree(TreePath path) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
720 |
CompilationUnitTree t = path.getCompilationUnit(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
721 |
Tree leaf = path.getLeaf(); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
722 |
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
|
723 |
JCCompilationUnit cu = (JCCompilationUnit) t; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
724 |
if (cu.docComments != null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
725 |
return cu.docComments.getCommentTree((JCTree) leaf); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
726 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
727 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
728 |
return null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
729 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
730 |
|
10 | 731 |
public boolean isAccessible(Scope scope, TypeElement type) { |
732 |
if (scope instanceof JavacScope && type instanceof ClassSymbol) { |
|
733 |
Env<AttrContext> env = ((JavacScope) scope).env; |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
7077
diff
changeset
|
734 |
return resolve.isAccessible(env, (ClassSymbol)type, true); |
10 | 735 |
} else |
736 |
return false; |
|
737 |
} |
|
738 |
||
739 |
public boolean isAccessible(Scope scope, Element member, DeclaredType type) { |
|
740 |
if (scope instanceof JavacScope |
|
741 |
&& member instanceof Symbol |
|
742 |
&& type instanceof com.sun.tools.javac.code.Type) { |
|
743 |
Env<AttrContext> env = ((JavacScope) scope).env; |
|
7209
889e80aa1d2e
6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents:
7077
diff
changeset
|
744 |
return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true); |
10 | 745 |
} else |
746 |
return false; |
|
747 |
} |
|
748 |
||
749 |
private Env<AttrContext> getAttrContext(TreePath path) { |
|
750 |
if (!(path.getLeaf() instanceof JCTree)) // implicit null-check |
|
751 |
throw new IllegalArgumentException(); |
|
752 |
||
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
753 |
// 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
|
754 |
// 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
|
755 |
// 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
|
756 |
// will already have been entered. |
10 | 757 |
if (javacTaskImpl != null) { |
758 |
try { |
|
759 |
javacTaskImpl.enter(null); |
|
760 |
} catch (IOException e) { |
|
761 |
throw new Error("unexpected error while entering symbols: " + e); |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
||
766 |
JCCompilationUnit unit = (JCCompilationUnit) path.getCompilationUnit(); |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
767 |
Copier copier = createCopier(treeMaker.forToplevel(unit)); |
10 | 768 |
|
769 |
Env<AttrContext> env = null; |
|
770 |
JCMethodDecl method = null; |
|
771 |
JCVariableDecl field = null; |
|
772 |
||
773 |
List<Tree> l = List.nil(); |
|
774 |
TreePath p = path; |
|
775 |
while (p != null) { |
|
776 |
l = l.prepend(p.getLeaf()); |
|
777 |
p = p.getParentPath(); |
|
778 |
} |
|
779 |
||
780 |
for ( ; l.nonEmpty(); l = l.tail) { |
|
781 |
Tree tree = l.head; |
|
782 |
switch (tree.getKind()) { |
|
783 |
case COMPILATION_UNIT: |
|
784 |
// System.err.println("COMP: " + ((JCCompilationUnit)tree).sourcefile); |
|
785 |
env = enter.getTopLevelEnv((JCCompilationUnit)tree); |
|
786 |
break; |
|
7077
55689b828dc5
6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents:
6717
diff
changeset
|
787 |
case ANNOTATION_TYPE: |
10 | 788 |
case CLASS: |
7077
55689b828dc5
6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents:
6717
diff
changeset
|
789 |
case ENUM: |
6600 | 790 |
case INTERFACE: |
10 | 791 |
// System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); |
792 |
env = enter.getClassEnv(((JCClassDecl)tree).sym); |
|
793 |
break; |
|
794 |
case METHOD: |
|
795 |
// System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); |
|
796 |
method = (JCMethodDecl)tree; |
|
797 |
break; |
|
798 |
case VARIABLE: |
|
799 |
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName()); |
|
800 |
field = (JCVariableDecl)tree; |
|
801 |
break; |
|
802 |
case BLOCK: { |
|
803 |
// System.err.println("BLOCK: "); |
|
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
804 |
if (method != null) { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
805 |
try { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
806 |
Assert.check(method.body == tree); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
807 |
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
|
808 |
env = memberEnter.getMethodEnv(method, env); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
809 |
env = attribStatToTree(method.body, env, copier.leafCopy); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
810 |
} finally { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
811 |
method.body = (JCBlock) tree; |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
812 |
} |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
813 |
} else { |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
814 |
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
|
815 |
env = attribStatToTree(body, env, copier.leafCopy); |
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
816 |
} |
10 | 817 |
return env; |
818 |
} |
|
819 |
default: |
|
820 |
// System.err.println("DEFAULT: " + tree.getKind()); |
|
821 |
if (field != null && field.getInitializer() == tree) { |
|
822 |
env = memberEnter.getInitEnv(field, env); |
|
823 |
JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); |
|
824 |
env = attribExprToTree(expr, env, copier.leafCopy); |
|
825 |
return env; |
|
826 |
} |
|
827 |
} |
|
828 |
} |
|
10631
d9914010b902
7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents:
9599
diff
changeset
|
829 |
return (field != null) ? memberEnter.getInitEnv(field, env) : env; |
10 | 830 |
} |
831 |
||
832 |
private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) { |
|
833 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
834 |
try { |
|
835 |
return attr.attribStatToTree(stat, env, tree); |
|
836 |
} finally { |
|
837 |
log.useSource(prev); |
|
838 |
} |
|
839 |
} |
|
840 |
||
841 |
private Env<AttrContext> attribExprToTree(JCExpression expr, Env<AttrContext>env, JCTree tree) { |
|
842 |
JavaFileObject prev = log.useSource(env.toplevel.sourcefile); |
|
843 |
try { |
|
844 |
return attr.attribExprToTree(expr, env, tree); |
|
845 |
} finally { |
|
846 |
log.useSource(prev); |
|
847 |
} |
|
848 |
} |
|
849 |
||
850 |
/** |
|
851 |
* Makes a copy of a tree, noting the value resulting from copying a particular leaf. |
|
852 |
**/ |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
853 |
protected static class Copier extends TreeCopier<JCTree> { |
10 | 854 |
JCTree leafCopy = null; |
855 |
||
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
856 |
protected Copier(TreeMaker M) { |
10 | 857 |
super(M); |
858 |
} |
|
859 |
||
6717 | 860 |
@Override |
10 | 861 |
public <T extends JCTree> T copy(T t, JCTree leaf) { |
862 |
T t2 = super.copy(t, leaf); |
|
863 |
if (t == leaf) |
|
864 |
leafCopy = t2; |
|
865 |
return t2; |
|
866 |
} |
|
867 |
} |
|
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
|
868 |
|
13845
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
869 |
protected Copier createCopier(TreeMaker maker) { |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
870 |
return new Copier(maker); |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
871 |
} |
bbb35ad7a9c1
7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents:
13077
diff
changeset
|
872 |
|
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
|
873 |
/** |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
874 |
* 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
|
875 |
* @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
|
876 |
* @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
|
877 |
* 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
|
878 |
*/ |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
879 |
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
|
880 |
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
|
881 |
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
|
882 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
883 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
10
diff
changeset
|
884 |
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
|
885 |
} |
3149 | 886 |
|
887 |
/** |
|
888 |
* Prints a message of the specified kind at the location of the |
|
889 |
* tree within the provided compilation unit |
|
890 |
* |
|
891 |
* @param kind the kind of message |
|
892 |
* @param msg the message, or an empty string if none |
|
893 |
* @param t the tree to use as a position hint |
|
894 |
* @param root the compilation unit that contains tree |
|
895 |
*/ |
|
896 |
public void printMessage(Diagnostic.Kind kind, CharSequence msg, |
|
897 |
com.sun.source.tree.Tree t, |
|
898 |
com.sun.source.tree.CompilationUnitTree root) { |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
899 |
printMessage(kind, msg, ((JCTree) t).pos(), root); |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
900 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
901 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
902 |
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
|
903 |
com.sun.source.doctree.DocTree t, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
904 |
com.sun.source.doctree.DocCommentTree c, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
905 |
com.sun.source.tree.CompilationUnitTree root) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
906 |
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
|
907 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
908 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
909 |
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
|
910 |
JCDiagnostic.DiagnosticPosition pos, |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
911 |
com.sun.source.tree.CompilationUnitTree root) { |
3149 | 912 |
JavaFileObject oldSource = null; |
913 |
JavaFileObject newSource = null; |
|
914 |
||
915 |
newSource = root.getSourceFile(); |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
916 |
if (newSource == null) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
917 |
pos = null; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14258
diff
changeset
|
918 |
} else { |
3149 | 919 |
oldSource = log.useSource(newSource); |
920 |
} |
|
921 |
||
922 |
try { |
|
923 |
switch (kind) { |
|
924 |
case ERROR: |
|
925 |
boolean prev = log.multipleErrors; |
|
926 |
try { |
|
927 |
log.error(pos, "proc.messager", msg.toString()); |
|
928 |
} finally { |
|
929 |
log.multipleErrors = prev; |
|
930 |
} |
|
931 |
break; |
|
932 |
||
933 |
case WARNING: |
|
934 |
log.warning(pos, "proc.messager", msg.toString()); |
|
935 |
break; |
|
936 |
||
937 |
case MANDATORY_WARNING: |
|
938 |
log.mandatoryWarning(pos, "proc.messager", msg.toString()); |
|
939 |
break; |
|
940 |
||
941 |
default: |
|
942 |
log.note(pos, "proc.messager", msg.toString()); |
|
943 |
} |
|
944 |
} finally { |
|
945 |
if (oldSource != null) |
|
946 |
log.useSource(oldSource); |
|
947 |
} |
|
948 |
} |
|
9599
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
949 |
|
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
950 |
@Override |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
951 |
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
|
952 |
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
|
953 |
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
|
954 |
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
|
955 |
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
|
956 |
return ut.getLub(); |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
957 |
} else { |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
958 |
return v.type; |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
959 |
} |
0996df19ea87
7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents:
7631
diff
changeset
|
960 |
} |
10 | 961 |
} |