Tue, 09 Oct 2012 19:31:58 -0700
8000208: fix langtools javadoc comment issues
Reviewed-by: bpatel, mcimadamore
duke@1 | 1 | /* |
jjg@1358 | 2 | * Copyright (c) 2001, 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 | |
bpatel@995 | 28 | import java.util.*; |
duke@1 | 29 | import com.sun.javadoc.*; |
bpatel@995 | 30 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
duke@1 | 31 | |
duke@1 | 32 | /** |
duke@1 | 33 | * This class acts as an artificial PackageDoc for classes specified |
duke@1 | 34 | * on the command line when running Javadoc. For example, if you |
duke@1 | 35 | * specify several classes from package java.lang, this class will catalog |
duke@1 | 36 | * those classes so that we can retrieve all of the classes from a particular |
duke@1 | 37 | * package later. |
duke@1 | 38 | * |
duke@1 | 39 | * This code is not part of an API. |
duke@1 | 40 | * It is implementation that is subject to change. |
duke@1 | 41 | * Do not use it as an API |
duke@1 | 42 | * |
duke@1 | 43 | * @author Jamie Ho |
duke@1 | 44 | * @since 1.4 |
duke@1 | 45 | */ |
duke@1 | 46 | |
duke@1 | 47 | public class ClassDocCatalog { |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * Stores the set of packages that the classes specified on the command line |
duke@1 | 51 | * belong to. Note that the default package is "". |
duke@1 | 52 | */ |
jjg@74 | 53 | private Set<String> packageSet; |
duke@1 | 54 | |
duke@1 | 55 | |
duke@1 | 56 | /** |
duke@1 | 57 | * Stores all classes for each package |
duke@1 | 58 | */ |
jjg@74 | 59 | private Map<String,Set<ClassDoc>> allClasses; |
duke@1 | 60 | |
duke@1 | 61 | /** |
duke@1 | 62 | * Stores ordinary classes (excluding Exceptions and Errors) for each |
duke@1 | 63 | * package |
duke@1 | 64 | */ |
jjg@74 | 65 | private Map<String,Set<ClassDoc>> ordinaryClasses; |
duke@1 | 66 | |
duke@1 | 67 | /** |
duke@1 | 68 | * Stores exceptions for each package |
duke@1 | 69 | */ |
jjg@74 | 70 | private Map<String,Set<ClassDoc>> exceptions; |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Stores enums for each package. |
duke@1 | 74 | */ |
jjg@74 | 75 | private Map<String,Set<ClassDoc>> enums; |
duke@1 | 76 | |
duke@1 | 77 | /** |
duke@1 | 78 | * Stores annotation types for each package. |
duke@1 | 79 | */ |
jjg@74 | 80 | private Map<String,Set<ClassDoc>> annotationTypes; |
duke@1 | 81 | |
duke@1 | 82 | /** |
duke@1 | 83 | * Stores errors for each package |
duke@1 | 84 | */ |
jjg@74 | 85 | private Map<String,Set<ClassDoc>> errors; |
duke@1 | 86 | |
duke@1 | 87 | /** |
duke@1 | 88 | * Stores interfaces for each package |
duke@1 | 89 | */ |
jjg@74 | 90 | private Map<String,Set<ClassDoc>> interfaces; |
duke@1 | 91 | |
bpatel@995 | 92 | private Configuration configuration; |
bpatel@995 | 93 | |
duke@1 | 94 | /** |
duke@1 | 95 | * Construct a new ClassDocCatalog. |
duke@1 | 96 | * |
duke@1 | 97 | * @param classdocs the array of ClassDocs to catalog |
duke@1 | 98 | */ |
bpatel@995 | 99 | public ClassDocCatalog (ClassDoc[] classdocs, Configuration config) { |
duke@1 | 100 | init(); |
bpatel@995 | 101 | this.configuration = config; |
duke@1 | 102 | for (int i = 0; i < classdocs.length; i++) { |
duke@1 | 103 | addClassDoc(classdocs[i]); |
duke@1 | 104 | } |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Construct a new ClassDocCatalog. |
duke@1 | 109 | * |
duke@1 | 110 | */ |
duke@1 | 111 | public ClassDocCatalog () { |
duke@1 | 112 | init(); |
duke@1 | 113 | } |
duke@1 | 114 | |
duke@1 | 115 | private void init() { |
jjg@74 | 116 | allClasses = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 117 | ordinaryClasses = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 118 | exceptions = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 119 | enums = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 120 | annotationTypes = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 121 | errors = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 122 | interfaces = new HashMap<String,Set<ClassDoc>>(); |
jjg@74 | 123 | packageSet = new HashSet<String>(); |
duke@1 | 124 | } |
duke@1 | 125 | |
duke@1 | 126 | /** |
duke@1 | 127 | * Add the given class to the catalog. |
duke@1 | 128 | * @param classdoc the ClassDoc to add to the catelog. |
duke@1 | 129 | */ |
duke@1 | 130 | public void addClassDoc(ClassDoc classdoc) { |
duke@1 | 131 | if (classdoc == null) { |
duke@1 | 132 | return; |
duke@1 | 133 | } |
duke@1 | 134 | addClass(classdoc, allClasses); |
duke@1 | 135 | if (classdoc.isOrdinaryClass()) { |
duke@1 | 136 | addClass(classdoc, ordinaryClasses); |
duke@1 | 137 | } else if (classdoc.isException()) { |
duke@1 | 138 | addClass(classdoc, exceptions); |
duke@1 | 139 | } else if (classdoc.isEnum()) { |
duke@1 | 140 | addClass(classdoc, enums); |
duke@1 | 141 | } else if (classdoc.isAnnotationType()) { |
duke@1 | 142 | addClass(classdoc, annotationTypes); |
duke@1 | 143 | } else if (classdoc.isError()) { |
duke@1 | 144 | addClass(classdoc, errors); |
duke@1 | 145 | } else if (classdoc.isInterface()) { |
duke@1 | 146 | addClass(classdoc, interfaces); |
duke@1 | 147 | } |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** |
duke@1 | 151 | * Add the given class to the given map. |
duke@1 | 152 | * @param classdoc the ClassDoc to add to the catelog. |
duke@1 | 153 | * @param map the Map to add the ClassDoc to. |
duke@1 | 154 | */ |
jjg@74 | 155 | private void addClass(ClassDoc classdoc, Map<String,Set<ClassDoc>> map) { |
duke@1 | 156 | |
duke@1 | 157 | PackageDoc pkg = classdoc.containingPackage(); |
bpatel@995 | 158 | if (pkg.isIncluded() || (configuration.nodeprecated && Util.isDeprecated(pkg))) { |
bpatel@995 | 159 | //No need to catalog this class if it's package is |
bpatel@995 | 160 | //included on the command line or if -nodeprecated option is set |
bpatel@995 | 161 | // and the containing package is marked as deprecated. |
duke@1 | 162 | return; |
duke@1 | 163 | } |
duke@1 | 164 | String key = Util.getPackageName(pkg); |
jjg@74 | 165 | Set<ClassDoc> s = map.get(key); |
duke@1 | 166 | if (s == null) { |
duke@1 | 167 | packageSet.add(key); |
jjg@74 | 168 | s = new HashSet<ClassDoc>(); |
duke@1 | 169 | } |
duke@1 | 170 | s.add(classdoc); |
duke@1 | 171 | map.put(key, s); |
duke@1 | 172 | |
duke@1 | 173 | } |
duke@1 | 174 | |
jjg@74 | 175 | private ClassDoc[] getArray(Map<String,Set<ClassDoc>> m, String key) { |
jjg@74 | 176 | Set<ClassDoc> s = m.get(key); |
duke@1 | 177 | if (s == null) { |
duke@1 | 178 | return new ClassDoc[] {}; |
duke@1 | 179 | } else { |
jjg@74 | 180 | return s.toArray(new ClassDoc[] {}); |
duke@1 | 181 | } |
duke@1 | 182 | } |
duke@1 | 183 | |
duke@1 | 184 | /** |
duke@1 | 185 | * Return all of the classes specified on the command-line that |
duke@1 | 186 | * belong to the given package. |
jjg@1358 | 187 | * @param pkgDoc the package to return the classes for. |
duke@1 | 188 | */ |
duke@1 | 189 | public ClassDoc[] allClasses(PackageDoc pkgDoc) { |
duke@1 | 190 | return pkgDoc.isIncluded() ? |
duke@1 | 191 | pkgDoc.allClasses() : |
duke@1 | 192 | getArray(allClasses, Util.getPackageName(pkgDoc)); |
duke@1 | 193 | } |
duke@1 | 194 | |
duke@1 | 195 | /** |
duke@1 | 196 | * Return all of the classes specified on the command-line that |
duke@1 | 197 | * belong to the given package. |
duke@1 | 198 | * @param packageName the name of the package specified on the |
duke@1 | 199 | * command-line. |
duke@1 | 200 | */ |
duke@1 | 201 | public ClassDoc[] allClasses(String packageName) { |
duke@1 | 202 | return getArray(allClasses, packageName); |
duke@1 | 203 | } |
duke@1 | 204 | |
duke@1 | 205 | /** |
duke@1 | 206 | * Return the array of package names that this catalog stores |
duke@1 | 207 | * ClassDocs for. |
duke@1 | 208 | */ |
duke@1 | 209 | public String[] packageNames() { |
jjg@74 | 210 | return packageSet.toArray(new String[] {}); |
duke@1 | 211 | } |
duke@1 | 212 | |
duke@1 | 213 | /** |
duke@1 | 214 | * Return true if the given package is known to this catalog. |
duke@1 | 215 | * @param packageName the name to check. |
duke@1 | 216 | * @return true if this catalog has any information about |
duke@1 | 217 | * classes in the given package. |
duke@1 | 218 | */ |
duke@1 | 219 | public boolean isKnownPackage(String packageName) { |
duke@1 | 220 | return packageSet.contains(packageName); |
duke@1 | 221 | } |
duke@1 | 222 | |
duke@1 | 223 | |
duke@1 | 224 | /** |
duke@1 | 225 | * Return all of the errors specified on the command-line |
duke@1 | 226 | * that belong to the given package. |
duke@1 | 227 | * @param packageName the name of the package specified on the |
duke@1 | 228 | * command-line. |
duke@1 | 229 | */ |
duke@1 | 230 | public ClassDoc[] errors(String packageName) { |
duke@1 | 231 | return getArray(errors, packageName); |
duke@1 | 232 | } |
duke@1 | 233 | |
duke@1 | 234 | /** |
duke@1 | 235 | * Return all of the exceptions specified on the command-line |
duke@1 | 236 | * that belong to the given package. |
duke@1 | 237 | * @param packageName the name of the package specified on the |
duke@1 | 238 | * command-line. |
duke@1 | 239 | */ |
duke@1 | 240 | public ClassDoc[] exceptions(String packageName) { |
duke@1 | 241 | return getArray(exceptions, packageName); |
duke@1 | 242 | } |
duke@1 | 243 | |
duke@1 | 244 | /** |
duke@1 | 245 | * Return all of the enums specified on the command-line |
duke@1 | 246 | * that belong to the given package. |
duke@1 | 247 | * @param packageName the name of the package specified on the |
duke@1 | 248 | * command-line. |
duke@1 | 249 | */ |
duke@1 | 250 | public ClassDoc[] enums(String packageName) { |
duke@1 | 251 | return getArray(enums, packageName); |
duke@1 | 252 | } |
duke@1 | 253 | |
duke@1 | 254 | /** |
duke@1 | 255 | * Return all of the annotation types specified on the command-line |
duke@1 | 256 | * that belong to the given package. |
duke@1 | 257 | * @param packageName the name of the package specified on the |
duke@1 | 258 | * command-line. |
duke@1 | 259 | */ |
duke@1 | 260 | public ClassDoc[] annotationTypes(String packageName) { |
duke@1 | 261 | return getArray(annotationTypes, packageName); |
duke@1 | 262 | } |
duke@1 | 263 | |
duke@1 | 264 | /** |
duke@1 | 265 | * Return all of the interfaces specified on the command-line |
duke@1 | 266 | * that belong to the given package. |
duke@1 | 267 | * @param packageName the name of the package specified on the |
duke@1 | 268 | * command-line. |
duke@1 | 269 | */ |
duke@1 | 270 | public ClassDoc[] interfaces(String packageName) { |
duke@1 | 271 | return getArray(interfaces, packageName); |
duke@1 | 272 | } |
duke@1 | 273 | |
duke@1 | 274 | /** |
duke@1 | 275 | * Return all of the ordinary classes specified on the command-line |
duke@1 | 276 | * that belong to the given package. |
duke@1 | 277 | * @param packageName the name of the package specified on the |
duke@1 | 278 | * command-line. |
duke@1 | 279 | */ |
duke@1 | 280 | public ClassDoc[] ordinaryClasses(String packageName) { |
duke@1 | 281 | return getArray(ordinaryClasses, packageName); |
duke@1 | 282 | } |
duke@1 | 283 | } |