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