/* * @(#)AbstractTreeWriter.java 1.8 98/02/24 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.tools.doclets.standard; import com.sun.tools.doclets.*; import com.sun.javadoc.*; import java.io.*; import java.lang.*; import java.util.*; /** * Abstract class to print the class hierarchy page for all the Classes. * Sub-classes to generate the Interface Tree and Class Tree Part. * * @author Atul M Dambalkar */ public abstract class AbstractTreeWriter extends HtmlStandardWriter { /** * The class and interface tree built. */ protected final ClassTree classtree; /** * Constructor. * * @param file String filename */ protected AbstractTreeWriter(String filename, ClassTree classtree) throws IOException, DocletAbortException { super(filename); this.classtree = classtree; } /* protected abstract void printClassLink(ClassDoc cd); protected abstract void printBoldClassLink(ClassDoc cd); */ /** * Constructor. * * @param file String filename */ protected AbstractTreeWriter(String path, String filename, ClassTree classtree, PackageDoc pkg) throws IOException, DocletAbortException { super(path, filename, DirectoryManager.getRelativePath(pkg.name())); this.classtree = classtree; } /** * Generate each line for level info regarding classes. * Recurses itself to generate subclasses info. * To iterate is human, to recurse is divine - L. Peter Deutsch. * * @param parent the superclass or superinterface of the list. * @param list list of the sub-classes at this level. */ protected void generateLevelInfo(ClassDoc parent, List list) { if (list.size() > 0) { ul(); for (int i = 0; i < list.size(); i++) { ClassDoc local = (ClassDoc)list.get(i); printPartialInfo(local); printExtendsImplements(parent, local); generateLevelInfo(local, classtree.subs(local)); // Recurse } ulEnd(); } } /** * Generate Tree method, to be called by the TreeWriter. Call appropriate * methods from the sub-classes. */ protected void generateTree(List list, String heading) { if (list.size() > 0) { ClassDoc cd = (ClassDoc)list.get(0); printTreeHeading(heading); generateLevelInfo(cd.isClass()? (ClassDoc)list.get(0): null, list); } } /** * Print the information regarding the classes which this class extends or * implements. * * @param cd The classdoc under consideration. */ protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) { ClassDoc[] interfaces = cd.interfaces(); if (interfaces.length > (cd.isInterface()? 1 : 0)) { Arrays.sort(interfaces); if (cd.isInterface()) { print("(" + getText("doclet.also") + " extends "); } else { print("(implements "); } boolean printcomma = false; for (int i = 0; i < interfaces.length; i++) { if (parent != interfaces[i]) { if (printcomma) { print(", "); } printPreQualifiedClassLink(interfaces[i]); printcomma = true; } } println(")"); } } /** * Print informatioon about the class kind. * * @param cd classdoc. */ protected void printPartialInfo(ClassDoc cd) { boolean isInterface = cd.isInterface(); li("circle"); print(isInterface? "interface " : "class "); printPreQualifiedBoldClassLink(cd); } /** * Print the heading for the tree depending upon if it's Interface Tree or * Class Tree. */ protected void printTreeHeading(String heading) { h2(); println(getText(heading)); h2End(); } /** * Print class/interface hierarchy link */ protected void navLinkTree() { boldText("doclet.Tree"); } }