langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java
author jjg
Tue, 15 Jul 2008 19:22:51 -0700
changeset 868 d0f233085cbb
parent 10 06bc494ca11e
child 1264 076a3cde30d5
permissions -rw-r--r--
6657907: javadoc has unchecked warnings Reviewed-by: bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2004 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * Build list of all the deprecated classes, constructors, fields and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
public class DeprecatedAPIListBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
    public static final int NUM_TYPES = 11;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    public static final int INTERFACE = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    public static final int CLASS = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    public static final int ENUM = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    public static final int EXCEPTION = 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    public static final int ERROR = 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    public static final int ANNOTATION_TYPE = 5;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    public static final int FIELD = 6;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    public static final int METHOD = 7;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    public static final int CONSTRUCTOR = 8;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    public static final int ENUM_CONSTANT = 9;
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public static final int ANNOTATION_TYPE_MEMBER = 10;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * List of deprecated type Lists.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    55
    private List<List<Doc>> deprecatedLists;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * @param root Root of the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public DeprecatedAPIListBuilder(RootDoc root) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    64
        deprecatedLists = new ArrayList<List<Doc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        for (int i = 0; i < NUM_TYPES; i++) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    66
            deprecatedLists.add(i, new ArrayList<Doc>());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        buildDeprecatedAPIInfo(root);
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * Build the sorted list of all the deprecated APIs in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * Build separate lists for deprecated classes, constructors, methods and
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @param root Root of the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    private void buildDeprecatedAPIInfo(RootDoc root) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        ClassDoc[] classes = root.classes();
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        for (int i = 0; i < classes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            ClassDoc cd = classes[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            if (Util.isDeprecated(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                if (cd.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                    getList(CLASS).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                    getList(INTERFACE).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                } else if (cd.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                    getList(EXCEPTION).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                } else if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                    getList(ENUM).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                } else if (cd.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                    getList(ERROR).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                }else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                    getList(ANNOTATION_TYPE).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            composeDeprecatedList(getList(FIELD), cd.fields());
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            composeDeprecatedList(getList(METHOD), cd.methods());
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                    ((AnnotationTypeDoc) cd).elements());
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        sortDeprecatedLists();
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * Add the members into a single list of deprecated members.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * @param list List of all the particular deprecated members, e.g. methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * @param members members to be added in the list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   117
    private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        for (int i = 0; i < members.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            if (Util.isDeprecated(members[i])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                list.add(members[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * Sort the deprecated lists for class kinds, fields, methods and
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    private void sortDeprecatedLists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
        for (int i = 0; i < NUM_TYPES; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            Collections.sort(getList(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * Return the list of deprecated Doc objects of a given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     * @param the constant representing the type of list being returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   140
    public List<Doc> getList(int type) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   141
        return deprecatedLists.get(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * Return true if the list of a given type has size greater than 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * @param type the type of list being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public boolean hasDocumentation(int type) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   150
        return (deprecatedLists.get(type)).size() > 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
}