langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java
author ksrini
Sun, 15 Jun 2014 08:41:57 -0700
changeset 25454 376a52c9540c
parent 24221 2376793dd33b
permissions -rw-r--r--
8039028: [javadoc] refactor the usage of Util.java Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22165
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
10
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
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
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9606
diff changeset
    28
import java.util.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9606
diff changeset
    29
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    31
import com.sun.tools.doclets.internal.toolkit.Configuration;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    34
 * Build list of all the deprecated packages, classes, constructors, fields and methods.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    39
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    40
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
public class DeprecatedAPIListBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    45
    public static final int NUM_TYPES = 12;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    47
    public static final int PACKAGE = 0;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    48
    public static final int INTERFACE = 1;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    49
    public static final int CLASS = 2;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    50
    public static final int ENUM = 3;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    51
    public static final int EXCEPTION = 4;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    52
    public static final int ERROR = 5;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    53
    public static final int ANNOTATION_TYPE = 6;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    54
    public static final int FIELD = 7;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    55
    public static final int METHOD = 8;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    56
    public static final int CONSTRUCTOR = 9;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    57
    public static final int ENUM_CONSTANT = 10;
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    58
    public static final int ANNOTATION_TYPE_MEMBER = 11;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * List of deprecated type Lists.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    63
    private List<List<Doc>> deprecatedLists;
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    64
    private final Configuration configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    65
    private final Utils utils;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     *
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    70
     * @param configuration the current configuration of the doclet
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     */
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    72
    public DeprecatedAPIListBuilder(Configuration configuration) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    73
        this.configuration = configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    74
        this.utils = configuration.utils;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    75
        deprecatedLists = new ArrayList<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        for (int i = 0; i < NUM_TYPES; i++) {
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
    77
            deprecatedLists.add(i, new ArrayList<Doc>());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        }
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    79
        buildDeprecatedAPIInfo();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * Build the sorted list of all the deprecated APIs in this run.
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    84
     * Build separate lists for deprecated packages, classes, constructors,
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    85
     * methods and fields.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     *
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    87
     * @param configuration the current configuration of the doclet.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    89
    private void buildDeprecatedAPIInfo() {
24221
2376793dd33b 8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents: 22165
diff changeset
    90
        Set<PackageDoc> packages = configuration.packages;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14260
diff changeset
    91
        for (PackageDoc pkg : packages) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    92
            if (utils.isDeprecated(pkg)) {
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    93
                getList(PACKAGE).add(pkg);
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    94
            }
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
    95
        }
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14260
diff changeset
    96
        for (ClassDoc cd : configuration.root.classes()) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
    97
            if (utils.isDeprecated(cd)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                if (cd.isOrdinaryClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                    getList(CLASS).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                    getList(INTERFACE).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
                } else if (cd.isException()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                    getList(EXCEPTION).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                } else if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                    getList(ENUM).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
                } else if (cd.isError()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                    getList(ERROR).add(cd);
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
   108
                } else if (cd.isAnnotationType()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                    getList(ANNOTATION_TYPE).add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            composeDeprecatedList(getList(FIELD), cd.fields());
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            composeDeprecatedList(getList(METHOD), cd.methods());
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            composeDeprecatedList(getList(CONSTRUCTOR), cd.constructors());
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            if (cd.isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                composeDeprecatedList(getList(ENUM_CONSTANT), cd.enumConstants());
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                composeDeprecatedList(getList(ANNOTATION_TYPE_MEMBER),
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14260
diff changeset
   120
                                      ((AnnotationTypeDoc) cd).elements());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        sortDeprecatedLists();
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * Add the members into a single list of deprecated members.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * @param list List of all the particular deprecated members, e.g. methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * @param members members to be added in the list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   132
    private void composeDeprecatedList(List<Doc> list, MemberDoc[] members) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14260
diff changeset
   133
        for (MemberDoc member : members) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 24221
diff changeset
   134
            if (utils.isDeprecated(member)) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14260
diff changeset
   135
                list.add(member);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     * Sort the deprecated lists for class kinds, fields, methods and
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    private void sortDeprecatedLists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        for (int i = 0; i < NUM_TYPES; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            Collections.sort(getList(i));
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * Return the list of deprecated Doc objects of a given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     *
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   153
     * @param type the constant representing the type of list being returned.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   155
    public List<Doc> getList(int type) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   156
        return deprecatedLists.get(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * Return true if the list of a given type has size greater than 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * @param type the type of list being checked.
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    public boolean hasDocumentation(int type) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   165
        return (deprecatedLists.get(type)).size() > 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
}