author | emc |
Tue, 21 Oct 2014 09:01:51 -0400 | |
changeset 27224 | 228abfa87080 |
parent 25874 | 83c19f00452c |
child 30066 | d74c06a92bd8 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22165
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javadoc; |
|
27 |
||
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
28 |
import java.io.File; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
29 |
import java.io.IOException; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
30 |
import java.lang.reflect.Modifier; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
31 |
import java.net.URI; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
32 |
import java.util.HashSet; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
33 |
import java.util.Set; |
14802 | 34 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
35 |
import javax.tools.FileObject; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
36 |
import javax.tools.JavaFileManager.Location; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
37 |
import javax.tools.StandardJavaFileManager; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
38 |
import javax.tools.StandardLocation; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
39 |
|
10 | 40 |
import com.sun.javadoc.*; |
14802 | 41 |
import com.sun.source.util.TreePath; |
10 | 42 |
import com.sun.tools.javac.code.Flags; |
43 |
import com.sun.tools.javac.code.Kinds; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
44 |
import com.sun.tools.javac.code.Kinds.KindSelector; |
10 | 45 |
import com.sun.tools.javac.code.Scope; |
46 |
import com.sun.tools.javac.code.Symbol; |
|
47 |
import com.sun.tools.javac.code.Symbol.*; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
48 |
import com.sun.tools.javac.code.Type; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
49 |
import com.sun.tools.javac.code.Type.ClassType; |
18915
dcc9c8265f65
8016640: compiler hangs if the generics arity of a base class is wrong
mcimadamore
parents:
17275
diff
changeset
|
50 |
import com.sun.tools.javac.code.TypeTag; |
10 | 51 |
import com.sun.tools.javac.comp.AttrContext; |
52 |
import com.sun.tools.javac.comp.Env; |
|
53 |
import com.sun.tools.javac.tree.JCTree; |
|
54 |
import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
|
55 |
import com.sun.tools.javac.tree.JCTree.JCImport; |
|
56 |
import com.sun.tools.javac.tree.TreeInfo; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
57 |
import com.sun.tools.javac.util.List; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
58 |
import com.sun.tools.javac.util.ListBuffer; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
59 |
import com.sun.tools.javac.util.Name; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
60 |
import com.sun.tools.javac.util.Names; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
61 |
import com.sun.tools.javac.util.Position; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
62 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
63 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
64 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
10950 | 65 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
10 | 66 |
|
67 |
/** |
|
68 |
* Represents a java class and provides access to information |
|
69 |
* about the class, the class' comment and tags, and the |
|
70 |
* members of the class. A ClassDocImpl only exists if it was |
|
71 |
* processed in this run of javadoc. References to classes |
|
72 |
* which may or may not have been processed in this run are |
|
73 |
* referred to using Type (which can be converted to ClassDocImpl, |
|
74 |
* if possible). |
|
75 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
76 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
77 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
78 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
79 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14259
diff
changeset
|
80 |
* |
10 | 81 |
* @see Type |
82 |
* |
|
83 |
* @since 1.2 |
|
84 |
* @author Robert Field |
|
85 |
* @author Neal Gafter (rewrite) |
|
86 |
* @author Scott Seligman (generics, enums, annotations) |
|
87 |
*/ |
|
88 |
||
89 |
public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { |
|
90 |
||
91 |
public final ClassType type; // protected->public for debugging |
|
92 |
protected final ClassSymbol tsym; |
|
93 |
||
94 |
boolean isIncluded = false; // Set in RootDocImpl |
|
95 |
||
96 |
private SerializedForm serializedForm; |
|
97 |
||
98 |
/** |
|
99 |
* Constructor |
|
100 |
*/ |
|
101 |
public ClassDocImpl(DocEnv env, ClassSymbol sym) { |
|
14802 | 102 |
this(env, sym, null); |
10 | 103 |
} |
104 |
||
105 |
/** |
|
106 |
* Constructor |
|
107 |
*/ |
|
14802 | 108 |
public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) { |
109 |
super(env, sym, treePath); |
|
10 | 110 |
this.type = (ClassType)sym.type; |
111 |
this.tsym = sym; |
|
112 |
} |
|
113 |
||
16969
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
114 |
public com.sun.javadoc.Type getElementType() { |
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
115 |
return null; |
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
116 |
} |
b58d8a70d921
8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents:
15385
diff
changeset
|
117 |
|
10 | 118 |
/** |
119 |
* Returns the flags in terms of javac's flags |
|
120 |
*/ |
|
121 |
protected long getFlags() { |
|
122 |
return getFlags(tsym); |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Returns the flags of a ClassSymbol in terms of javac's flags |
|
127 |
*/ |
|
128 |
static long getFlags(ClassSymbol clazz) { |
|
129 |
while (true) { |
|
130 |
try { |
|
131 |
return clazz.flags(); |
|
132 |
} catch (CompletionFailure ex) { |
|
19669 | 133 |
/* Quietly ignore completion failures. |
134 |
* Note that a CompletionFailure can only |
|
135 |
* occur as a result of calling complete(), |
|
136 |
* which will always remove the current |
|
137 |
* completer, leaving it to be null or |
|
138 |
* follow-up completer. Thus the loop |
|
139 |
* is guaranteed to eventually terminate. |
|
140 |
*/ |
|
10 | 141 |
} |
142 |
} |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Is a ClassSymbol an annotation type? |
|
147 |
*/ |
|
148 |
static boolean isAnnotationType(ClassSymbol clazz) { |
|
149 |
return (getFlags(clazz) & Flags.ANNOTATION) != 0; |
|
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Identify the containing class |
|
154 |
*/ |
|
155 |
protected ClassSymbol getContainingClass() { |
|
156 |
return tsym.owner.enclClass(); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* Return true if this is a class, not an interface. |
|
161 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
162 |
@Override |
10 | 163 |
public boolean isClass() { |
164 |
return !Modifier.isInterface(getModifiers()); |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Return true if this is a ordinary class, |
|
169 |
* not an enumeration, exception, an error, or an interface. |
|
170 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
171 |
@Override |
10 | 172 |
public boolean isOrdinaryClass() { |
173 |
if (isEnum() || isInterface() || isAnnotationType()) { |
|
174 |
return false; |
|
175 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
176 |
for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { |
10 | 177 |
if (t.tsym == env.syms.errorType.tsym || |
178 |
t.tsym == env.syms.exceptionType.tsym) { |
|
179 |
return false; |
|
180 |
} |
|
181 |
} |
|
182 |
return true; |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Return true if this is an enumeration. |
|
187 |
* (For legacy doclets, return false.) |
|
188 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
189 |
@Override |
10 | 190 |
public boolean isEnum() { |
191 |
return (getFlags() & Flags.ENUM) != 0 |
|
192 |
&& |
|
193 |
!env.legacyDoclet; |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Return true if this is an interface, but not an annotation type. |
|
198 |
* Overridden by AnnotationTypeDocImpl. |
|
199 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
200 |
@Override |
10 | 201 |
public boolean isInterface() { |
202 |
return Modifier.isInterface(getModifiers()); |
|
203 |
} |
|
204 |
||
205 |
/** |
|
206 |
* Return true if this is an exception class |
|
207 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
208 |
@Override |
10 | 209 |
public boolean isException() { |
210 |
if (isEnum() || isInterface() || isAnnotationType()) { |
|
211 |
return false; |
|
212 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
213 |
for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { |
10 | 214 |
if (t.tsym == env.syms.exceptionType.tsym) { |
215 |
return true; |
|
216 |
} |
|
217 |
} |
|
218 |
return false; |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Return true if this is an error class |
|
223 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
224 |
@Override |
10 | 225 |
public boolean isError() { |
226 |
if (isEnum() || isInterface() || isAnnotationType()) { |
|
227 |
return false; |
|
228 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
229 |
for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { |
10 | 230 |
if (t.tsym == env.syms.errorType.tsym) { |
231 |
return true; |
|
232 |
} |
|
233 |
} |
|
234 |
return false; |
|
235 |
} |
|
236 |
||
237 |
/** |
|
238 |
* Return true if this is a throwable class |
|
239 |
*/ |
|
240 |
public boolean isThrowable() { |
|
241 |
if (isEnum() || isInterface() || isAnnotationType()) { |
|
242 |
return false; |
|
243 |
} |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14260
diff
changeset
|
244 |
for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { |
10 | 245 |
if (t.tsym == env.syms.throwableType.tsym) { |
246 |
return true; |
|
247 |
} |
|
248 |
} |
|
249 |
return false; |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* Return true if this class is abstract |
|
254 |
*/ |
|
255 |
public boolean isAbstract() { |
|
256 |
return Modifier.isAbstract(getModifiers()); |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Returns true if this class was synthesized by the compiler. |
|
261 |
*/ |
|
262 |
public boolean isSynthetic() { |
|
263 |
return (getFlags() & Flags.SYNTHETIC) != 0; |
|
264 |
} |
|
265 |
||
266 |
/** |
|
267 |
* Return true if this class is included in the active set. |
|
268 |
* A ClassDoc is included iff either it is specified on the |
|
269 |
* commandline, or if it's containing package is specified |
|
270 |
* on the command line, or if it is a member class of an |
|
271 |
* included class. |
|
272 |
*/ |
|
273 |
||
274 |
public boolean isIncluded() { |
|
275 |
if (isIncluded) { |
|
276 |
return true; |
|
277 |
} |
|
278 |
if (env.shouldDocument(tsym)) { |
|
279 |
// Class is nameable from top-level and |
|
280 |
// the class and all enclosing classes |
|
281 |
// pass the modifier filter. |
|
282 |
if (containingPackage().isIncluded()) { |
|
283 |
return isIncluded=true; |
|
284 |
} |
|
285 |
ClassDoc outer = containingClass(); |
|
286 |
if (outer != null && outer.isIncluded()) { |
|
287 |
return isIncluded=true; |
|
288 |
} |
|
289 |
} |
|
290 |
return false; |
|
291 |
} |
|
292 |
||
293 |
/** |
|
294 |
* Return the package that this class is contained in. |
|
295 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
296 |
@Override |
10 | 297 |
public PackageDoc containingPackage() { |
298 |
PackageDocImpl p = env.getPackageDoc(tsym.packge()); |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
299 |
if (p.setDocPath == false) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
300 |
FileObject docPath; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
301 |
try { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
302 |
Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
303 |
? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
304 |
|
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
305 |
docPath = env.fileManager.getFileForInput( |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
306 |
location, p.qualifiedName(), "package.html"); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
307 |
} catch (IOException e) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
308 |
docPath = null; |
10 | 309 |
} |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
310 |
|
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
311 |
if (docPath == null) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
312 |
// fall back on older semantics of looking in same directory as |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
313 |
// source file for this class |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
314 |
SourcePosition po = position(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
315 |
if (env.fileManager instanceof StandardJavaFileManager && |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
316 |
po instanceof SourcePositionImpl) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
317 |
URI uri = ((SourcePositionImpl) po).filename.toUri(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
318 |
if ("file".equals(uri.getScheme())) { |
3782 | 319 |
File f = new File(uri); |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
320 |
File dir = f.getParentFile(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
321 |
if (dir != null) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
322 |
File pf = new File(dir, "package.html"); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
323 |
if (pf.exists()) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
324 |
StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
325 |
docPath = sfm.getJavaFileObjects(pf).iterator().next(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
326 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
327 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
328 |
|
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
329 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
330 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
331 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
332 |
|
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
333 |
p.setDocPath(docPath); |
10 | 334 |
} |
335 |
return p; |
|
336 |
} |
|
337 |
||
338 |
/** |
|
339 |
* Return the class name without package qualifier - but with |
|
340 |
* enclosing class qualifier - as a String. |
|
341 |
* <pre> |
|
342 |
* Examples: |
|
343 |
* for java.util.Hashtable |
|
344 |
* return Hashtable |
|
345 |
* for java.util.Map.Entry |
|
346 |
* return Map.Entry |
|
347 |
* </pre> |
|
348 |
*/ |
|
349 |
public String name() { |
|
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
350 |
if (name == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
351 |
name = getClassName(tsym, false); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
352 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
353 |
return name; |
10 | 354 |
} |
355 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
356 |
private String name; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
357 |
|
10 | 358 |
/** |
359 |
* Return the qualified class name as a String. |
|
360 |
* <pre> |
|
361 |
* Example: |
|
362 |
* for java.util.Hashtable |
|
363 |
* return java.util.Hashtable |
|
364 |
* if no qualifier, just return flat name |
|
365 |
* </pre> |
|
366 |
*/ |
|
367 |
public String qualifiedName() { |
|
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
368 |
if (qualifiedName == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
369 |
qualifiedName = getClassName(tsym, true); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
370 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
371 |
return qualifiedName; |
10 | 372 |
} |
373 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
374 |
private String qualifiedName; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
375 |
|
10 | 376 |
/** |
377 |
* Return unqualified name of type excluding any dimension information. |
|
378 |
* <p> |
|
379 |
* For example, a two dimensional array of String returns 'String'. |
|
380 |
*/ |
|
381 |
public String typeName() { |
|
382 |
return name(); |
|
383 |
} |
|
384 |
||
385 |
/** |
|
386 |
* Return qualified name of type excluding any dimension information. |
|
387 |
*<p> |
|
388 |
* For example, a two dimensional array of String |
|
389 |
* returns 'java.lang.String'. |
|
390 |
*/ |
|
391 |
public String qualifiedTypeName() { |
|
392 |
return qualifiedName(); |
|
393 |
} |
|
394 |
||
395 |
/** |
|
396 |
* Return the simple name of this type. |
|
397 |
*/ |
|
398 |
public String simpleTypeName() { |
|
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
399 |
if (simpleTypeName == null) { |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
400 |
simpleTypeName = tsym.name.toString(); |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
401 |
} |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
402 |
return simpleTypeName; |
10 | 403 |
} |
404 |
||
17275
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
405 |
private String simpleTypeName; |
bcaa1940863a
8012656: cache frequently used name strings for DocImpl classes
jjg
parents:
16969
diff
changeset
|
406 |
|
10 | 407 |
/** |
408 |
* Return the qualified name and any type parameters. |
|
409 |
* Each parameter is a type variable with optional bounds. |
|
410 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
411 |
@Override |
10 | 412 |
public String toString() { |
413 |
return classToString(env, tsym, true); |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Return the class name as a string. If "full" is true the name is |
|
418 |
* qualified, otherwise it is qualified by its enclosing class(es) only. |
|
419 |
*/ |
|
420 |
static String getClassName(ClassSymbol c, boolean full) { |
|
421 |
if (full) { |
|
422 |
return c.getQualifiedName().toString(); |
|
423 |
} else { |
|
424 |
String n = ""; |
|
425 |
for ( ; c != null; c = c.owner.enclClass()) { |
|
426 |
n = c.name + (n.equals("") ? "" : ".") + n; |
|
427 |
} |
|
428 |
return n; |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
/** |
|
433 |
* Return the class name with any type parameters as a string. |
|
434 |
* Each parameter is a type variable with optional bounds. |
|
435 |
* If "full" is true all names are qualified, otherwise they are |
|
436 |
* qualified by their enclosing class(es) only. |
|
437 |
*/ |
|
438 |
static String classToString(DocEnv env, ClassSymbol c, boolean full) { |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
439 |
StringBuilder s = new StringBuilder(); |
10 | 440 |
if (!c.isInner()) { // if c is not an inner class |
441 |
s.append(getClassName(c, full)); |
|
442 |
} else { |
|
443 |
// c is an inner class, so include type params of outer. |
|
444 |
ClassSymbol encl = c.owner.enclClass(); |
|
445 |
s.append(classToString(env, encl, full)) |
|
446 |
.append('.') |
|
447 |
.append(c.name); |
|
448 |
} |
|
449 |
s.append(TypeMaker.typeParametersString(env, c, full)); |
|
450 |
return s.toString(); |
|
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* Is this class (or any enclosing class) generic? That is, does |
|
455 |
* it have type parameters? |
|
456 |
*/ |
|
457 |
static boolean isGeneric(ClassSymbol c) { |
|
458 |
return c.type.allparams().nonEmpty(); |
|
459 |
} |
|
460 |
||
461 |
/** |
|
462 |
* Return the formal type parameters of this class or interface. |
|
463 |
* Return an empty array if there are none. |
|
464 |
*/ |
|
465 |
public TypeVariable[] typeParameters() { |
|
466 |
if (env.legacyDoclet) { |
|
467 |
return new TypeVariable[0]; |
|
468 |
} |
|
469 |
TypeVariable res[] = new TypeVariable[type.getTypeArguments().length()]; |
|
470 |
TypeMaker.getTypes(env, type.getTypeArguments(), res); |
|
471 |
return res; |
|
472 |
} |
|
473 |
||
474 |
/** |
|
475 |
* Return the type parameter tags of this class or interface. |
|
476 |
*/ |
|
477 |
public ParamTag[] typeParamTags() { |
|
478 |
return (env.legacyDoclet) |
|
479 |
? new ParamTag[0] |
|
480 |
: comment().typeParamTags(); |
|
481 |
} |
|
482 |
||
483 |
/** |
|
484 |
* Return the modifier string for this class. If it's an interface |
|
485 |
* exclude 'abstract' keyword from the modifier string |
|
486 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
487 |
@Override |
10 | 488 |
public String modifiers() { |
489 |
return Modifier.toString(modifierSpecifier()); |
|
490 |
} |
|
491 |
||
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
492 |
@Override |
10 | 493 |
public int modifierSpecifier() { |
494 |
int modifiers = getModifiers(); |
|
495 |
return (isInterface() || isAnnotationType()) |
|
496 |
? modifiers & ~Modifier.ABSTRACT |
|
497 |
: modifiers; |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* Return the superclass of this class |
|
502 |
* |
|
503 |
* @return the ClassDocImpl for the superclass of this class, null |
|
504 |
* if there is no superclass. |
|
505 |
*/ |
|
506 |
public ClassDoc superclass() { |
|
507 |
if (isInterface() || isAnnotationType()) return null; |
|
508 |
if (tsym == env.syms.objectType.tsym) return null; |
|
509 |
ClassSymbol c = (ClassSymbol)env.types.supertype(type).tsym; |
|
510 |
if (c == null || c == tsym) c = (ClassSymbol)env.syms.objectType.tsym; |
|
511 |
return env.getClassDoc(c); |
|
512 |
} |
|
513 |
||
514 |
/** |
|
515 |
* Return the superclass of this class. Return null if this is an |
|
516 |
* interface. A superclass is represented by either a |
|
517 |
* <code>ClassDoc</code> or a <code>ParameterizedType</code>. |
|
518 |
*/ |
|
519 |
public com.sun.javadoc.Type superclassType() { |
|
520 |
if (isInterface() || isAnnotationType() || |
|
521 |
(tsym == env.syms.objectType.tsym)) |
|
522 |
return null; |
|
523 |
Type sup = env.types.supertype(type); |
|
524 |
return TypeMaker.getType(env, |
|
18915
dcc9c8265f65
8016640: compiler hangs if the generics arity of a base class is wrong
mcimadamore
parents:
17275
diff
changeset
|
525 |
(sup.hasTag(TypeTag.NONE)) ? env.syms.objectType : sup); |
10 | 526 |
} |
527 |
||
528 |
/** |
|
529 |
* Test whether this class is a subclass of the specified class. |
|
530 |
* |
|
531 |
* @param cd the candidate superclass. |
|
532 |
* @return true if cd is a superclass of this class. |
|
533 |
*/ |
|
534 |
public boolean subclassOf(ClassDoc cd) { |
|
535 |
return tsym.isSubClass(((ClassDocImpl)cd).tsym, env.types); |
|
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
* Return interfaces implemented by this class or interfaces |
|
540 |
* extended by this interface. |
|
541 |
* |
|
542 |
* @return An array of ClassDocImpl representing the interfaces. |
|
543 |
* Return an empty array if there are no interfaces. |
|
544 |
*/ |
|
545 |
public ClassDoc[] interfaces() { |
|
22163 | 546 |
ListBuffer<ClassDocImpl> ta = new ListBuffer<>(); |
10 | 547 |
for (Type t : env.types.interfaces(type)) { |
548 |
ta.append(env.getClassDoc((ClassSymbol)t.tsym)); |
|
549 |
} |
|
550 |
//### Cache ta here? |
|
551 |
return ta.toArray(new ClassDocImpl[ta.length()]); |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* Return interfaces implemented by this class or interfaces extended |
|
556 |
* by this interface. Includes only directly-declared interfaces, not |
|
557 |
* inherited interfaces. |
|
558 |
* Return an empty array if there are no interfaces. |
|
559 |
*/ |
|
560 |
public com.sun.javadoc.Type[] interfaceTypes() { |
|
561 |
//### Cache result here? |
|
562 |
return TypeMaker.getTypes(env, env.types.interfaces(type)); |
|
563 |
} |
|
564 |
||
565 |
/** |
|
566 |
* Return fields in class. |
|
567 |
* @param filter include only the included fields if filter==true |
|
568 |
*/ |
|
569 |
public FieldDoc[] fields(boolean filter) { |
|
570 |
return fields(filter, false); |
|
571 |
} |
|
572 |
||
573 |
/** |
|
574 |
* Return included fields in class. |
|
575 |
*/ |
|
576 |
public FieldDoc[] fields() { |
|
577 |
return fields(true, false); |
|
578 |
} |
|
579 |
||
580 |
/** |
|
581 |
* Return the enum constants if this is an enum type. |
|
582 |
*/ |
|
583 |
public FieldDoc[] enumConstants() { |
|
584 |
return fields(false, true); |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* Return fields in class. |
|
589 |
* @param filter if true, return only the included fields |
|
590 |
* @param enumConstants if true, return the enum constants instead |
|
591 |
*/ |
|
592 |
private FieldDoc[] fields(boolean filter, boolean enumConstants) { |
|
593 |
List<FieldDocImpl> fields = List.nil(); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
594 |
for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
595 |
if (sym != null && sym.kind == VAR) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
596 |
VarSymbol s = (VarSymbol)sym; |
10 | 597 |
boolean isEnum = ((s.flags() & Flags.ENUM) != 0) && |
598 |
!env.legacyDoclet; |
|
599 |
if (isEnum == enumConstants && |
|
600 |
(!filter || env.shouldDocument(s))) { |
|
601 |
fields = fields.prepend(env.getFieldDoc(s)); |
|
602 |
} |
|
603 |
} |
|
604 |
} |
|
605 |
return fields.toArray(new FieldDocImpl[fields.length()]); |
|
606 |
} |
|
607 |
||
608 |
/** |
|
609 |
* Return methods in class. |
|
610 |
* This method is overridden by AnnotationTypeDocImpl. |
|
611 |
* |
|
612 |
* @param filter include only the included methods if filter==true |
|
613 |
* @return an array of MethodDocImpl for representing the visible |
|
614 |
* methods in this class. Does not include constructors. |
|
615 |
*/ |
|
616 |
public MethodDoc[] methods(boolean filter) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
617 |
Names names = tsym.name.table.names; |
10 | 618 |
List<MethodDocImpl> methods = List.nil(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
619 |
for (Symbol sym :tsym.members().getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
620 |
if (sym != null |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
621 |
&& sym.kind == MTH |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
622 |
&& sym.name != names.init |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
623 |
&& sym.name != names.clinit) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
624 |
MethodSymbol s = (MethodSymbol)sym; |
10 | 625 |
if (!filter || env.shouldDocument(s)) { |
626 |
methods = methods.prepend(env.getMethodDoc(s)); |
|
627 |
} |
|
628 |
} |
|
629 |
} |
|
630 |
//### Cache methods here? |
|
631 |
return methods.toArray(new MethodDocImpl[methods.length()]); |
|
632 |
} |
|
633 |
||
634 |
/** |
|
635 |
* Return included methods in class. |
|
636 |
* |
|
637 |
* @return an array of MethodDocImpl for representing the visible |
|
638 |
* methods in this class. Does not include constructors. |
|
639 |
*/ |
|
640 |
public MethodDoc[] methods() { |
|
641 |
return methods(true); |
|
642 |
} |
|
643 |
||
644 |
/** |
|
645 |
* Return constructors in class. |
|
646 |
* |
|
647 |
* @param filter include only the included constructors if filter==true |
|
648 |
* @return an array of ConstructorDocImpl for representing the visible |
|
649 |
* constructors in this class. |
|
650 |
*/ |
|
651 |
public ConstructorDoc[] constructors(boolean filter) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
652 |
Names names = tsym.name.table.names; |
10 | 653 |
List<ConstructorDocImpl> constructors = List.nil(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
654 |
for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
655 |
if (sym != null && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
656 |
sym.kind == MTH && sym.name == names.init) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
657 |
MethodSymbol s = (MethodSymbol)sym; |
10 | 658 |
if (!filter || env.shouldDocument(s)) { |
659 |
constructors = constructors.prepend(env.getConstructorDoc(s)); |
|
660 |
} |
|
661 |
} |
|
662 |
} |
|
663 |
//### Cache constructors here? |
|
664 |
return constructors.toArray(new ConstructorDocImpl[constructors.length()]); |
|
665 |
} |
|
666 |
||
667 |
/** |
|
668 |
* Return included constructors in class. |
|
669 |
* |
|
670 |
* @return an array of ConstructorDocImpl for representing the visible |
|
671 |
* constructors in this class. |
|
672 |
*/ |
|
673 |
public ConstructorDoc[] constructors() { |
|
674 |
return constructors(true); |
|
675 |
} |
|
676 |
||
677 |
/** |
|
678 |
* Adds all inner classes of this class, and their |
|
679 |
* inner classes recursively, to the list l. |
|
680 |
*/ |
|
681 |
void addAllClasses(ListBuffer<ClassDocImpl> l, boolean filtered) { |
|
682 |
try { |
|
683 |
if (isSynthetic()) return; |
|
684 |
// sometimes synthetic classes are not marked synthetic |
|
685 |
if (!JavadocTool.isValidClassName(tsym.name.toString())) return; |
|
686 |
if (filtered && !env.shouldDocument(tsym)) return; |
|
687 |
if (l.contains(this)) return; |
|
688 |
l.append(this); |
|
689 |
List<ClassDocImpl> more = List.nil(); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
690 |
for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
691 |
if (sym != null && sym.kind == TYP) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
692 |
ClassSymbol s = (ClassSymbol)sym; |
10 | 693 |
ClassDocImpl c = env.getClassDoc(s); |
694 |
if (c.isSynthetic()) continue; |
|
695 |
if (c != null) more = more.prepend(c); |
|
696 |
} |
|
697 |
} |
|
698 |
// this extra step preserves the ordering from oldjavadoc |
|
699 |
for (; more.nonEmpty(); more=more.tail) { |
|
700 |
more.head.addAllClasses(l, filtered); |
|
701 |
} |
|
702 |
} catch (CompletionFailure e) { |
|
703 |
// quietly ignore completion failures |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
/** |
|
708 |
* Return inner classes within this class. |
|
709 |
* |
|
710 |
* @param filter include only the included inner classes if filter==true. |
|
711 |
* @return an array of ClassDocImpl for representing the visible |
|
712 |
* classes defined in this class. Anonymous and local classes |
|
713 |
* are not included. |
|
714 |
*/ |
|
715 |
public ClassDoc[] innerClasses(boolean filter) { |
|
22163 | 716 |
ListBuffer<ClassDocImpl> innerClasses = new ListBuffer<>(); |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
717 |
for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
718 |
if (sym != null && sym.kind == TYP) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
719 |
ClassSymbol s = (ClassSymbol)sym; |
10 | 720 |
if ((s.flags_field & Flags.SYNTHETIC) != 0) continue; |
721 |
if (!filter || env.isVisible(s)) { |
|
722 |
innerClasses.prepend(env.getClassDoc(s)); |
|
723 |
} |
|
724 |
} |
|
725 |
} |
|
726 |
//### Cache classes here? |
|
727 |
return innerClasses.toArray(new ClassDocImpl[innerClasses.length()]); |
|
728 |
} |
|
729 |
||
730 |
/** |
|
731 |
* Return included inner classes within this class. |
|
732 |
* |
|
733 |
* @return an array of ClassDocImpl for representing the visible |
|
734 |
* classes defined in this class. Anonymous and local classes |
|
735 |
* are not included. |
|
736 |
*/ |
|
737 |
public ClassDoc[] innerClasses() { |
|
738 |
return innerClasses(true); |
|
739 |
} |
|
740 |
||
741 |
/** |
|
742 |
* Find a class within the context of this class. |
|
743 |
* Search order: qualified name, in this class (inner), |
|
744 |
* in this package, in the class imports, in the package |
|
745 |
* imports. |
|
746 |
* Return the ClassDocImpl if found, null if not found. |
|
747 |
*/ |
|
748 |
//### The specified search order is not the normal rule the |
|
749 |
//### compiler would use. Leave as specified or change it? |
|
750 |
public ClassDoc findClass(String className) { |
|
751 |
ClassDoc searchResult = searchClass(className); |
|
752 |
if (searchResult == null) { |
|
753 |
ClassDocImpl enclosingClass = (ClassDocImpl)containingClass(); |
|
754 |
//Expand search space to include enclosing class. |
|
755 |
while (enclosingClass != null && enclosingClass.containingClass() != null) { |
|
756 |
enclosingClass = (ClassDocImpl)enclosingClass.containingClass(); |
|
757 |
} |
|
758 |
searchResult = enclosingClass == null ? |
|
759 |
null : enclosingClass.searchClass(className); |
|
760 |
} |
|
761 |
return searchResult; |
|
762 |
} |
|
763 |
||
764 |
private ClassDoc searchClass(String className) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
765 |
Names names = tsym.name.table.names; |
10 | 766 |
|
767 |
// search by qualified name first |
|
768 |
ClassDoc cd = env.lookupClass(className); |
|
769 |
if (cd != null) { |
|
770 |
return cd; |
|
771 |
} |
|
772 |
||
773 |
// search inner classes |
|
774 |
//### Add private entry point to avoid creating array? |
|
775 |
//### Replicate code in innerClasses here to avoid consing? |
|
10203
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
776 |
for (ClassDoc icd : innerClasses()) { |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
777 |
if (icd.name().equals(className) || |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
778 |
//### This is from original javadoc but it looks suspicious to me... |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
779 |
//### I believe it is attempting to compensate for the confused |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
780 |
//### convention of including the nested class qualifiers in the |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
781 |
//### 'name' of the inner class, rather than the true simple name. |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
782 |
icd.name().endsWith("." + className)) { |
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
783 |
return icd; |
10 | 784 |
} else { |
10203
cca843a7d258
7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents:
8631
diff
changeset
|
785 |
ClassDoc innercd = ((ClassDocImpl) icd).searchClass(className); |
10 | 786 |
if (innercd != null) { |
787 |
return innercd; |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
// check in this package |
|
793 |
cd = containingPackage().findClass(className); |
|
794 |
if (cd != null) { |
|
795 |
return cd; |
|
796 |
} |
|
797 |
||
798 |
// make sure that this symbol has been completed |
|
799 |
if (tsym.completer != null) { |
|
800 |
tsym.complete(); |
|
801 |
} |
|
802 |
||
803 |
// search imports |
|
804 |
||
805 |
if (tsym.sourcefile != null) { |
|
806 |
||
807 |
//### This information is available only for source classes. |
|
808 |
||
809 |
Env<AttrContext> compenv = env.enter.getEnv(tsym); |
|
810 |
if (compenv == null) return null; |
|
811 |
||
812 |
Scope s = compenv.toplevel.namedImportScope; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
813 |
for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
814 |
if (sym.kind == TYP) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
815 |
ClassDoc c = env.getClassDoc((ClassSymbol)sym); |
10 | 816 |
return c; |
817 |
} |
|
818 |
} |
|
819 |
||
820 |
s = compenv.toplevel.starImportScope; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
821 |
for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
822 |
if (sym.kind == TYP) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
823 |
ClassDoc c = env.getClassDoc((ClassSymbol)sym); |
10 | 824 |
return c; |
825 |
} |
|
826 |
} |
|
827 |
} |
|
828 |
||
829 |
return null; // not found |
|
830 |
} |
|
831 |
||
832 |
||
833 |
private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) { |
|
834 |
||
835 |
if (argTypes == null) { |
|
836 |
// wildcard |
|
837 |
return true; |
|
838 |
} |
|
839 |
||
840 |
int i = 0; |
|
841 |
List<Type> types = method.type.getParameterTypes(); |
|
842 |
||
843 |
if (argTypes.length != types.length()) { |
|
844 |
return false; |
|
845 |
} |
|
846 |
||
847 |
for (Type t : types) { |
|
848 |
String argType = argTypes[i++]; |
|
849 |
// For vararg method, "T..." matches type T[]. |
|
850 |
if (i == argTypes.length) { |
|
851 |
argType = argType.replace("...", "[]"); |
|
852 |
} |
|
853 |
if (!hasTypeName(env.types.erasure(t), argType)) { //###(gj) |
|
854 |
return false; |
|
855 |
} |
|
856 |
} |
|
857 |
return true; |
|
858 |
} |
|
859 |
// where |
|
860 |
private boolean hasTypeName(Type t, String name) { |
|
861 |
return |
|
862 |
name.equals(TypeMaker.getTypeName(t, true)) |
|
863 |
|| |
|
864 |
name.equals(TypeMaker.getTypeName(t, false)) |
|
865 |
|| |
|
866 |
(qualifiedName() + "." + name).equals(TypeMaker.getTypeName(t, true)); |
|
867 |
} |
|
868 |
||
869 |
||
870 |
||
871 |
/** |
|
872 |
* Find a method in this class scope. |
|
873 |
* Search order: this class, interfaces, superclasses, outerclasses. |
|
874 |
* Note that this is not necessarily what the compiler would do! |
|
875 |
* |
|
876 |
* @param methodName the unqualified name to search for. |
|
14259 | 877 |
* @param paramTypes the array of Strings for method parameter types. |
10 | 878 |
* @return the first MethodDocImpl which matches, null if not found. |
879 |
*/ |
|
880 |
public MethodDocImpl findMethod(String methodName, String[] paramTypes) { |
|
881 |
// Use hash table 'searched' to avoid searching same class twice. |
|
882 |
//### It is not clear how this could happen. |
|
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
883 |
return searchMethod(methodName, paramTypes, new HashSet<ClassDocImpl>()); |
10 | 884 |
} |
885 |
||
886 |
private MethodDocImpl searchMethod(String methodName, |
|
887 |
String[] paramTypes, Set<ClassDocImpl> searched) { |
|
888 |
//### Note that this search is not necessarily what the compiler would do! |
|
889 |
||
7071
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
890 |
Names names = tsym.name.table.names; |
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
891 |
// do not match constructors |
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
892 |
if (names.init.contentEquals(methodName)) { |
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
893 |
return null; |
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
894 |
} |
8bcda461a06a
6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents:
5520
diff
changeset
|
895 |
|
10 | 896 |
ClassDocImpl cdi; |
897 |
MethodDocImpl mdi; |
|
898 |
||
899 |
if (searched.contains(this)) { |
|
900 |
return null; |
|
901 |
} |
|
902 |
searched.add(this); |
|
903 |
||
904 |
//DEBUG |
|
905 |
/*---------------------------------* |
|
906 |
System.out.print("searching " + this + " for " + methodName); |
|
907 |
if (paramTypes == null) { |
|
908 |
System.out.println("()"); |
|
909 |
} else { |
|
910 |
System.out.print("("); |
|
911 |
for (int k=0; k < paramTypes.length; k++) { |
|
912 |
System.out.print(paramTypes[k]); |
|
913 |
if ((k + 1) < paramTypes.length) { |
|
914 |
System.out.print(", "); |
|
915 |
} |
|
916 |
} |
|
917 |
System.out.println(")"); |
|
918 |
} |
|
919 |
*---------------------------------*/ |
|
920 |
||
921 |
// search current class |
|
922 |
||
923 |
//### Using modifier filter here isn't really correct, |
|
924 |
//### but emulates the old behavior. Instead, we should |
|
925 |
//### apply the normal rules of visibility and inheritance. |
|
926 |
||
927 |
if (paramTypes == null) { |
|
928 |
// If no parameters specified, we are allowed to return |
|
929 |
// any method with a matching name. In practice, the old |
|
930 |
// code returned the first method, which is now the last! |
|
931 |
// In order to provide textually identical results, we |
|
932 |
// attempt to emulate the old behavior. |
|
933 |
MethodSymbol lastFound = null; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
934 |
for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
935 |
if (sym.kind == MTH) { |
10 | 936 |
//### Should intern methodName as Name. |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
937 |
if (sym.name.toString().equals(methodName)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
938 |
lastFound = (MethodSymbol)sym; |
10 | 939 |
} |
940 |
} |
|
941 |
} |
|
942 |
if (lastFound != null) { |
|
943 |
return env.getMethodDoc(lastFound); |
|
944 |
} |
|
945 |
} else { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
946 |
for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
947 |
if (sym != null && |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
948 |
sym.kind == MTH) { |
10 | 949 |
//### Should intern methodName as Name. |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
950 |
if (hasParameterTypes((MethodSymbol)sym, paramTypes)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
951 |
return env.getMethodDoc((MethodSymbol)sym); |
10 | 952 |
} |
953 |
} |
|
954 |
} |
|
955 |
} |
|
956 |
||
957 |
//### If we found a MethodDoc above, but which did not pass |
|
958 |
//### the modifier filter, we should return failure here! |
|
959 |
||
960 |
// search superclass |
|
961 |
cdi = (ClassDocImpl)superclass(); |
|
962 |
if (cdi != null) { |
|
963 |
mdi = cdi.searchMethod(methodName, paramTypes, searched); |
|
964 |
if (mdi != null) { |
|
965 |
return mdi; |
|
966 |
} |
|
967 |
} |
|
968 |
||
969 |
// search interfaces |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21020
diff
changeset
|
970 |
for (ClassDoc intf : interfaces()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21020
diff
changeset
|
971 |
cdi = (ClassDocImpl) intf; |
10 | 972 |
mdi = cdi.searchMethod(methodName, paramTypes, searched); |
973 |
if (mdi != null) { |
|
974 |
return mdi; |
|
975 |
} |
|
976 |
} |
|
977 |
||
978 |
// search enclosing class |
|
979 |
cdi = (ClassDocImpl)containingClass(); |
|
980 |
if (cdi != null) { |
|
981 |
mdi = cdi.searchMethod(methodName, paramTypes, searched); |
|
982 |
if (mdi != null) { |
|
983 |
return mdi; |
|
984 |
} |
|
985 |
} |
|
986 |
||
987 |
//###(gj) As a temporary measure until type variables are better |
|
988 |
//### handled, try again without the parameter types. |
|
989 |
//### This should most often find the right method, and occassionally |
|
990 |
//### find the wrong one. |
|
991 |
//if (paramTypes != null) { |
|
992 |
// return findMethod(methodName, null); |
|
993 |
//} |
|
994 |
||
995 |
return null; |
|
996 |
} |
|
997 |
||
998 |
/** |
|
999 |
* Find constructor in this class. |
|
1000 |
* |
|
1001 |
* @param constrName the unqualified name to search for. |
|
14259 | 1002 |
* @param paramTypes the array of Strings for constructor parameters. |
10 | 1003 |
* @return the first ConstructorDocImpl which matches, null if not found. |
1004 |
*/ |
|
1005 |
public ConstructorDoc findConstructor(String constrName, |
|
1006 |
String[] paramTypes) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1007 |
Names names = tsym.name.table.names; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
1008 |
for (Symbol sym : tsym.members().getSymbolsByName(names.fromString("<init>"))) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
1009 |
if (sym.kind == MTH) { |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
1010 |
if (hasParameterTypes((MethodSymbol)sym, paramTypes)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
1011 |
return env.getConstructorDoc((MethodSymbol)sym); |
10 | 1012 |
} |
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
//###(gj) As a temporary measure until type variables are better |
|
1017 |
//### handled, try again without the parameter types. |
|
1018 |
//### This will often find the right constructor, and occassionally |
|
1019 |
//### find the wrong one. |
|
1020 |
//if (paramTypes != null) { |
|
1021 |
// return findConstructor(constrName, null); |
|
1022 |
//} |
|
1023 |
||
1024 |
return null; |
|
1025 |
} |
|
1026 |
||
1027 |
/** |
|
1028 |
* Find a field in this class scope. |
|
1029 |
* Search order: this class, outerclasses, interfaces, |
|
1030 |
* superclasses. IMP: If see tag is defined in an inner class, |
|
1031 |
* which extends a super class and if outerclass and the super |
|
1032 |
* class have a visible field in common then Java compiler cribs |
|
1033 |
* about the ambiguity, but the following code will search in the |
|
1034 |
* above given search order. |
|
1035 |
* |
|
1036 |
* @param fieldName the unqualified name to search for. |
|
1037 |
* @return the first FieldDocImpl which matches, null if not found. |
|
1038 |
*/ |
|
1039 |
public FieldDoc findField(String fieldName) { |
|
22165
ec53c8946fc2
8030807: langtools should still build using jdk 7
vromero
parents:
22163
diff
changeset
|
1040 |
return searchField(fieldName, new HashSet<ClassDocImpl>()); |
10 | 1041 |
} |
1042 |
||
1043 |
private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> searched) { |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1044 |
Names names = tsym.name.table.names; |
10 | 1045 |
if (searched.contains(this)) { |
1046 |
return null; |
|
1047 |
} |
|
1048 |
searched.add(this); |
|
1049 |
||
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
1050 |
for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(fieldName))) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
1051 |
if (sym.kind == VAR) { |
10 | 1052 |
//### Should intern fieldName as Name. |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
23799
diff
changeset
|
1053 |
return env.getFieldDoc((VarSymbol)sym); |
10 | 1054 |
} |
1055 |
} |
|
1056 |
||
1057 |
//### If we found a FieldDoc above, but which did not pass |
|
1058 |
//### the modifier filter, we should return failure here! |
|
1059 |
||
1060 |
ClassDocImpl cdi = (ClassDocImpl)containingClass(); |
|
1061 |
if (cdi != null) { |
|
1062 |
FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
|
1063 |
if (fdi != null) { |
|
1064 |
return fdi; |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
1068 |
// search superclass |
|
1069 |
cdi = (ClassDocImpl)superclass(); |
|
1070 |
if (cdi != null) { |
|
1071 |
FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
|
1072 |
if (fdi != null) { |
|
1073 |
return fdi; |
|
1074 |
} |
|
1075 |
} |
|
1076 |
||
1077 |
// search interfaces |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21020
diff
changeset
|
1078 |
for (ClassDoc intf : interfaces()) { |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
21020
diff
changeset
|
1079 |
cdi = (ClassDocImpl) intf; |
10 | 1080 |
FieldDocImpl fdi = cdi.searchField(fieldName, searched); |
1081 |
if (fdi != null) { |
|
1082 |
return fdi; |
|
1083 |
} |
|
1084 |
} |
|
1085 |
||
1086 |
return null; |
|
1087 |
} |
|
1088 |
||
1089 |
/** |
|
1090 |
* Get the list of classes declared as imported. |
|
1091 |
* These are called "single-type-import declarations" in the JLS. |
|
1092 |
* This method is deprecated in the ClassDoc interface. |
|
1093 |
* |
|
1094 |
* @return an array of ClassDocImpl representing the imported classes. |
|
1095 |
* |
|
1096 |
* @deprecated Import declarations are implementation details that |
|
1097 |
* should not be exposed here. In addition, not all imported |
|
1098 |
* classes are imported through single-type-import declarations. |
|
1099 |
*/ |
|
1100 |
@Deprecated |
|
1101 |
public ClassDoc[] importedClasses() { |
|
1102 |
// information is not available for binary classfiles |
|
1103 |
if (tsym.sourcefile == null) return new ClassDoc[0]; |
|
1104 |
||
22163 | 1105 |
ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<>(); |
10 | 1106 |
|
1107 |
Env<AttrContext> compenv = env.enter.getEnv(tsym); |
|
1108 |
if (compenv == null) return new ClassDocImpl[0]; |
|
1109 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1110 |
Name asterisk = tsym.name.table.names.asterisk; |
10 | 1111 |
for (JCTree t : compenv.toplevel.defs) { |
10950 | 1112 |
if (t.hasTag(IMPORT)) { |
10 | 1113 |
JCTree imp = ((JCImport) t).qualid; |
1114 |
if ((TreeInfo.name(imp) != asterisk) && |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
1115 |
imp.type.tsym.kind.matches(KindSelector.TYP)) { |
10 | 1116 |
importedClasses.append( |
1117 |
env.getClassDoc((ClassSymbol)imp.type.tsym)); |
|
1118 |
} |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]); |
|
1123 |
} |
|
1124 |
||
1125 |
/** |
|
1126 |
* Get the list of packages declared as imported. |
|
1127 |
* These are called "type-import-on-demand declarations" in the JLS. |
|
1128 |
* This method is deprecated in the ClassDoc interface. |
|
1129 |
* |
|
1130 |
* @return an array of PackageDocImpl representing the imported packages. |
|
1131 |
* |
|
1132 |
* ###NOTE: the syntax supports importing all inner classes from a class as well. |
|
1133 |
* @deprecated Import declarations are implementation details that |
|
1134 |
* should not be exposed here. In addition, this method's |
|
1135 |
* return type does not allow for all type-import-on-demand |
|
1136 |
* declarations to be returned. |
|
1137 |
*/ |
|
1138 |
@Deprecated |
|
1139 |
public PackageDoc[] importedPackages() { |
|
1140 |
// information is not available for binary classfiles |
|
1141 |
if (tsym.sourcefile == null) return new PackageDoc[0]; |
|
1142 |
||
22163 | 1143 |
ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<>(); |
10 | 1144 |
|
1145 |
//### Add the implicit "import java.lang.*" to the result |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
10
diff
changeset
|
1146 |
Names names = tsym.name.table.names; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22165
diff
changeset
|
1147 |
importedPackages.append(env.getPackageDoc(env.syms.enterPackage(names.java_lang))); |
10 | 1148 |
|
1149 |
Env<AttrContext> compenv = env.enter.getEnv(tsym); |
|
1150 |
if (compenv == null) return new PackageDocImpl[0]; |
|
1151 |
||
1152 |
for (JCTree t : compenv.toplevel.defs) { |
|
10950 | 1153 |
if (t.hasTag(IMPORT)) { |
10 | 1154 |
JCTree imp = ((JCImport) t).qualid; |
1155 |
if (TreeInfo.name(imp) == names.asterisk) { |
|
1156 |
JCFieldAccess sel = (JCFieldAccess)imp; |
|
1157 |
Symbol s = sel.selected.type.tsym; |
|
1158 |
PackageDocImpl pdoc = env.getPackageDoc(s.packge()); |
|
1159 |
if (!importedPackages.contains(pdoc)) |
|
1160 |
importedPackages.append(pdoc); |
|
1161 |
} |
|
1162 |
} |
|
1163 |
} |
|
1164 |
||
1165 |
return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]); |
|
1166 |
} |
|
1167 |
||
1168 |
/** |
|
1169 |
* Return the type's dimension information. |
|
1170 |
* Always return "", as this is not an array type. |
|
1171 |
*/ |
|
1172 |
public String dimension() { |
|
1173 |
return ""; |
|
1174 |
} |
|
1175 |
||
1176 |
/** |
|
1177 |
* Return this type as a class, which it already is. |
|
1178 |
*/ |
|
1179 |
public ClassDoc asClassDoc() { |
|
1180 |
return this; |
|
1181 |
} |
|
1182 |
||
1183 |
/** |
|
1184 |
* Return null (unless overridden), as this is not an annotation type. |
|
1185 |
*/ |
|
1186 |
public AnnotationTypeDoc asAnnotationTypeDoc() { |
|
1187 |
return null; |
|
1188 |
} |
|
1189 |
||
1190 |
/** |
|
1191 |
* Return null, as this is not a class instantiation. |
|
1192 |
*/ |
|
1193 |
public ParameterizedType asParameterizedType() { |
|
1194 |
return null; |
|
1195 |
} |
|
1196 |
||
1197 |
/** |
|
1198 |
* Return null, as this is not a type variable. |
|
1199 |
*/ |
|
1200 |
public TypeVariable asTypeVariable() { |
|
1201 |
return null; |
|
1202 |
} |
|
1203 |
||
1204 |
/** |
|
1205 |
* Return null, as this is not a wildcard type. |
|
1206 |
*/ |
|
1207 |
public WildcardType asWildcardType() { |
|
1208 |
return null; |
|
1209 |
} |
|
1210 |
||
1211 |
/** |
|
15385 | 1212 |
* Returns null, as this is not an annotated type. |
1213 |
*/ |
|
1214 |
public AnnotatedType asAnnotatedType() { |
|
1215 |
return null; |
|
1216 |
} |
|
1217 |
||
1218 |
/** |
|
10 | 1219 |
* Return false, as this is not a primitive type. |
1220 |
*/ |
|
1221 |
public boolean isPrimitive() { |
|
1222 |
return false; |
|
1223 |
} |
|
1224 |
||
1225 |
//--- Serialization --- |
|
1226 |
||
1227 |
//### These methods ignore modifier filter. |
|
1228 |
||
1229 |
/** |
|
1230 |
* Return true if this class implements <code>java.io.Serializable</code>. |
|
1231 |
* |
|
1232 |
* Since <code>java.io.Externalizable</code> extends |
|
1233 |
* <code>java.io.Serializable</code>, |
|
1234 |
* Externalizable objects are also Serializable. |
|
1235 |
*/ |
|
1236 |
public boolean isSerializable() { |
|
1237 |
try { |
|
1238 |
return env.types.isSubtype(type, env.syms.serializableType); |
|
1239 |
} catch (CompletionFailure ex) { |
|
1240 |
// quietly ignore completion failures |
|
1241 |
return false; |
|
1242 |
} |
|
1243 |
} |
|
1244 |
||
1245 |
/** |
|
1246 |
* Return true if this class implements |
|
1247 |
* <code>java.io.Externalizable</code>. |
|
1248 |
*/ |
|
1249 |
public boolean isExternalizable() { |
|
1250 |
try { |
|
1251 |
return env.types.isSubtype(type, env.externalizableSym.type); |
|
1252 |
} catch (CompletionFailure ex) { |
|
1253 |
// quietly ignore completion failures |
|
1254 |
return false; |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
/** |
|
1259 |
* Return the serialization methods for this class. |
|
1260 |
* |
|
1261 |
* @return an array of <code>MethodDocImpl</code> that represents |
|
1262 |
* the serialization methods for this class. |
|
1263 |
*/ |
|
1264 |
public MethodDoc[] serializationMethods() { |
|
1265 |
if (serializedForm == null) { |
|
1266 |
serializedForm = new SerializedForm(env, tsym, this); |
|
1267 |
} |
|
1268 |
//### Clone this? |
|
1269 |
return serializedForm.methods(); |
|
1270 |
} |
|
1271 |
||
1272 |
/** |
|
1273 |
* Return the Serializable fields of class.<p> |
|
1274 |
* |
|
1275 |
* Return either a list of default fields documented by |
|
1276 |
* <code>serial</code> tag<br> |
|
1277 |
* or return a single <code>FieldDoc</code> for |
|
1278 |
* <code>serialPersistentField</code> member. |
|
1279 |
* There should be a <code>serialField</code> tag for |
|
1280 |
* each Serializable field defined by an <code>ObjectStreamField</code> |
|
1281 |
* array component of <code>serialPersistentField</code>. |
|
1282 |
* |
|
1283 |
* @returns an array of <code>FieldDoc</code> for the Serializable fields |
|
1284 |
* of this class. |
|
1285 |
* |
|
1286 |
* @see #definesSerializableFields() |
|
1287 |
* @see SerialFieldTagImpl |
|
1288 |
*/ |
|
1289 |
public FieldDoc[] serializableFields() { |
|
1290 |
if (serializedForm == null) { |
|
1291 |
serializedForm = new SerializedForm(env, tsym, this); |
|
1292 |
} |
|
1293 |
//### Clone this? |
|
1294 |
return serializedForm.fields(); |
|
1295 |
} |
|
1296 |
||
1297 |
/** |
|
1298 |
* Return true if Serializable fields are explicitly defined with |
|
1299 |
* the special class member <code>serialPersistentFields</code>. |
|
1300 |
* |
|
1301 |
* @see #serializableFields() |
|
1302 |
* @see SerialFieldTagImpl |
|
1303 |
*/ |
|
1304 |
public boolean definesSerializableFields() { |
|
1305 |
if (!isSerializable() || isExternalizable()) { |
|
1306 |
return false; |
|
1307 |
} else { |
|
1308 |
if (serializedForm == null) { |
|
1309 |
serializedForm = new SerializedForm(env, tsym, this); |
|
1310 |
} |
|
1311 |
//### Clone this? |
|
1312 |
return serializedForm.definesSerializableFields(); |
|
1313 |
} |
|
1314 |
} |
|
1315 |
||
1316 |
/** |
|
1317 |
* Determine if a class is a RuntimeException. |
|
1318 |
* <p> |
|
1319 |
* Used only by ThrowsTagImpl. |
|
1320 |
*/ |
|
1321 |
boolean isRuntimeException() { |
|
1322 |
return tsym.isSubClass(env.syms.runtimeExceptionType.tsym, env.types); |
|
1323 |
} |
|
1324 |
||
1325 |
/** |
|
1326 |
* Return the source position of the entity, or null if |
|
1327 |
* no position is available. |
|
1328 |
*/ |
|
8631
664f84942e74
6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents:
7681
diff
changeset
|
1329 |
@Override |
10 | 1330 |
public SourcePosition position() { |
1331 |
if (tsym.sourcefile == null) return null; |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1264
diff
changeset
|
1332 |
return SourcePositionImpl.make(tsym.sourcefile, |
10 | 1333 |
(tree==null) ? Position.NOPOS : tree.pos, |
1334 |
lineMap); |
|
1335 |
} |
|
1336 |
} |