1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassDocCatalog.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,284 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.internal.toolkit.util; 1.30 + 1.31 +import java.util.*; 1.32 +import com.sun.javadoc.*; 1.33 +import com.sun.tools.doclets.internal.toolkit.Configuration; 1.34 + 1.35 +/** 1.36 + * This class acts as an artificial PackageDoc for classes specified 1.37 + * on the command line when running Javadoc. For example, if you 1.38 + * specify several classes from package java.lang, this class will catalog 1.39 + * those classes so that we can retrieve all of the classes from a particular 1.40 + * package later. 1.41 + * 1.42 + * <p><b>This is NOT part of any supported API. 1.43 + * If you write code that depends on this, you do so at your own risk. 1.44 + * This code and its internal interfaces are subject to change or 1.45 + * deletion without notice.</b> 1.46 + * 1.47 + * @author Jamie Ho 1.48 + * @since 1.4 1.49 + */ 1.50 + 1.51 + public class ClassDocCatalog { 1.52 + 1.53 + /** 1.54 + * Stores the set of packages that the classes specified on the command line 1.55 + * belong to. Note that the default package is "". 1.56 + */ 1.57 + private Set<String> packageSet; 1.58 + 1.59 + 1.60 + /** 1.61 + * Stores all classes for each package 1.62 + */ 1.63 + private Map<String,Set<ClassDoc>> allClasses; 1.64 + 1.65 + /** 1.66 + * Stores ordinary classes (excluding Exceptions and Errors) for each 1.67 + * package 1.68 + */ 1.69 + private Map<String,Set<ClassDoc>> ordinaryClasses; 1.70 + 1.71 + /** 1.72 + * Stores exceptions for each package 1.73 + */ 1.74 + private Map<String,Set<ClassDoc>> exceptions; 1.75 + 1.76 + /** 1.77 + * Stores enums for each package. 1.78 + */ 1.79 + private Map<String,Set<ClassDoc>> enums; 1.80 + 1.81 + /** 1.82 + * Stores annotation types for each package. 1.83 + */ 1.84 + private Map<String,Set<ClassDoc>> annotationTypes; 1.85 + 1.86 + /** 1.87 + * Stores errors for each package 1.88 + */ 1.89 + private Map<String,Set<ClassDoc>> errors; 1.90 + 1.91 + /** 1.92 + * Stores interfaces for each package 1.93 + */ 1.94 + private Map<String,Set<ClassDoc>> interfaces; 1.95 + 1.96 + private Configuration configuration; 1.97 + 1.98 + /** 1.99 + * Construct a new ClassDocCatalog. 1.100 + * 1.101 + * @param classdocs the array of ClassDocs to catalog 1.102 + */ 1.103 + public ClassDocCatalog (ClassDoc[] classdocs, Configuration config) { 1.104 + init(); 1.105 + this.configuration = config; 1.106 + for (int i = 0; i < classdocs.length; i++) { 1.107 + addClassDoc(classdocs[i]); 1.108 + } 1.109 + } 1.110 + 1.111 + /** 1.112 + * Construct a new ClassDocCatalog. 1.113 + * 1.114 + */ 1.115 + public ClassDocCatalog () { 1.116 + init(); 1.117 + } 1.118 + 1.119 + private void init() { 1.120 + allClasses = new HashMap<String,Set<ClassDoc>>(); 1.121 + ordinaryClasses = new HashMap<String,Set<ClassDoc>>(); 1.122 + exceptions = new HashMap<String,Set<ClassDoc>>(); 1.123 + enums = new HashMap<String,Set<ClassDoc>>(); 1.124 + annotationTypes = new HashMap<String,Set<ClassDoc>>(); 1.125 + errors = new HashMap<String,Set<ClassDoc>>(); 1.126 + interfaces = new HashMap<String,Set<ClassDoc>>(); 1.127 + packageSet = new HashSet<String>(); 1.128 + } 1.129 + 1.130 + /** 1.131 + * Add the given class to the catalog. 1.132 + * @param classdoc the ClassDoc to add to the catelog. 1.133 + */ 1.134 + public void addClassDoc(ClassDoc classdoc) { 1.135 + if (classdoc == null) { 1.136 + return; 1.137 + } 1.138 + addClass(classdoc, allClasses); 1.139 + if (classdoc.isOrdinaryClass()) { 1.140 + addClass(classdoc, ordinaryClasses); 1.141 + } else if (classdoc.isException()) { 1.142 + addClass(classdoc, exceptions); 1.143 + } else if (classdoc.isEnum()) { 1.144 + addClass(classdoc, enums); 1.145 + } else if (classdoc.isAnnotationType()) { 1.146 + addClass(classdoc, annotationTypes); 1.147 + } else if (classdoc.isError()) { 1.148 + addClass(classdoc, errors); 1.149 + } else if (classdoc.isInterface()) { 1.150 + addClass(classdoc, interfaces); 1.151 + } 1.152 + } 1.153 + 1.154 + /** 1.155 + * Add the given class to the given map. 1.156 + * @param classdoc the ClassDoc to add to the catelog. 1.157 + * @param map the Map to add the ClassDoc to. 1.158 + */ 1.159 + private void addClass(ClassDoc classdoc, Map<String,Set<ClassDoc>> map) { 1.160 + 1.161 + PackageDoc pkg = classdoc.containingPackage(); 1.162 + if (pkg.isIncluded() || (configuration.nodeprecated && Util.isDeprecated(pkg))) { 1.163 + //No need to catalog this class if it's package is 1.164 + //included on the command line or if -nodeprecated option is set 1.165 + // and the containing package is marked as deprecated. 1.166 + return; 1.167 + } 1.168 + String key = Util.getPackageName(pkg); 1.169 + Set<ClassDoc> s = map.get(key); 1.170 + if (s == null) { 1.171 + packageSet.add(key); 1.172 + s = new HashSet<ClassDoc>(); 1.173 + } 1.174 + s.add(classdoc); 1.175 + map.put(key, s); 1.176 + 1.177 + } 1.178 + 1.179 + private ClassDoc[] getArray(Map<String,Set<ClassDoc>> m, String key) { 1.180 + Set<ClassDoc> s = m.get(key); 1.181 + if (s == null) { 1.182 + return new ClassDoc[] {}; 1.183 + } else { 1.184 + return s.toArray(new ClassDoc[] {}); 1.185 + } 1.186 + } 1.187 + 1.188 + /** 1.189 + * Return all of the classes specified on the command-line that 1.190 + * belong to the given package. 1.191 + * @param pkgDoc the package to return the classes for. 1.192 + */ 1.193 + public ClassDoc[] allClasses(PackageDoc pkgDoc) { 1.194 + return pkgDoc.isIncluded() ? 1.195 + pkgDoc.allClasses() : 1.196 + getArray(allClasses, Util.getPackageName(pkgDoc)); 1.197 + } 1.198 + 1.199 + /** 1.200 + * Return all of the classes specified on the command-line that 1.201 + * belong to the given package. 1.202 + * @param packageName the name of the package specified on the 1.203 + * command-line. 1.204 + */ 1.205 + public ClassDoc[] allClasses(String packageName) { 1.206 + return getArray(allClasses, packageName); 1.207 + } 1.208 + 1.209 + /** 1.210 + * Return the array of package names that this catalog stores 1.211 + * ClassDocs for. 1.212 + */ 1.213 + public String[] packageNames() { 1.214 + return packageSet.toArray(new String[] {}); 1.215 + } 1.216 + 1.217 + /** 1.218 + * Return true if the given package is known to this catalog. 1.219 + * @param packageName the name to check. 1.220 + * @return true if this catalog has any information about 1.221 + * classes in the given package. 1.222 + */ 1.223 + public boolean isKnownPackage(String packageName) { 1.224 + return packageSet.contains(packageName); 1.225 + } 1.226 + 1.227 + 1.228 + /** 1.229 + * Return all of the errors specified on the command-line 1.230 + * that belong to the given package. 1.231 + * @param packageName the name of the package specified on the 1.232 + * command-line. 1.233 + */ 1.234 + public ClassDoc[] errors(String packageName) { 1.235 + return getArray(errors, packageName); 1.236 + } 1.237 + 1.238 + /** 1.239 + * Return all of the exceptions specified on the command-line 1.240 + * that belong to the given package. 1.241 + * @param packageName the name of the package specified on the 1.242 + * command-line. 1.243 + */ 1.244 + public ClassDoc[] exceptions(String packageName) { 1.245 + return getArray(exceptions, packageName); 1.246 + } 1.247 + 1.248 + /** 1.249 + * Return all of the enums specified on the command-line 1.250 + * that belong to the given package. 1.251 + * @param packageName the name of the package specified on the 1.252 + * command-line. 1.253 + */ 1.254 + public ClassDoc[] enums(String packageName) { 1.255 + return getArray(enums, packageName); 1.256 + } 1.257 + 1.258 + /** 1.259 + * Return all of the annotation types specified on the command-line 1.260 + * that belong to the given package. 1.261 + * @param packageName the name of the package specified on the 1.262 + * command-line. 1.263 + */ 1.264 + public ClassDoc[] annotationTypes(String packageName) { 1.265 + return getArray(annotationTypes, packageName); 1.266 + } 1.267 + 1.268 + /** 1.269 + * Return all of the interfaces specified on the command-line 1.270 + * that belong to the given package. 1.271 + * @param packageName the name of the package specified on the 1.272 + * command-line. 1.273 + */ 1.274 + public ClassDoc[] interfaces(String packageName) { 1.275 + return getArray(interfaces, packageName); 1.276 + } 1.277 + 1.278 + /** 1.279 + * Return all of the ordinary classes specified on the command-line 1.280 + * that belong to the given package. 1.281 + * @param packageName the name of the package specified on the 1.282 + * command-line. 1.283 + */ 1.284 + public ClassDoc[] ordinaryClasses(String packageName) { 1.285 + return getArray(ordinaryClasses, packageName); 1.286 + } 1.287 +}