src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.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

     1 /*
     2  * Copyright (c) 1998, 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.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.Configuration;
    33 /**
    34  * Build list of all the deprecated packages, classes, constructors, fields and methods.
    35  *
    36  *  <p><b>This is NOT part of any supported API.
    37  *  If you write code that depends on this, you do so at your own risk.
    38  *  This code and its internal interfaces are subject to change or
    39  *  deletion without notice.</b>
    40  *
    41  * @author Atul M Dambalkar
    42  */
    43 public class DeprecatedAPIListBuilder {
    45     public static final int NUM_TYPES = 12;
    47     public static final int PACKAGE = 0;
    48     public static final int INTERFACE = 1;
    49     public static final int CLASS = 2;
    50     public static final int ENUM = 3;
    51     public static final int EXCEPTION = 4;
    52     public static final int ERROR = 5;
    53     public static final int ANNOTATION_TYPE = 6;
    54     public static final int FIELD = 7;
    55     public static final int METHOD = 8;
    56     public static final int CONSTRUCTOR = 9;
    57     public static final int ENUM_CONSTANT = 10;
    58     public static final int ANNOTATION_TYPE_MEMBER = 11;
    60     /**
    61      * List of deprecated type Lists.
    62      */
    63     private List<List<Doc>> deprecatedLists;
    66     /**
    67      * Constructor.
    68      *
    69      * @param configuration the current configuration of the doclet
    70      */
    71     public DeprecatedAPIListBuilder(Configuration configuration) {
    72         deprecatedLists = new ArrayList<List<Doc>>();
    73         for (int i = 0; i < NUM_TYPES; i++) {
    74             deprecatedLists.add(i, new ArrayList<Doc>());
    75         }
    76         buildDeprecatedAPIInfo(configuration);
    77     }
    79     /**
    80      * Build the sorted list of all the deprecated APIs in this run.
    81      * Build separate lists for deprecated packages, classes, constructors,
    82      * methods and fields.
    83      *
    84      * @param configuration the current configuration of the doclet.
    85      */
    86     private void buildDeprecatedAPIInfo(Configuration configuration) {
    87         PackageDoc[] packages = configuration.packages;
    88         PackageDoc pkg;
    89         for (int c = 0; c < packages.length; c++) {
    90             pkg = packages[c];
    91             if (Util.isDeprecated(pkg)) {
    92                 getList(PACKAGE).add(pkg);
    93             }
    94         }
    95         ClassDoc[] classes = configuration.root.classes();
    96         for (int i = 0; i < classes.length; i++) {
    97             ClassDoc cd = classes[i];
    98             if (Util.isDeprecated(cd)) {
    99                 if (cd.isOrdinaryClass()) {
   100                     getList(CLASS).add(cd);
   101                 } else if (cd.isInterface()) {
   102                     getList(INTERFACE).add(cd);
   103                 } else if (cd.isException()) {
   104                     getList(EXCEPTION).add(cd);
   105                 } else if (cd.isEnum()) {
   106                     getList(ENUM).add(cd);
   107                 } else if (cd.isError()) {
   108                     getList(ERROR).add(cd);
   109                 } else if (cd.isAnnotationType()) {
   110                     getList(ANNOTATION_TYPE).add(cd);
   111                 }
   112             }
   113             composeDeprecatedList(getList(FIELD), cd.fields());
   114             composeDeprecatedList(getList(METHOD), cd.methods());
   115             composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
   116             if (cd.isEnum()) {
   117                 composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
   118             }
   119             if (cd.isAnnotationType()) {
   120                 composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
   121                         ((AnnotationTypeDoc) cd).elements());
   122             }
   123         }
   124         sortDeprecatedLists();
   125     }
   127     /**
   128      * Add the members into a single list of deprecated members.
   129      *
   130      * @param list List of all the particular deprecated members, e.g. methods.
   131      * @param members members to be added in the list.
   132      */
   133     private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
   134         for (int i = 0; i < members.length; i++) {
   135             if (Util.isDeprecated(members[i])) {
   136                 list.add(members[i]);
   137             }
   138         }
   139     }
   141     /**
   142      * Sort the deprecated lists for class kinds, fields, methods and
   143      * constructors.
   144      */
   145     private void sortDeprecatedLists() {
   146         for (int i = 0; i < NUM_TYPES; i++) {
   147             Collections.sort(getList(i));
   148         }
   149     }
   151     /**
   152      * Return the list of deprecated Doc objects of a given type.
   153      *
   154      * @param type the constant representing the type of list being returned.
   155      */
   156     public List<Doc> getList(int type) {
   157         return deprecatedLists.get(type);
   158     }
   160     /**
   161      * Return true if the list of a given type has size greater than 0.
   162      *
   163      * @param type the type of list being checked.
   164      */
   165     public boolean hasDocumentation(int type) {
   166         return (deprecatedLists.get(type)).size() > 0;
   167     }
   168 }

mercurial