langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ClassTree.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.tools.doclets.internal.toolkit.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * Build Class Hierarchy for all the Classes. This class builds the Class
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * Tree and the Interface Tree separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * This code is not part of an API.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * It is implementation that is subject to change.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * Do not use it as an API
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * @see java.util.HashMap
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * @see java.util.List
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @see com.sun.javadoc.Type
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @see com.sun.javadoc.ClassDoc
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class ClassTree {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * List of baseclasses. Contains only java.lang.Object. Can be used to get
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * the mapped listing of sub-classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    52
    private List<ClassDoc> baseclasses = new ArrayList<ClassDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    * Mapping for each Class with their SubClasses
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    57
    private Map<ClassDoc,List<ClassDoc>> subclasses = new HashMap<ClassDoc,List<ClassDoc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * List of base-interfaces. Contains list of all the interfaces who do not
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * have super-interfaces. Can be used to get the mapped listing of
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * sub-interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    64
    private List<ClassDoc> baseinterfaces = new ArrayList<ClassDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    * Mapping for each Interface with their SubInterfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    69
    private Map<ClassDoc,List<ClassDoc>> subinterfaces = new HashMap<ClassDoc,List<ClassDoc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    71
    private List<ClassDoc> baseEnums = new ArrayList<ClassDoc>();
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    72
    private Map<ClassDoc,List<ClassDoc>> subEnums = new HashMap<ClassDoc,List<ClassDoc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    74
    private List<ClassDoc> baseAnnotationTypes = new ArrayList<ClassDoc>();
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    75
    private Map<ClassDoc,List<ClassDoc>> subAnnotationTypes = new HashMap<ClassDoc,List<ClassDoc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    * Mapping for each Interface with classes who implement it.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    80
    private Map<ClassDoc,List<ClassDoc>> implementingclasses = new HashMap<ClassDoc,List<ClassDoc>>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * Constructor. Build the Tree using the Root of this Javadoc run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * @param configuration the configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * @param noDeprecated Don't add deprecated classes in the class tree, if
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * true.
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    public ClassTree(Configuration configuration, boolean noDeprecated) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        configuration.message.notice("doclet.Building_Tree");
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        buildTree(configuration.root.classes(), configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * Constructor. Build the Tree using the Root of this Javadoc run.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * @param root Root of the Document.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * @param configuration The curren configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public ClassTree(RootDoc root, Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        buildTree(root.classes(), configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * Constructor. Build the tree for the given array of classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * @param classes Array of classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * @param configuration The curren configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    public ClassTree(ClassDoc[] classes, Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        buildTree(classes, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * Generate mapping for the sub-classes for every class in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * Return the sub-class list for java.lang.Object which will be having
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * sub-class listing for itself and also for each sub-class itself will
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * have their own sub-class lists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @param classes all the classes in this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * @param configuration the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    private void buildTree(ClassDoc[] classes, Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        for (int i = 0; i < classes.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
            if (configuration.nodeprecated &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                    classes[i].tags("deprecated").length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
            if (classes[i].isEnum()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                processType(classes[i], configuration, baseEnums, subEnums);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            } else if (classes[i].isClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                processType(classes[i], configuration, baseclasses, subclasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            } else if (classes[i].isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                processInterface(classes[i]);
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   135
                List<ClassDoc> list = implementingclasses.get(classes[i]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                if (list != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                    Collections.sort(list);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            } else if (classes[i].isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
                processType(classes[i], configuration, baseAnnotationTypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                    subAnnotationTypes);
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
        Collections.sort(baseinterfaces);
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   146
        for (Iterator<List<ClassDoc>> it = subinterfaces.values().iterator(); it.hasNext(); ) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   147
            Collections.sort(it.next());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   149
        for (Iterator<List<ClassDoc>> it = subclasses.values().iterator(); it.hasNext(); ) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   150
            Collections.sort(it.next());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * For the class passed map it to it's own sub-class listing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * For the Class passed, get the super class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * if superclass is non null, (it is not "java.lang.Object")
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     *    get the "value" from the hashmap for this key Class
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     *    if entry not found create one and get that.
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *    add this Class as a sub class in the list
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     *    Recurse till hits java.lang.Object Null SuperClass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * @param cd class for which sub-class mapping to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * @param configuration the current configurtation of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    private void processType(ClassDoc cd, Configuration configuration,
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   167
            List<ClassDoc> bases, Map<ClassDoc,List<ClassDoc>> subs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        ClassDoc superclass = Util.getFirstVisibleSuperClassCD(cd, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        if (superclass != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
            if (!add(subs, superclass, cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                processType(superclass, configuration, bases, subs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        } else {     // cd is java.lang.Object, add it once to the list
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            if (!bases.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                bases.add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        List intfacs = Util.getAllInterfaces(cd, configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        for (Iterator iter = intfacs.iterator(); iter.hasNext();) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            add(implementingclasses, ((Type) iter.next()).asClassDoc(), cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * For the interface passed get the interfaces which it extends, and then
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * put this interface in the sub-interface list of those interfaces. Do it
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * recursively. If a interface doesn't have super-interface just attach
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * that interface in the list of all the baseinterfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * @param cd Interface under consideration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    private void processInterface(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        ClassDoc[] intfacs = cd.interfaces();
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        if (intfacs.length > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            for (int i = 0; i < intfacs.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
                if (!add(subinterfaces, intfacs[i], cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
                    processInterface(intfacs[i]);   // Recurse
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            // we need to add all the interfaces who do not have
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            // super-interfaces to baseinterfaces list to traverse them
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            if (!baseinterfaces.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                baseinterfaces.add(cd);
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     * Adjust the Class Tree. Add the class interface  in to it's super-class'
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * or super-interface's sub-interface list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * @param map the entire map.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * @param superclass java.lang.Object or the super-interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * @param cd sub-interface to be mapped.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * @returns boolean true if class added, false if class already processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   222
    private boolean add(Map<ClassDoc,List<ClassDoc>> map, ClassDoc superclass, ClassDoc cd) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   223
        List<ClassDoc> list = map.get(superclass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        if (list == null) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   225
            list = new ArrayList<ClassDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            map.put(superclass, list);
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        if (list.contains(cd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
            list.add(cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     * From the map return the list of sub-classes or sub-interfaces. If list
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * is null create a new one and return it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * @param map The entire map.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * @param cd class for which the sub-class list is requested.
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * @returns List Sub-Class list for the class passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   244
    private List<ClassDoc> get(Map<ClassDoc,List<ClassDoc>> map, ClassDoc cd) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   245
        List<ClassDoc> list = map.get(cd);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        if (list == null) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   247
            return new ArrayList<ClassDoc>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     *  Return the sub-class list for the class passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * @param cd class whose sub-class list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   257
    public List<ClassDoc> subclasses(ClassDoc cd) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        return get(subclasses, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     *  Return the sub-interface list for the interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * @param cd interface whose sub-interface list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   266
    public List<ClassDoc> subinterfaces(ClassDoc cd) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        return get(subinterfaces, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *  Return the list of classes which implement the interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * @param cd interface whose implementing-classes list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   275
    public List<ClassDoc> implementingclasses(ClassDoc cd) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   276
        List<ClassDoc> result = get(implementingclasses, cd);
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   277
        List<ClassDoc> subinterfaces = allSubs(cd, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        //If class x implements a subinterface of cd, then it follows
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        //that class x implements cd.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        Iterator implementingClassesIter, subInterfacesIter = subinterfaces.listIterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        ClassDoc c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        while(subInterfacesIter.hasNext()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            implementingClassesIter = implementingclasses((ClassDoc)
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                    subInterfacesIter.next()).listIterator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            while(implementingClassesIter.hasNext()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                c = (ClassDoc)implementingClassesIter.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                if(! result.contains(c)){
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
                    result.add(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        Collections.sort(result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     *  Return the sub-class/interface list for the class/interface passed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     * @param cd class/interface whose sub-class/interface list is required.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     * @param isEnum true if the subclasses should be forced to come from the
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     * enum tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   304
    public List<ClassDoc> subs(ClassDoc cd, boolean isEnum) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        if (isEnum) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            return get(subEnums, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        } else if (cd.isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            return get(subAnnotationTypes, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        } else if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            return get(subinterfaces, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        } else if (cd.isClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            return get(subclasses, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            return null;
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
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     * Return a list of all direct or indirect, sub-classes and subinterfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     * of the ClassDoc argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     * @param cd ClassDoc whose sub-classes or sub-interfaces are requested.
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     * @param isEnum true if the subclasses should be forced to come from the
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     * enum tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     */
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   327
    public List<ClassDoc> allSubs(ClassDoc cd, boolean isEnum) {
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   328
        List<ClassDoc> list = subs(cd, isEnum);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        for (int i = 0; i < list.size(); i++) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   330
            cd = list.get(i);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            List tlist = subs(cd, isEnum);
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            for (int j = 0; j < tlist.size(); j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                ClassDoc tcd = (ClassDoc)tlist.get(j);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                if (!list.contains(tcd)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                    list.add(tcd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        Collections.sort(list);
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        return list;
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 the base-classes list. This will have only one element namely
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     *  thw classdoc for java.lang.Object, since this is the base class for all
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
     *  classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    public List baseclasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        return baseclasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
     *  Return the list of base interfaces. This is the list of interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
     *  which do not have super-interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
    public List baseinterfaces() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        return baseinterfaces;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     *  Return the list of base enums. This is the list of enums
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     *  which do not have super-enums.
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    public List baseEnums() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        return baseEnums;
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 list of base annotation types. This is the list of
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     *  annotation types which do not have super-annotation types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    public List baseAnnotationTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        return baseAnnotationTypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
}