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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1359
25e14ad23cef
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.internal.toolkit.util;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29 import com.sun.javadoc.*;
aoqi@0 30 import com.sun.tools.doclets.internal.toolkit.Configuration;
aoqi@0 31
aoqi@0 32 /**
aoqi@0 33 * This class acts as an artificial PackageDoc for classes specified
aoqi@0 34 * on the command line when running Javadoc. For example, if you
aoqi@0 35 * specify several classes from package java.lang, this class will catalog
aoqi@0 36 * those classes so that we can retrieve all of the classes from a particular
aoqi@0 37 * package later.
aoqi@0 38 *
aoqi@0 39 * <p><b>This is NOT part of any supported API.
aoqi@0 40 * If you write code that depends on this, you do so at your own risk.
aoqi@0 41 * This code and its internal interfaces are subject to change or
aoqi@0 42 * deletion without notice.</b>
aoqi@0 43 *
aoqi@0 44 * @author Jamie Ho
aoqi@0 45 * @since 1.4
aoqi@0 46 */
aoqi@0 47
aoqi@0 48 public class ClassDocCatalog {
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * Stores the set of packages that the classes specified on the command line
aoqi@0 52 * belong to. Note that the default package is "".
aoqi@0 53 */
aoqi@0 54 private Set<String> packageSet;
aoqi@0 55
aoqi@0 56
aoqi@0 57 /**
aoqi@0 58 * Stores all classes for each package
aoqi@0 59 */
aoqi@0 60 private Map<String,Set<ClassDoc>> allClasses;
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * Stores ordinary classes (excluding Exceptions and Errors) for each
aoqi@0 64 * package
aoqi@0 65 */
aoqi@0 66 private Map<String,Set<ClassDoc>> ordinaryClasses;
aoqi@0 67
aoqi@0 68 /**
aoqi@0 69 * Stores exceptions for each package
aoqi@0 70 */
aoqi@0 71 private Map<String,Set<ClassDoc>> exceptions;
aoqi@0 72
aoqi@0 73 /**
aoqi@0 74 * Stores enums for each package.
aoqi@0 75 */
aoqi@0 76 private Map<String,Set<ClassDoc>> enums;
aoqi@0 77
aoqi@0 78 /**
aoqi@0 79 * Stores annotation types for each package.
aoqi@0 80 */
aoqi@0 81 private Map<String,Set<ClassDoc>> annotationTypes;
aoqi@0 82
aoqi@0 83 /**
aoqi@0 84 * Stores errors for each package
aoqi@0 85 */
aoqi@0 86 private Map<String,Set<ClassDoc>> errors;
aoqi@0 87
aoqi@0 88 /**
aoqi@0 89 * Stores interfaces for each package
aoqi@0 90 */
aoqi@0 91 private Map<String,Set<ClassDoc>> interfaces;
aoqi@0 92
aoqi@0 93 private Configuration configuration;
aoqi@0 94
aoqi@0 95 /**
aoqi@0 96 * Construct a new ClassDocCatalog.
aoqi@0 97 *
aoqi@0 98 * @param classdocs the array of ClassDocs to catalog
aoqi@0 99 */
aoqi@0 100 public ClassDocCatalog (ClassDoc[] classdocs, Configuration config) {
aoqi@0 101 init();
aoqi@0 102 this.configuration = config;
aoqi@0 103 for (int i = 0; i < classdocs.length; i++) {
aoqi@0 104 addClassDoc(classdocs[i]);
aoqi@0 105 }
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 /**
aoqi@0 109 * Construct a new ClassDocCatalog.
aoqi@0 110 *
aoqi@0 111 */
aoqi@0 112 public ClassDocCatalog () {
aoqi@0 113 init();
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 private void init() {
aoqi@0 117 allClasses = new HashMap<String,Set<ClassDoc>>();
aoqi@0 118 ordinaryClasses = new HashMap<String,Set<ClassDoc>>();
aoqi@0 119 exceptions = new HashMap<String,Set<ClassDoc>>();
aoqi@0 120 enums = new HashMap<String,Set<ClassDoc>>();
aoqi@0 121 annotationTypes = new HashMap<String,Set<ClassDoc>>();
aoqi@0 122 errors = new HashMap<String,Set<ClassDoc>>();
aoqi@0 123 interfaces = new HashMap<String,Set<ClassDoc>>();
aoqi@0 124 packageSet = new HashSet<String>();
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 /**
aoqi@0 128 * Add the given class to the catalog.
aoqi@0 129 * @param classdoc the ClassDoc to add to the catelog.
aoqi@0 130 */
aoqi@0 131 public void addClassDoc(ClassDoc classdoc) {
aoqi@0 132 if (classdoc == null) {
aoqi@0 133 return;
aoqi@0 134 }
aoqi@0 135 addClass(classdoc, allClasses);
aoqi@0 136 if (classdoc.isOrdinaryClass()) {
aoqi@0 137 addClass(classdoc, ordinaryClasses);
aoqi@0 138 } else if (classdoc.isException()) {
aoqi@0 139 addClass(classdoc, exceptions);
aoqi@0 140 } else if (classdoc.isEnum()) {
aoqi@0 141 addClass(classdoc, enums);
aoqi@0 142 } else if (classdoc.isAnnotationType()) {
aoqi@0 143 addClass(classdoc, annotationTypes);
aoqi@0 144 } else if (classdoc.isError()) {
aoqi@0 145 addClass(classdoc, errors);
aoqi@0 146 } else if (classdoc.isInterface()) {
aoqi@0 147 addClass(classdoc, interfaces);
aoqi@0 148 }
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 /**
aoqi@0 152 * Add the given class to the given map.
aoqi@0 153 * @param classdoc the ClassDoc to add to the catelog.
aoqi@0 154 * @param map the Map to add the ClassDoc to.
aoqi@0 155 */
aoqi@0 156 private void addClass(ClassDoc classdoc, Map<String,Set<ClassDoc>> map) {
aoqi@0 157
aoqi@0 158 PackageDoc pkg = classdoc.containingPackage();
aoqi@0 159 if (pkg.isIncluded() || (configuration.nodeprecated && Util.isDeprecated(pkg))) {
aoqi@0 160 //No need to catalog this class if it's package is
aoqi@0 161 //included on the command line or if -nodeprecated option is set
aoqi@0 162 // and the containing package is marked as deprecated.
aoqi@0 163 return;
aoqi@0 164 }
aoqi@0 165 String key = Util.getPackageName(pkg);
aoqi@0 166 Set<ClassDoc> s = map.get(key);
aoqi@0 167 if (s == null) {
aoqi@0 168 packageSet.add(key);
aoqi@0 169 s = new HashSet<ClassDoc>();
aoqi@0 170 }
aoqi@0 171 s.add(classdoc);
aoqi@0 172 map.put(key, s);
aoqi@0 173
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 private ClassDoc[] getArray(Map<String,Set<ClassDoc>> m, String key) {
aoqi@0 177 Set<ClassDoc> s = m.get(key);
aoqi@0 178 if (s == null) {
aoqi@0 179 return new ClassDoc[] {};
aoqi@0 180 } else {
aoqi@0 181 return s.toArray(new ClassDoc[] {});
aoqi@0 182 }
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 /**
aoqi@0 186 * Return all of the classes specified on the command-line that
aoqi@0 187 * belong to the given package.
aoqi@0 188 * @param pkgDoc the package to return the classes for.
aoqi@0 189 */
aoqi@0 190 public ClassDoc[] allClasses(PackageDoc pkgDoc) {
aoqi@0 191 return pkgDoc.isIncluded() ?
aoqi@0 192 pkgDoc.allClasses() :
aoqi@0 193 getArray(allClasses, Util.getPackageName(pkgDoc));
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 /**
aoqi@0 197 * Return all of the classes specified on the command-line that
aoqi@0 198 * belong to the given package.
aoqi@0 199 * @param packageName the name of the package specified on the
aoqi@0 200 * command-line.
aoqi@0 201 */
aoqi@0 202 public ClassDoc[] allClasses(String packageName) {
aoqi@0 203 return getArray(allClasses, packageName);
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 /**
aoqi@0 207 * Return the array of package names that this catalog stores
aoqi@0 208 * ClassDocs for.
aoqi@0 209 */
aoqi@0 210 public String[] packageNames() {
aoqi@0 211 return packageSet.toArray(new String[] {});
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 /**
aoqi@0 215 * Return true if the given package is known to this catalog.
aoqi@0 216 * @param packageName the name to check.
aoqi@0 217 * @return true if this catalog has any information about
aoqi@0 218 * classes in the given package.
aoqi@0 219 */
aoqi@0 220 public boolean isKnownPackage(String packageName) {
aoqi@0 221 return packageSet.contains(packageName);
aoqi@0 222 }
aoqi@0 223
aoqi@0 224
aoqi@0 225 /**
aoqi@0 226 * Return all of the errors specified on the command-line
aoqi@0 227 * that belong to the given package.
aoqi@0 228 * @param packageName the name of the package specified on the
aoqi@0 229 * command-line.
aoqi@0 230 */
aoqi@0 231 public ClassDoc[] errors(String packageName) {
aoqi@0 232 return getArray(errors, packageName);
aoqi@0 233 }
aoqi@0 234
aoqi@0 235 /**
aoqi@0 236 * Return all of the exceptions specified on the command-line
aoqi@0 237 * that belong to the given package.
aoqi@0 238 * @param packageName the name of the package specified on the
aoqi@0 239 * command-line.
aoqi@0 240 */
aoqi@0 241 public ClassDoc[] exceptions(String packageName) {
aoqi@0 242 return getArray(exceptions, packageName);
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 /**
aoqi@0 246 * Return all of the enums specified on the command-line
aoqi@0 247 * that belong to the given package.
aoqi@0 248 * @param packageName the name of the package specified on the
aoqi@0 249 * command-line.
aoqi@0 250 */
aoqi@0 251 public ClassDoc[] enums(String packageName) {
aoqi@0 252 return getArray(enums, packageName);
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 /**
aoqi@0 256 * Return all of the annotation types specified on the command-line
aoqi@0 257 * that belong to the given package.
aoqi@0 258 * @param packageName the name of the package specified on the
aoqi@0 259 * command-line.
aoqi@0 260 */
aoqi@0 261 public ClassDoc[] annotationTypes(String packageName) {
aoqi@0 262 return getArray(annotationTypes, packageName);
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 /**
aoqi@0 266 * Return all of the interfaces specified on the command-line
aoqi@0 267 * that belong to the given package.
aoqi@0 268 * @param packageName the name of the package specified on the
aoqi@0 269 * command-line.
aoqi@0 270 */
aoqi@0 271 public ClassDoc[] interfaces(String packageName) {
aoqi@0 272 return getArray(interfaces, packageName);
aoqi@0 273 }
aoqi@0 274
aoqi@0 275 /**
aoqi@0 276 * Return all of the ordinary classes specified on the command-line
aoqi@0 277 * that belong to the given package.
aoqi@0 278 * @param packageName the name of the package specified on the
aoqi@0 279 * command-line.
aoqi@0 280 */
aoqi@0 281 public ClassDoc[] ordinaryClasses(String packageName) {
aoqi@0 282 return getArray(ordinaryClasses, packageName);
aoqi@0 283 }
aoqi@0 284 }

mercurial