FileDocCategorySizeDatePackage
ClassTree.javaAPI DocExample9274Wed Apr 19 11:17:16 BST 2000com.sun.tools.doclets

ClassTree

public class ClassTree extends Object
Build Class Hierarchy for all the Classes. This class builds the Class Tree and the Interface Tree separately.
see
java.util.HashMap
see
java.util.List
see
com.sun.javadoc.Type
see
com.sun.javadoc.ClassDoc
author
Atul M Dambalkar

Fields Summary
private List
baseclasses
List of baseclasses. Contains only java.lang.Object. Can be used to get the mapped listing of sub-classes.
private Map
subclasses
Mapping for each Class with their SubClasses
private List
baseinterfaces
List of base-interfaces. Contains list of all the interfaces who do not have super-interfaces. Can be used to get the mapped listing of sub-interfaces.
private Map
subinterfaces
Mapping for each Interface with their SubInterfaces
private Map
implementingclasses
Mapping for each Interface with classes who implement it.
Constructors Summary
public ClassTree(RootDoc root, boolean noDeprecated)
Constructor. Build the Tree using the Root of this Javadoc run.

param
root Root of the Document.
param
noDeprecated Don't add deprecated classes in the class tree, if true.


                                       
         
        Configuration.message.notice("doclet.Building_Tree");
        buildTree(root.classes(), noDeprecated);
    
public ClassTree(ClassDoc[] classes, boolean noDeprecated)
Constructor. Build the tree for the given array of classes.

param
classes Array of classes.
param
noDeprecated Don't add deprecated classes in the class tree, if true.

        buildTree(classes, noDeprecated);
    
Methods Summary
private booleanadd(java.util.Map map, com.sun.javadoc.ClassDoc superclass, com.sun.javadoc.ClassDoc cd)
Adjust the Class Tree. Add the class interface in to it's super-class' or super-interface's sub-interface list.

param
map the entire map.
param
superclass java.lang.Object or the super-interface.
param
cd sub-interface to be mapped.
returns
boolean true if class added, false if class already processed.

        List list = (List)map.get(superclass);
        if (list == null) {
            list = new ArrayList();
            map.put(superclass, list); 
        }     
        if (list.contains(cd)) {
            return false; 
        } else {
            list.add(cd);
        }
        return true;
    
public java.util.ListallSubs(com.sun.javadoc.ClassDoc cd)
Return a list of all direct or indirect, sub-classes and subinterfaces of the ClassDoc argument.

param
cd ClassDoc whose sub-classes or sub-interfaces are requested.

        List list = get(cd.isInterface()? subinterfaces: subclasses, cd);
        for (int i = 0; i < list.size(); i++) {
            cd = (ClassDoc)list.get(i);
            List tlist = get(cd.isInterface()? subinterfaces: subclasses, cd);
            for (int j = 0; j < tlist.size(); j++) {
                ClassDoc tcd = (ClassDoc)tlist.get(j); 
                if (!list.contains(tcd)) {
                    list.add(tcd);
                }
            }
        }
        Collections.sort(list);
        return list; 
    
public java.util.Listbaseclasses()
Return the base-classes list. This will have only one element namely thw classdoc for java.lang.Object, since this is the base class for all classes.

        return baseclasses;
    
public java.util.Listbaseinterfaces()
Return the list of base interfaces. This is the list of interfaces which do not have super-interface.

        return baseinterfaces;
    
private voidbuildTree(com.sun.javadoc.ClassDoc[] classes, boolean noDeprecated)
Generate mapping for the sub-classes for every class in this run. Return the sub-class list for java.lang.Object which will be having sub-class listing for itself and also for each sub-class itself will have their own sub-class lists.

param
classes all the classes in this run.
param
noDeprecated Don't add deprecated classes in the class tree, if true.

        for (int i = 0; i < classes.length; i++) {
            if (noDeprecated && classes[i].tags("deprecated").length > 0) {
                continue;
            }
            if (classes[i].isClass()) {
                processClass(classes[i]);
            } else {    // this is an interface.
                processInterface(classes[i]);
                List list  = (List)implementingclasses.get(classes[i]);
                if (list != null) {
                    Collections.sort(list);
                }
            }
        }

        Collections.sort(baseinterfaces);
        for (Iterator it = subinterfaces.values().iterator(); it.hasNext(); ) {
            Collections.sort((List)it.next());
        }
        for (Iterator it = subclasses.values().iterator(); it.hasNext(); ) {
            Collections.sort((List)it.next());
        }
    
private java.util.Listget(java.util.Map map, com.sun.javadoc.ClassDoc cd)
From the map return the list of sub-classes or sub-interfaces. If list is null create a new one and return it.

param
map The entire map.
param
cd class for which the sub-class list is requested.
returns
List Sub-Class list for the class passed.

        List list = (List)map.get(cd);
        if (list == null) {
            return new ArrayList();
        }
        return list;
    
public java.util.Listimplementingclasses(com.sun.javadoc.ClassDoc cd)
Return the list of classes which implement the interface passed.

param
cd interface whose implementing-classes list is required.

        return get(implementingclasses, cd);
    
private voidprocessClass(com.sun.javadoc.ClassDoc cd)
For the class passed map it to it's own sub-class listing. For the Class passed, get the super class, if superclass is non null, (it is not "java.lang.Object") get the "value" from the hashmap for this key Class if entry not found create one and get that. add this Class as a sub class in the list Recurse till hits java.lang.Object Null SuperClass.

param
cd class for which sub-class mapping to be generated.

        ClassDoc superclass = cd.superclass();      
        if (superclass != null) {   
            if (!add(subclasses, superclass, cd)) {
                return;
            } else {
                processClass(superclass);      // Recurse
            }
        } else {     // cd is java.lang.Object, add it once to the list 
            if (!baseclasses.contains(cd)) {
                baseclasses.add(cd);
            }
        } 
        ClassDoc[] intfacs = cd.interfaces();
        for (int i = 0; i < intfacs.length; i++) {
            add(implementingclasses, intfacs[i], cd);    
        }
    
private voidprocessInterface(com.sun.javadoc.ClassDoc cd)
For the interface passed get the interfaces which it extends, and then put this interface in the sub-interface list of those interfaces. Do it recursively. If a interface doesn't have super-interface just attach that interface in the list of all the baseinterfaces.

param
cd Interface under consideration.

        ClassDoc[] intfacs = cd.interfaces();
        if (intfacs.length > 0) {
            for (int i = 0; i < intfacs.length; i++) {
                if (!add(subinterfaces, intfacs[i], cd)) {
                    return;
                } else {
                    processInterface(intfacs[i]);   // Recurse
                }
            }
        } else {   
            // we need to add all the interfaces who do not have
            // super-interfaces to baseinterfaces list to traverse them
            if (!baseinterfaces.contains(cd)) {
                baseinterfaces.add(cd);
            }
        }
    
public java.util.Listsubclasses(com.sun.javadoc.ClassDoc cd)
Return the sub-class list for the class passed.

param
cd class whose sub-class list is required.

        return get(subclasses, cd);
    
public java.util.Listsubinterfaces(com.sun.javadoc.ClassDoc cd)
Return the sub-interface list for the interface passed.

param
cd interface whose sub-interface list is required.

        return get(subinterfaces, cd);
    
public java.util.Listsubs(com.sun.javadoc.ClassDoc cd)
Return the sub-class/interface list for the class/interface passed.

param
cd class/interface whose sub-class/interface list is required.

        return get(cd.isInterface()? subinterfaces: subclasses, cd);