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

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1998-2008 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit.util;
    28 import com.sun.javadoc.*;
    29 import java.util.*;
    31 /**
    32  * Build list of all the deprecated classes, constructors, fields and methods.
    33  *
    34  * @author Atul M Dambalkar
    35  */
    36 public class DeprecatedAPIListBuilder {
    38     public static final int NUM_TYPES = 11;
    40     public static final int INTERFACE = 0;
    41     public static final int CLASS = 1;
    42     public static final int ENUM = 2;
    43     public static final int EXCEPTION = 3;
    44     public static final int ERROR = 4;
    45     public static final int ANNOTATION_TYPE = 5;
    46     public static final int FIELD = 6;
    47     public static final int METHOD = 7;
    48     public static final int CONSTRUCTOR = 8;
    49     public static final int ENUM_CONSTANT = 9;
    50     public static final int ANNOTATION_TYPE_MEMBER = 10;
    52     /**
    53      * List of deprecated type Lists.
    54      */
    55     private List<List<Doc>> deprecatedLists;
    58     /**
    59      * Constructor.
    60      *
    61      * @param root Root of the tree.
    62      */
    63     public DeprecatedAPIListBuilder(RootDoc root) {
    64         deprecatedLists = new ArrayList<List<Doc>>();
    65         for (int i = 0; i < NUM_TYPES; i++) {
    66             deprecatedLists.add(i, new ArrayList<Doc>());
    67         }
    68         buildDeprecatedAPIInfo(root);
    69     }
    71     /**
    72      * Build the sorted list of all the deprecated APIs in this run.
    73      * Build separate lists for deprecated classes, constructors, methods and
    74      * fields.
    75      *
    76      * @param root Root of the tree.
    77      */
    78     private void buildDeprecatedAPIInfo(RootDoc root) {
    79         ClassDoc[] classes = root.classes();
    80         for (int i = 0; i < classes.length; i++) {
    81             ClassDoc cd = classes[i];
    82             if (Util.isDeprecated(cd)) {
    83                 if (cd.isOrdinaryClass()) {
    84                     getList(CLASS).add(cd);
    85                 } else if (cd.isInterface()) {
    86                     getList(INTERFACE).add(cd);
    87                 } else if (cd.isException()) {
    88                     getList(EXCEPTION).add(cd);
    89                 } else if (cd.isEnum()) {
    90                     getList(ENUM).add(cd);
    91                 } else if (cd.isError()) {
    92                     getList(ERROR).add(cd);
    93                 }else if (cd.isAnnotationType()) {
    94                     getList(ANNOTATION_TYPE).add(cd);
    95                 }
    96             }
    97             composeDeprecatedList(getList(FIELD), cd.fields());
    98             composeDeprecatedList(getList(METHOD), cd.methods());
    99             composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
   100             if (cd.isEnum()) {
   101                 composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
   102             }
   103             if (cd.isAnnotationType()) {
   104                 composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
   105                     ((AnnotationTypeDoc) cd).elements());
   106             }
   107         }
   108         sortDeprecatedLists();
   109     }
   111     /**
   112      * Add the members into a single list of deprecated members.
   113      *
   114      * @param list List of all the particular deprecated members, e.g. methods.
   115      * @param members members to be added in the list.
   116      */
   117     private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
   118         for (int i = 0; i < members.length; i++) {
   119             if (Util.isDeprecated(members[i])) {
   120                 list.add(members[i]);
   121             }
   122         }
   123     }
   125     /**
   126      * Sort the deprecated lists for class kinds, fields, methods and
   127      * constructors.
   128      */
   129     private void sortDeprecatedLists() {
   130         for (int i = 0; i < NUM_TYPES; i++) {
   131             Collections.sort(getList(i));
   132         }
   133     }
   135     /**
   136      * Return the list of deprecated Doc objects of a given type.
   137      *
   138      * @param the constant representing the type of list being returned.
   139      */
   140     public List<Doc> getList(int type) {
   141         return deprecatedLists.get(type);
   142     }
   144     /**
   145      * Return true if the list of a given type has size greater than 0.
   146      *
   147      * @param type the type of list being checked.
   148      */
   149     public boolean hasDocumentation(int type) {
   150         return (deprecatedLists.get(type)).size() > 0;
   151     }
   152 }

mercurial