author | bpatel |
Mon, 02 May 2011 02:13:02 -0700 | |
changeset 9606 | e5a619cb5dd3 |
parent 5520 | 86e4b9a9da40 |
child 14258 | 8d2148961366 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 1998, 2011, 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.doclets.internal.toolkit.util; |
|
27 |
||
28 |
import com.sun.tools.doclets.internal.toolkit.*; |
|
29 |
import com.sun.javadoc.*; |
|
30 |
import java.util.*; |
|
31 |
||
32 |
/** |
|
33 |
* Build Class Hierarchy for all the Classes. This class builds the Class |
|
34 |
* Tree and the Interface Tree separately. |
|
35 |
* |
|
36 |
* This code is not part of an API. |
|
37 |
* It is implementation that is subject to change. |
|
38 |
* Do not use it as an API |
|
39 |
* |
|
40 |
* @see java.util.HashMap |
|
41 |
* @see java.util.List |
|
42 |
* @see com.sun.javadoc.Type |
|
43 |
* @see com.sun.javadoc.ClassDoc |
|
44 |
* @author Atul M Dambalkar |
|
45 |
*/ |
|
46 |
public class ClassTree { |
|
47 |
||
48 |
/** |
|
49 |
* List of baseclasses. Contains only java.lang.Object. Can be used to get |
|
50 |
* the mapped listing of sub-classes. |
|
51 |
*/ |
|
868 | 52 |
private List<ClassDoc> baseclasses = new ArrayList<ClassDoc>(); |
10 | 53 |
|
54 |
/** |
|
55 |
* Mapping for each Class with their SubClasses |
|
56 |
*/ |
|
868 | 57 |
private Map<ClassDoc,List<ClassDoc>> subclasses = new HashMap<ClassDoc,List<ClassDoc>>(); |
10 | 58 |
|
59 |
/** |
|
60 |
* List of base-interfaces. Contains list of all the interfaces who do not |
|
61 |
* have super-interfaces. Can be used to get the mapped listing of |
|
62 |
* sub-interfaces. |
|
63 |
*/ |
|
868 | 64 |
private List<ClassDoc> baseinterfaces = new ArrayList<ClassDoc>(); |
10 | 65 |
|
66 |
/** |
|
67 |
* Mapping for each Interface with their SubInterfaces |
|
68 |
*/ |
|
868 | 69 |
private Map<ClassDoc,List<ClassDoc>> subinterfaces = new HashMap<ClassDoc,List<ClassDoc>>(); |
10 | 70 |
|
868 | 71 |
private List<ClassDoc> baseEnums = new ArrayList<ClassDoc>(); |
72 |
private Map<ClassDoc,List<ClassDoc>> subEnums = new HashMap<ClassDoc,List<ClassDoc>>(); |
|
10 | 73 |
|
868 | 74 |
private List<ClassDoc> baseAnnotationTypes = new ArrayList<ClassDoc>(); |
75 |
private Map<ClassDoc,List<ClassDoc>> subAnnotationTypes = new HashMap<ClassDoc,List<ClassDoc>>(); |
|
10 | 76 |
|
77 |
/** |
|
78 |
* Mapping for each Interface with classes who implement it. |
|
79 |
*/ |
|
868 | 80 |
private Map<ClassDoc,List<ClassDoc>> implementingclasses = new HashMap<ClassDoc,List<ClassDoc>>(); |
10 | 81 |
|
82 |
/** |
|
83 |
* Constructor. Build the Tree using the Root of this Javadoc run. |
|
84 |
* |
|
85 |
* @param configuration the configuration of the doclet. |
|
86 |
* @param noDeprecated Don't add deprecated classes in the class tree, if |
|
87 |
* true. |
|
88 |
*/ |
|
89 |
public ClassTree(Configuration configuration, boolean noDeprecated) { |
|
90 |
configuration.message.notice("doclet.Building_Tree"); |
|
91 |
buildTree(configuration.root.classes(), configuration); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* Constructor. Build the Tree using the Root of this Javadoc run. |
|
96 |
* |
|
97 |
* @param root Root of the Document. |
|
98 |
* @param configuration The curren configuration of the doclet. |
|
99 |
*/ |
|
100 |
public ClassTree(RootDoc root, Configuration configuration) { |
|
101 |
buildTree(root.classes(), configuration); |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Constructor. Build the tree for the given array of classes. |
|
106 |
* |
|
107 |
* @param classes Array of classes. |
|
108 |
* @param configuration The curren configuration of the doclet. |
|
109 |
*/ |
|
110 |
public ClassTree(ClassDoc[] classes, Configuration configuration) { |
|
111 |
buildTree(classes, configuration); |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Generate mapping for the sub-classes for every class in this run. |
|
116 |
* Return the sub-class list for java.lang.Object which will be having |
|
117 |
* sub-class listing for itself and also for each sub-class itself will |
|
118 |
* have their own sub-class lists. |
|
119 |
* |
|
120 |
* @param classes all the classes in this run. |
|
121 |
* @param configuration the current configuration of the doclet. |
|
122 |
*/ |
|
123 |
private void buildTree(ClassDoc[] classes, Configuration configuration) { |
|
124 |
for (int i = 0; i < classes.length; i++) { |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
125 |
// In the tree page (e.g overview-tree.html) do not include |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
126 |
// information of classes which are deprecated or are a part of a |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
127 |
// deprecated package. |
10 | 128 |
if (configuration.nodeprecated && |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
129 |
(Util.isDeprecated(classes[i]) || |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
5520
diff
changeset
|
130 |
Util.isDeprecated(classes[i].containingPackage()))) { |
10 | 131 |
continue; |
132 |
} |
|
133 |
if (classes[i].isEnum()) { |
|
134 |
processType(classes[i], configuration, baseEnums, subEnums); |
|
135 |
} else if (classes[i].isClass()) { |
|
136 |
processType(classes[i], configuration, baseclasses, subclasses); |
|
137 |
} else if (classes[i].isInterface()) { |
|
138 |
processInterface(classes[i]); |
|
868 | 139 |
List<ClassDoc> list = implementingclasses.get(classes[i]); |
10 | 140 |
if (list != null) { |
141 |
Collections.sort(list); |
|
142 |
} |
|
143 |
} else if (classes[i].isAnnotationType()) { |
|
144 |
processType(classes[i], configuration, baseAnnotationTypes, |
|
145 |
subAnnotationTypes); |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
Collections.sort(baseinterfaces); |
|
868 | 150 |
for (Iterator<List<ClassDoc>> it = subinterfaces.values().iterator(); it.hasNext(); ) { |
151 |
Collections.sort(it.next()); |
|
10 | 152 |
} |
868 | 153 |
for (Iterator<List<ClassDoc>> it = subclasses.values().iterator(); it.hasNext(); ) { |
154 |
Collections.sort(it.next()); |
|
10 | 155 |
} |
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* For the class passed map it to it's own sub-class listing. |
|
160 |
* For the Class passed, get the super class, |
|
161 |
* if superclass is non null, (it is not "java.lang.Object") |
|
162 |
* get the "value" from the hashmap for this key Class |
|
163 |
* if entry not found create one and get that. |
|
164 |
* add this Class as a sub class in the list |
|
165 |
* Recurse till hits java.lang.Object Null SuperClass. |
|
166 |
* |
|
167 |
* @param cd class for which sub-class mapping to be generated. |
|
168 |
* @param configuration the current configurtation of the doclet. |
|
169 |
*/ |
|
170 |
private void processType(ClassDoc cd, Configuration configuration, |
|
868 | 171 |
List<ClassDoc> bases, Map<ClassDoc,List<ClassDoc>> subs) { |
10 | 172 |
ClassDoc superclass = Util.getFirstVisibleSuperClassCD(cd, configuration); |
173 |
if (superclass != null) { |
|
174 |
if (!add(subs, superclass, cd)) { |
|
175 |
return; |
|
176 |
} else { |
|
177 |
processType(superclass, configuration, bases, subs); |
|
178 |
} |
|
179 |
} else { // cd is java.lang.Object, add it once to the list |
|
180 |
if (!bases.contains(cd)) { |
|
181 |
bases.add(cd); |
|
182 |
} |
|
183 |
} |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
184 |
List<Type> intfacs = Util.getAllInterfaces(cd, configuration); |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
185 |
for (Iterator<Type> iter = intfacs.iterator(); iter.hasNext();) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
186 |
add(implementingclasses, iter.next().asClassDoc(), cd); |
10 | 187 |
} |
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* For the interface passed get the interfaces which it extends, and then |
|
192 |
* put this interface in the sub-interface list of those interfaces. Do it |
|
193 |
* recursively. If a interface doesn't have super-interface just attach |
|
194 |
* that interface in the list of all the baseinterfaces. |
|
195 |
* |
|
196 |
* @param cd Interface under consideration. |
|
197 |
*/ |
|
198 |
private void processInterface(ClassDoc cd) { |
|
199 |
ClassDoc[] intfacs = cd.interfaces(); |
|
200 |
if (intfacs.length > 0) { |
|
201 |
for (int i = 0; i < intfacs.length; i++) { |
|
202 |
if (!add(subinterfaces, intfacs[i], cd)) { |
|
203 |
return; |
|
204 |
} else { |
|
205 |
processInterface(intfacs[i]); // Recurse |
|
206 |
} |
|
207 |
} |
|
208 |
} else { |
|
209 |
// we need to add all the interfaces who do not have |
|
210 |
// super-interfaces to baseinterfaces list to traverse them |
|
211 |
if (!baseinterfaces.contains(cd)) { |
|
212 |
baseinterfaces.add(cd); |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
* Adjust the Class Tree. Add the class interface in to it's super-class' |
|
219 |
* or super-interface's sub-interface list. |
|
220 |
* |
|
221 |
* @param map the entire map. |
|
222 |
* @param superclass java.lang.Object or the super-interface. |
|
223 |
* @param cd sub-interface to be mapped. |
|
224 |
* @returns boolean true if class added, false if class already processed. |
|
225 |
*/ |
|
868 | 226 |
private boolean add(Map<ClassDoc,List<ClassDoc>> map, ClassDoc superclass, ClassDoc cd) { |
227 |
List<ClassDoc> list = map.get(superclass); |
|
10 | 228 |
if (list == null) { |
868 | 229 |
list = new ArrayList<ClassDoc>(); |
10 | 230 |
map.put(superclass, list); |
231 |
} |
|
232 |
if (list.contains(cd)) { |
|
233 |
return false; |
|
234 |
} else { |
|
235 |
list.add(cd); |
|
236 |
} |
|
237 |
return true; |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* From the map return the list of sub-classes or sub-interfaces. If list |
|
242 |
* is null create a new one and return it. |
|
243 |
* |
|
244 |
* @param map The entire map. |
|
245 |
* @param cd class for which the sub-class list is requested. |
|
246 |
* @returns List Sub-Class list for the class passed. |
|
247 |
*/ |
|
868 | 248 |
private List<ClassDoc> get(Map<ClassDoc,List<ClassDoc>> map, ClassDoc cd) { |
249 |
List<ClassDoc> list = map.get(cd); |
|
10 | 250 |
if (list == null) { |
868 | 251 |
return new ArrayList<ClassDoc>(); |
10 | 252 |
} |
253 |
return list; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Return the sub-class list for the class passed. |
|
258 |
* |
|
259 |
* @param cd class whose sub-class list is required. |
|
260 |
*/ |
|
868 | 261 |
public List<ClassDoc> subclasses(ClassDoc cd) { |
10 | 262 |
return get(subclasses, cd); |
263 |
} |
|
264 |
||
265 |
/** |
|
266 |
* Return the sub-interface list for the interface passed. |
|
267 |
* |
|
268 |
* @param cd interface whose sub-interface list is required. |
|
269 |
*/ |
|
868 | 270 |
public List<ClassDoc> subinterfaces(ClassDoc cd) { |
10 | 271 |
return get(subinterfaces, cd); |
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* Return the list of classes which implement the interface passed. |
|
276 |
* |
|
277 |
* @param cd interface whose implementing-classes list is required. |
|
278 |
*/ |
|
868 | 279 |
public List<ClassDoc> implementingclasses(ClassDoc cd) { |
280 |
List<ClassDoc> result = get(implementingclasses, cd); |
|
281 |
List<ClassDoc> subinterfaces = allSubs(cd, false); |
|
10 | 282 |
|
283 |
//If class x implements a subinterface of cd, then it follows |
|
284 |
//that class x implements cd. |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
285 |
Iterator<ClassDoc> implementingClassesIter, subInterfacesIter = subinterfaces.listIterator(); |
10 | 286 |
ClassDoc c; |
287 |
while(subInterfacesIter.hasNext()){ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
288 |
implementingClassesIter = implementingclasses( |
10 | 289 |
subInterfacesIter.next()).listIterator(); |
290 |
while(implementingClassesIter.hasNext()){ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
291 |
c = implementingClassesIter.next(); |
10 | 292 |
if(! result.contains(c)){ |
293 |
result.add(c); |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
Collections.sort(result); |
|
298 |
return result; |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Return the sub-class/interface list for the class/interface passed. |
|
303 |
* |
|
304 |
* @param cd class/interface whose sub-class/interface list is required. |
|
305 |
* @param isEnum true if the subclasses should be forced to come from the |
|
306 |
* enum tree. |
|
307 |
*/ |
|
868 | 308 |
public List<ClassDoc> subs(ClassDoc cd, boolean isEnum) { |
10 | 309 |
if (isEnum) { |
310 |
return get(subEnums, cd); |
|
311 |
} else if (cd.isAnnotationType()) { |
|
312 |
return get(subAnnotationTypes, cd); |
|
313 |
} else if (cd.isInterface()) { |
|
314 |
return get(subinterfaces, cd); |
|
315 |
} else if (cd.isClass()) { |
|
316 |
return get(subclasses, cd); |
|
317 |
} else { |
|
318 |
return null; |
|
319 |
} |
|
320 |
||
321 |
} |
|
322 |
||
323 |
/** |
|
324 |
* Return a list of all direct or indirect, sub-classes and subinterfaces |
|
325 |
* of the ClassDoc argument. |
|
326 |
* |
|
327 |
* @param cd ClassDoc whose sub-classes or sub-interfaces are requested. |
|
328 |
* @param isEnum true if the subclasses should be forced to come from the |
|
329 |
* enum tree. |
|
330 |
*/ |
|
868 | 331 |
public List<ClassDoc> allSubs(ClassDoc cd, boolean isEnum) { |
332 |
List<ClassDoc> list = subs(cd, isEnum); |
|
10 | 333 |
for (int i = 0; i < list.size(); i++) { |
868 | 334 |
cd = list.get(i); |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
335 |
List<ClassDoc> tlist = subs(cd, isEnum); |
10 | 336 |
for (int j = 0; j < tlist.size(); j++) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
337 |
ClassDoc tcd = tlist.get(j); |
10 | 338 |
if (!list.contains(tcd)) { |
339 |
list.add(tcd); |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
Collections.sort(list); |
|
344 |
return list; |
|
345 |
} |
|
346 |
||
347 |
/** |
|
348 |
* Return the base-classes list. This will have only one element namely |
|
349 |
* thw classdoc for java.lang.Object, since this is the base class for all |
|
350 |
* classes. |
|
351 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
352 |
public List<ClassDoc> baseclasses() { |
10 | 353 |
return baseclasses; |
354 |
} |
|
355 |
||
356 |
/** |
|
357 |
* Return the list of base interfaces. This is the list of interfaces |
|
358 |
* which do not have super-interface. |
|
359 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
360 |
public List<ClassDoc> baseinterfaces() { |
10 | 361 |
return baseinterfaces; |
362 |
} |
|
363 |
||
364 |
/** |
|
365 |
* Return the list of base enums. This is the list of enums |
|
366 |
* which do not have super-enums. |
|
367 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
368 |
public List<ClassDoc> baseEnums() { |
10 | 369 |
return baseEnums; |
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Return the list of base annotation types. This is the list of |
|
374 |
* annotation types which do not have super-annotation types. |
|
375 |
*/ |
|
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
376 |
public List<ClassDoc> baseAnnotationTypes() { |
10 | 377 |
return baseAnnotationTypes; |
378 |
} |
|
379 |
} |