src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassDocCatalog.java

Mon, 15 Oct 2012 17:07:55 -0700

author
jjg
date
Mon, 15 Oct 2012 17:07:55 -0700
changeset 1364
8db45b13526e
parent 1359
25e14ad23cef
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8000666: javadoc should write directly to Writer instead of composing strings
Reviewed-by: bpatel

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

mercurial