duke@1: /* jjg@1357: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: duke@1: import java.io.*; duke@1: import java.util.*; jjg@1357: jjg@1357: import com.sun.javadoc.*; jjg@1357: import com.sun.tools.doclets.formats.html.markup.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Abstract class to print the class hierarchy page for all the Classes. This duke@1: * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to duke@1: * generate the Package Tree and global Tree(for all the classes and packages) duke@1: * pages. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public abstract class AbstractTreeWriter extends HtmlDocletWriter { duke@1: duke@1: /** duke@1: * The class and interface tree built by using {@link ClassTree} duke@1: */ duke@1: protected final ClassTree classtree; duke@1: bpatel@766: private static final String LI_CIRCLE = "circle"; bpatel@766: duke@1: /** jjg@1372: * Constructor initializes classtree variable. This constructor will be used duke@1: * while generating global tree file "overview-tree.html". duke@1: * jjg@1372: * @param configuration The current configuration duke@1: * @param filename File to be generated. duke@1: * @param classtree Tree built by {@link ClassTree}. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: protected AbstractTreeWriter(ConfigurationImpl configuration, jjg@1372: DocPath filename, ClassTree classtree) duke@1: throws IOException { duke@1: super(configuration, filename); duke@1: this.classtree = classtree; duke@1: } duke@1: duke@1: /** bpatel@766: * Add each level of the class tree. For each sub-class or duke@1: * sub-interface indents the next level information. bpatel@766: * Recurses itself to add subclasses info. duke@1: * bpatel@766: * @param parent the superclass or superinterface of the list bpatel@766: * @param list list of the sub-classes at this level bpatel@766: * @param isEnum true if we are generating a tree for enums bpatel@766: * @param contentTree the content tree to which the level information will be added duke@1: */ bpatel@766: protected void addLevelInfo(ClassDoc parent, List list, bpatel@766: boolean isEnum, Content contentTree) { bpatel@766: int size = list.size(); bpatel@766: if (size > 0) { bpatel@766: Content ul = new HtmlTree(HtmlTag.UL); bpatel@766: for (int i = 0; i < size; i++) { mcimadamore@184: ClassDoc local = list.get(i); bpatel@766: HtmlTree li = new HtmlTree(HtmlTag.LI); bpatel@766: li.addAttr(HtmlAttr.TYPE, LI_CIRCLE); bpatel@766: addPartialInfo(local, li); bpatel@766: addExtendsImplements(parent, local, li); bpatel@766: addLevelInfo(local, classtree.subs(local, isEnum), bpatel@766: isEnum, li); // Recurse bpatel@766: ul.addContent(li); duke@1: } bpatel@766: contentTree.addContent(ul); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add the heading for the tree depending upon tree type if it's a bpatel@766: * Class Tree or Interface tree. duke@1: * duke@1: * @param list List of classes which are at the most base level, all the bpatel@766: * other classes in this run will derive from these classes bpatel@766: * @param heading heading for the tree bpatel@766: * @param div the content tree to which the tree will be added duke@1: */ bpatel@766: protected void addTree(List list, String heading, Content div) { duke@1: if (list.size() > 0) { mcimadamore@184: ClassDoc firstClassDoc = list.get(0); bpatel@766: Content headingContent = getResource(heading); bpatel@766: div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, bpatel@766: headingContent)); bpatel@766: addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null, bpatel@766: list, list == classtree.baseEnums(), div); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add information regarding the classes which this class extends or duke@1: * implements. duke@1: * bpatel@766: * @param parent the parent class of the class being documented bpatel@766: * @param cd the classdoc under consideration bpatel@766: * @param contentTree the content tree to which the information will be added duke@1: */ bpatel@766: protected void addExtendsImplements(ClassDoc parent, ClassDoc cd, bpatel@766: Content contentTree) { duke@1: ClassDoc[] interfaces = cd.interfaces(); duke@1: if (interfaces.length > (cd.isInterface()? 1 : 0)) { duke@1: Arrays.sort(interfaces); duke@1: int counter = 0; duke@1: for (int i = 0; i < interfaces.length; i++) { duke@1: if (parent != interfaces[i]) { duke@1: if (! (interfaces[i].isPublic() || jjg@1410: Util.isLinkable(interfaces[i], configuration))) { duke@1: continue; duke@1: } duke@1: if (counter == 0) { duke@1: if (cd.isInterface()) { bpatel@766: contentTree.addContent(" ("); bpatel@766: contentTree.addContent(getResource("doclet.also")); bpatel@766: contentTree.addContent(" extends "); duke@1: } else { bpatel@766: contentTree.addContent(" (implements "); duke@1: } duke@1: } else { bpatel@766: contentTree.addContent(", "); duke@1: } bpatel@766: addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE, bpatel@766: interfaces[i], contentTree); duke@1: counter++; duke@1: } duke@1: } duke@1: if (counter > 0) { bpatel@766: contentTree.addContent(")"); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add information about the class kind, if it's a "class" or "interface". duke@1: * bpatel@766: * @param cd the class being documented bpatel@766: * @param contentTree the content tree to which the information will be added duke@1: */ bpatel@766: protected void addPartialInfo(ClassDoc cd, Content contentTree) { bpatel@766: addPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd, contentTree); duke@1: } duke@1: duke@1: /** bpatel@766: * Get the tree label for the navigation bar. duke@1: * bpatel@766: * @return a content tree for the tree label duke@1: */ bpatel@766: protected Content getNavLinkTree() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel); bpatel@766: return li; duke@1: } duke@1: }