langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassTree.java
author jjg
Fri, 27 May 2016 13:06:58 -0700
changeset 38617 d93a7f64e231
parent 26270 a3635e6d3d78
permissions -rw-r--r--
8157606: deprecate com.sun.javadoc API Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
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: 1789
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: 1789
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: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
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.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 9606
diff changeset
    31
import com.sun.tools.doclets.internal.toolkit.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Build Class Hierarchy for all the Classes. This class builds the Class
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Tree and the Interface Tree separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    37
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    38
 *  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: 14258
diff changeset
    39
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    40
 *  deletion without notice.</b>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @see java.util.HashMap
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @see java.util.List
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @see com.sun.javadoc.Type
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @see com.sun.javadoc.ClassDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 26270
diff changeset
    48
@Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public class ClassTree {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     * List of baseclasses. Contains only java.lang.Object. Can be used to get
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * the mapped listing of sub-classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    55
    final private SortedSet<ClassDoc> baseclasses;
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
    * Mapping for each Class with their SubClasses
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    60
    final private Map<ClassDoc, SortedSet<ClassDoc>> subclasses = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * List of base-interfaces. Contains list of all the interfaces who do not
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * have super-interfaces. Can be used to get the mapped listing of
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * sub-interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    67
    final private SortedSet<ClassDoc> baseinterfaces;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    * Mapping for each Interface with their SubInterfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    72
    final private Map<ClassDoc, SortedSet<ClassDoc>> subinterfaces = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    74
    final private SortedSet<ClassDoc> baseEnums;
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    75
    final private Map<ClassDoc, SortedSet<ClassDoc>> subEnums = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    77
    final private SortedSet<ClassDoc> baseAnnotationTypes;
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    78
    final private Map<ClassDoc, SortedSet<ClassDoc>> subAnnotationTypes = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    * Mapping for each Interface with classes who implement it.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    83
    final private Map<ClassDoc, SortedSet<ClassDoc>> implementingclasses = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    85
    private final Configuration configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    86
    private final Utils utils;
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    87
    private final Comparator<Doc> comparator;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     * Constructor. Build the Tree using the Root of this Javadoc run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * @param configuration the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * @param noDeprecated Don't add deprecated classes in the class tree, if
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * true.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    public ClassTree(Configuration configuration, boolean noDeprecated) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        configuration.message.notice("doclet.Building_Tree");
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    97
        this.configuration = configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
    98
        this.utils = configuration.utils;
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
    99
        comparator = utils.makeGeneralPurposeComparator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   100
        baseAnnotationTypes = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   101
        baseEnums = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   102
        baseclasses = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   103
        baseinterfaces = new TreeSet<>(comparator);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   104
        buildTree(configuration.root.classes());
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   105
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * Constructor. Build the Tree using the Root of this Javadoc run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     * @param root Root of the Document.
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   112
     * @param configuration The current configuration of the doclet.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    public ClassTree(RootDoc root, Configuration configuration) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   115
        this.configuration = configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   116
        this.utils = configuration.utils;
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   117
        comparator = utils.makeGeneralPurposeComparator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   118
        baseAnnotationTypes = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   119
        baseEnums = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   120
        baseclasses = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   121
        baseinterfaces = new TreeSet<>(comparator);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   122
        buildTree(root.classes());
10
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
     * Constructor. Build the tree for the given array of classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * @param classes Array of classes.
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   129
     * @param configuration The current configuration of the doclet.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public ClassTree(ClassDoc[] classes, Configuration configuration) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   132
        this.configuration = configuration;
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   133
        this.utils = configuration.utils;
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   134
        comparator = utils.makeGeneralPurposeComparator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   135
        baseAnnotationTypes = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   136
        baseEnums = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   137
        baseclasses = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   138
        baseinterfaces = new TreeSet<>(comparator);
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   139
        buildTree(classes);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * Generate mapping for the sub-classes for every class in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * Return the sub-class list for java.lang.Object which will be having
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * sub-class listing for itself and also for each sub-class itself will
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * have their own sub-class lists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * @param classes all the classes in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     */
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   151
    private void buildTree(ClassDoc[] classes) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   152
        for (ClassDoc aClass : classes) {
9606
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
   153
            // In the tree page (e.g overview-tree.html) do not include
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
   154
            // information of classes which are deprecated or are a part of a
e5a619cb5dd3 6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents: 5520
diff changeset
   155
            // deprecated package.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            if (configuration.nodeprecated &&
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   157
                    (utils.isDeprecated(aClass) ||
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   158
                    utils.isDeprecated(aClass.containingPackage()))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            }
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14260
diff changeset
   161
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14260
diff changeset
   162
            if (configuration.javafx
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   163
                    && aClass.tags("treatAsPrivate").length > 0) {
16319
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14260
diff changeset
   164
                continue;
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14260
diff changeset
   165
            }
e586bfeb39c5 7112427: The doclet needs to be able to generate JavaFX documentation.
jjg
parents: 14260
diff changeset
   166
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   167
            if (aClass.isEnum()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   168
                processType(aClass, configuration, baseEnums, subEnums);
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   169
            } else if (aClass.isClass()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   170
                processType(aClass, configuration, baseclasses, subclasses);
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   171
            } else if (aClass.isInterface()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   172
                processInterface(aClass);
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   173
            } else if (aClass.isAnnotationType()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   174
                processType(aClass, configuration, baseAnnotationTypes,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                    subAnnotationTypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * For the class passed map it to it's own sub-class listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * For the Class passed, get the super class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * if superclass is non null, (it is not "java.lang.Object")
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     *    get the "value" from the hashmap for this key Class
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *    if entry not found create one and get that.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     *    add this Class as a sub class in the list
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     *    Recurse till hits java.lang.Object Null SuperClass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * @param cd class for which sub-class mapping to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * @param configuration the current configurtation of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    private void processType(ClassDoc cd, Configuration configuration,
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   193
            Collection<ClassDoc> bases, Map<ClassDoc, SortedSet<ClassDoc>> subs) {
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   194
        ClassDoc superclass = utils.getFirstVisibleSuperClassCD(cd, configuration);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        if (superclass != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            if (!add(subs, superclass, cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
                processType(superclass, configuration, bases, subs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        } else {     // cd is java.lang.Object, add it once to the list
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            if (!bases.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
                bases.add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        }
25454
376a52c9540c 8039028: [javadoc] refactor the usage of Util.java
ksrini
parents: 22163
diff changeset
   206
        List<Type> intfacs = utils.getAllInterfaces(cd, configuration);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   207
        for (Type intfac : intfacs) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   208
            add(implementingclasses, intfac.asClassDoc(), cd);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * For the interface passed get the interfaces which it extends, and then
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * put this interface in the sub-interface list of those interfaces. Do it
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * recursively. If a interface doesn't have super-interface just attach
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     * that interface in the list of all the baseinterfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * @param cd Interface under consideration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    private void processInterface(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        ClassDoc[] intfacs = cd.interfaces();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        if (intfacs.length > 0) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   223
            for (ClassDoc intfac : intfacs) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   224
                if (!add(subinterfaces, intfac, cd)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                } else {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   227
                    processInterface(intfac);   // Recurse
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            // we need to add all the interfaces who do not have
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            // super-interfaces to baseinterfaces list to traverse them
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            if (!baseinterfaces.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                baseinterfaces.add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * Adjust the Class Tree. Add the class interface  in to it's super-class'
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * or super-interface's sub-interface list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * @param map the entire map.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * @param superclass java.lang.Object or the super-interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * @param cd sub-interface to be mapped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     * @returns boolean true if class added, false if class already processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   248
    private boolean add(Map<ClassDoc, SortedSet<ClassDoc>> map, ClassDoc superclass, ClassDoc cd) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   249
        SortedSet<ClassDoc> list = map.get(superclass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        if (list == null) {
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   251
            list = new TreeSet<>(comparator);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            map.put(superclass, list);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        if (list.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            list.add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * From the map return the list of sub-classes or sub-interfaces. If list
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * is null create a new one and return it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * @param map The entire map.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @param cd class for which the sub-class list is requested.
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @returns List Sub-Class list for the class passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   270
    private SortedSet<ClassDoc> get(Map<ClassDoc, SortedSet<ClassDoc>> map, ClassDoc cd) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   271
        SortedSet<ClassDoc> aset = map.get(cd);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   272
        if (aset == null) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   273
            return new TreeSet<>(comparator);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        }
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   275
        return aset;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     *  Return the sub-class list for the class passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * @param cd class whose sub-class list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   283
    public SortedSet<ClassDoc> subclasses(ClassDoc cd) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        return get(subclasses, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     *  Return the sub-interface list for the interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * @param cd interface whose sub-interface list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   292
    public SortedSet<ClassDoc> subinterfaces(ClassDoc cd) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        return get(subinterfaces, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     *  Return the list of classes which implement the interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     * @param cd interface whose implementing-classes list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   301
    public SortedSet<ClassDoc> implementingclasses(ClassDoc cd) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   302
        SortedSet<ClassDoc> result = get(implementingclasses, cd);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   303
        SortedSet<ClassDoc> intfcs = allSubs(cd, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        //If class x implements a subinterface of cd, then it follows
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        //that class x implements cd.
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   307
        Iterator<ClassDoc> subInterfacesIter = intfcs.iterator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   308
        while (subInterfacesIter.hasNext()) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   309
            Iterator<ClassDoc> implementingClassesIter
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   310
                    = implementingclasses(subInterfacesIter.next()).iterator();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   311
            while (implementingClassesIter.hasNext()) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   312
                ClassDoc c = implementingClassesIter.next();
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   313
                if (!result.contains(c)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                    result.add(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *  Return the sub-class/interface list for the class/interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param cd class/interface whose sub-class/interface list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     * @param isEnum true if the subclasses should be forced to come from the
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     * enum tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   328
    public SortedSet<ClassDoc> subs(ClassDoc cd, boolean isEnum) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        if (isEnum) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            return get(subEnums, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        } else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            return get(subAnnotationTypes, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            return get(subinterfaces, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        } else if (cd.isClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
            return get(subclasses, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * Return a list of all direct or indirect, sub-classes and subinterfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     * of the ClassDoc argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     * @param cd ClassDoc whose sub-classes or sub-interfaces are requested.
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
     * @param isEnum true if the subclasses should be forced to come from the
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
     * enum tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   351
    public SortedSet<ClassDoc> allSubs(ClassDoc cd, boolean isEnum) {
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   352
        // new entries added to the list are searched as well
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   353
        List<ClassDoc> list = new ArrayList<>(subs(cd, isEnum));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        for (int i = 0; i < list.size(); i++) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   355
            cd = list.get(i);
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   356
            SortedSet<ClassDoc> tlist = subs(cd, isEnum);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 16319
diff changeset
   357
            for (ClassDoc tcd : tlist) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                if (!list.contains(tcd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                    list.add(tcd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        }
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   363
        SortedSet<ClassDoc> oset = new TreeSet<>(comparator);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   364
        oset.addAll(list);
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   365
        return oset;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     *  Return the base-classes list. This will have only one element namely
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     *  thw classdoc for java.lang.Object, since this is the base class for all
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     *  classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   373
    public SortedSet<ClassDoc> baseclasses() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        return baseclasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
     *  Return the list of base interfaces. This is the list of interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
     *  which do not have super-interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   381
    public SortedSet<ClassDoc> baseinterfaces() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        return baseinterfaces;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     *  Return the list of base enums. This is the list of enums
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     *  which do not have super-enums.
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   389
    public SortedSet<ClassDoc> baseEnums() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        return baseEnums;
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     *  Return the list of base annotation types. This is the list of
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     *  annotation types which do not have super-annotation types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     */
26270
a3635e6d3d78 8050031: [javadoc] class-use pages have duplicates and missing entries
ksrini
parents: 25874
diff changeset
   397
    public SortedSet<ClassDoc> baseAnnotationTypes() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        return baseAnnotationTypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
}