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

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