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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 995
62bc3775d5bb
child 1358
fc123bdeddb8
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     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  * @author Atul M Dambalkar
    37  */
    38 public class DeprecatedAPIListBuilder {
    40     public static final int NUM_TYPES = 12;
    42     public static final int PACKAGE = 0;
    43     public static final int INTERFACE = 1;
    44     public static final int CLASS = 2;
    45     public static final int ENUM = 3;
    46     public static final int EXCEPTION = 4;
    47     public static final int ERROR = 5;
    48     public static final int ANNOTATION_TYPE = 6;
    49     public static final int FIELD = 7;
    50     public static final int METHOD = 8;
    51     public static final int CONSTRUCTOR = 9;
    52     public static final int ENUM_CONSTANT = 10;
    53     public static final int ANNOTATION_TYPE_MEMBER = 11;
    55     /**
    56      * List of deprecated type Lists.
    57      */
    58     private List<List<Doc>> deprecatedLists;
    61     /**
    62      * Constructor.
    63      *
    64      * @param configuration the current configuration of the doclet
    65      */
    66     public DeprecatedAPIListBuilder(Configuration configuration) {
    67         deprecatedLists = new ArrayList<List<Doc>>();
    68         for (int i = 0; i < NUM_TYPES; i++) {
    69             deprecatedLists.add(i, new ArrayList<Doc>());
    70         }
    71         buildDeprecatedAPIInfo(configuration);
    72     }
    74     /**
    75      * Build the sorted list of all the deprecated APIs in this run.
    76      * Build separate lists for deprecated packages, classes, constructors,
    77      * methods and fields.
    78      *
    79      * @param configuration the current configuration of the doclet.
    80      */
    81     private void buildDeprecatedAPIInfo(Configuration configuration) {
    82         PackageDoc[] packages = configuration.packages;
    83         PackageDoc pkg;
    84         for (int c = 0; c < packages.length; c++) {
    85             pkg = packages[c];
    86             if (Util.isDeprecated(pkg)) {
    87                 getList(PACKAGE).add(pkg);
    88             }
    89         }
    90         ClassDoc[] classes = configuration.root.classes();
    91         for (int i = 0; i < classes.length; i++) {
    92             ClassDoc cd = classes[i];
    93             if (Util.isDeprecated(cd)) {
    94                 if (cd.isOrdinaryClass()) {
    95                     getList(CLASS).add(cd);
    96                 } else if (cd.isInterface()) {
    97                     getList(INTERFACE).add(cd);
    98                 } else if (cd.isException()) {
    99                     getList(EXCEPTION).add(cd);
   100                 } else if (cd.isEnum()) {
   101                     getList(ENUM).add(cd);
   102                 } else if (cd.isError()) {
   103                     getList(ERROR).add(cd);
   104                 } else if (cd.isAnnotationType()) {
   105                     getList(ANNOTATION_TYPE).add(cd);
   106                 }
   107             }
   108             composeDeprecatedList(getList(FIELD), cd.fields());
   109             composeDeprecatedList(getList(METHOD), cd.methods());
   110             composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
   111             if (cd.isEnum()) {
   112                 composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
   113             }
   114             if (cd.isAnnotationType()) {
   115                 composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
   116                         ((AnnotationTypeDoc) cd).elements());
   117             }
   118         }
   119         sortDeprecatedLists();
   120     }
   122     /**
   123      * Add the members into a single list of deprecated members.
   124      *
   125      * @param list List of all the particular deprecated members, e.g. methods.
   126      * @param members members to be added in the list.
   127      */
   128     private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
   129         for (int i = 0; i < members.length; i++) {
   130             if (Util.isDeprecated(members[i])) {
   131                 list.add(members[i]);
   132             }
   133         }
   134     }
   136     /**
   137      * Sort the deprecated lists for class kinds, fields, methods and
   138      * constructors.
   139      */
   140     private void sortDeprecatedLists() {
   141         for (int i = 0; i < NUM_TYPES; i++) {
   142             Collections.sort(getList(i));
   143         }
   144     }
   146     /**
   147      * Return the list of deprecated Doc objects of a given type.
   148      *
   149      * @param the constant representing the type of list being returned.
   150      */
   151     public List<Doc> getList(int type) {
   152         return deprecatedLists.get(type);
   153     }
   155     /**
   156      * Return true if the list of a given type has size greater than 0.
   157      *
   158      * @param type the type of list being checked.
   159      */
   160     public boolean hasDocumentation(int type) {
   161         return (deprecatedLists.get(type)).size() > 0;
   162     }
   163 }

mercurial