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

Tue, 09 Oct 2012 19:31:58 -0700

author
jjg
date
Tue, 09 Oct 2012 19:31:58 -0700
changeset 1358
fc123bdeddb8
parent 995
62bc3775d5bb
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000208: fix langtools javadoc comment issues
Reviewed-by: bpatel, mcimadamore

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

mercurial