src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1735
8ea30d59ac41
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html;
aoqi@0 27
aoqi@0 28 import java.io.*;
aoqi@0 29 import java.util.*;
aoqi@0 30
aoqi@0 31 import com.sun.javadoc.*;
aoqi@0 32 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Abstract class to print the class hierarchy page for all the Classes. This
aoqi@0 38 * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
aoqi@0 39 * generate the Package Tree and global Tree(for all the classes and packages)
aoqi@0 40 * pages.
aoqi@0 41 *
aoqi@0 42 * <p><b>This is NOT part of any supported API.
aoqi@0 43 * If you write code that depends on this, you do so at your own risk.
aoqi@0 44 * This code and its internal interfaces are subject to change or
aoqi@0 45 * deletion without notice.</b>
aoqi@0 46 *
aoqi@0 47 * @author Atul M Dambalkar
aoqi@0 48 */
aoqi@0 49 public abstract class AbstractTreeWriter extends HtmlDocletWriter {
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * The class and interface tree built by using {@link ClassTree}
aoqi@0 53 */
aoqi@0 54 protected final ClassTree classtree;
aoqi@0 55
aoqi@0 56 private static final String LI_CIRCLE = "circle";
aoqi@0 57
aoqi@0 58 /**
aoqi@0 59 * Constructor initializes classtree variable. This constructor will be used
aoqi@0 60 * while generating global tree file "overview-tree.html".
aoqi@0 61 *
aoqi@0 62 * @param configuration The current configuration
aoqi@0 63 * @param filename File to be generated.
aoqi@0 64 * @param classtree Tree built by {@link ClassTree}.
aoqi@0 65 * @throws IOException
aoqi@0 66 * @throws DocletAbortException
aoqi@0 67 */
aoqi@0 68 protected AbstractTreeWriter(ConfigurationImpl configuration,
aoqi@0 69 DocPath filename, ClassTree classtree)
aoqi@0 70 throws IOException {
aoqi@0 71 super(configuration, filename);
aoqi@0 72 this.classtree = classtree;
aoqi@0 73 }
aoqi@0 74
aoqi@0 75 /**
aoqi@0 76 * Add each level of the class tree. For each sub-class or
aoqi@0 77 * sub-interface indents the next level information.
aoqi@0 78 * Recurses itself to add subclasses info.
aoqi@0 79 *
aoqi@0 80 * @param parent the superclass or superinterface of the list
aoqi@0 81 * @param list list of the sub-classes at this level
aoqi@0 82 * @param isEnum true if we are generating a tree for enums
aoqi@0 83 * @param contentTree the content tree to which the level information will be added
aoqi@0 84 */
aoqi@0 85 protected void addLevelInfo(ClassDoc parent, List<ClassDoc> list,
aoqi@0 86 boolean isEnum, Content contentTree) {
aoqi@0 87 int size = list.size();
aoqi@0 88 if (size > 0) {
aoqi@0 89 Content ul = new HtmlTree(HtmlTag.UL);
aoqi@0 90 for (int i = 0; i < size; i++) {
aoqi@0 91 ClassDoc local = list.get(i);
aoqi@0 92 HtmlTree li = new HtmlTree(HtmlTag.LI);
aoqi@0 93 li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
aoqi@0 94 addPartialInfo(local, li);
aoqi@0 95 addExtendsImplements(parent, local, li);
aoqi@0 96 addLevelInfo(local, classtree.subs(local, isEnum),
aoqi@0 97 isEnum, li); // Recurse
aoqi@0 98 ul.addContent(li);
aoqi@0 99 }
aoqi@0 100 contentTree.addContent(ul);
aoqi@0 101 }
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Add the heading for the tree depending upon tree type if it's a
aoqi@0 106 * Class Tree or Interface tree.
aoqi@0 107 *
aoqi@0 108 * @param list List of classes which are at the most base level, all the
aoqi@0 109 * other classes in this run will derive from these classes
aoqi@0 110 * @param heading heading for the tree
aoqi@0 111 * @param div the content tree to which the tree will be added
aoqi@0 112 */
aoqi@0 113 protected void addTree(List<ClassDoc> list, String heading, Content div) {
aoqi@0 114 if (list.size() > 0) {
aoqi@0 115 ClassDoc firstClassDoc = list.get(0);
aoqi@0 116 Content headingContent = getResource(heading);
aoqi@0 117 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
aoqi@0 118 headingContent));
aoqi@0 119 addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
aoqi@0 120 list, list == classtree.baseEnums(), div);
aoqi@0 121 }
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 /**
aoqi@0 125 * Add information regarding the classes which this class extends or
aoqi@0 126 * implements.
aoqi@0 127 *
aoqi@0 128 * @param parent the parent class of the class being documented
aoqi@0 129 * @param cd the classdoc under consideration
aoqi@0 130 * @param contentTree the content tree to which the information will be added
aoqi@0 131 */
aoqi@0 132 protected void addExtendsImplements(ClassDoc parent, ClassDoc cd,
aoqi@0 133 Content contentTree) {
aoqi@0 134 ClassDoc[] interfaces = cd.interfaces();
aoqi@0 135 if (interfaces.length > (cd.isInterface()? 1 : 0)) {
aoqi@0 136 Arrays.sort(interfaces);
aoqi@0 137 int counter = 0;
aoqi@0 138 for (int i = 0; i < interfaces.length; i++) {
aoqi@0 139 if (parent != interfaces[i]) {
aoqi@0 140 if (! (interfaces[i].isPublic() ||
aoqi@0 141 Util.isLinkable(interfaces[i], configuration))) {
aoqi@0 142 continue;
aoqi@0 143 }
aoqi@0 144 if (counter == 0) {
aoqi@0 145 if (cd.isInterface()) {
aoqi@0 146 contentTree.addContent(" (");
aoqi@0 147 contentTree.addContent(getResource("doclet.also"));
aoqi@0 148 contentTree.addContent(" extends ");
aoqi@0 149 } else {
aoqi@0 150 contentTree.addContent(" (implements ");
aoqi@0 151 }
aoqi@0 152 } else {
aoqi@0 153 contentTree.addContent(", ");
aoqi@0 154 }
aoqi@0 155 addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE,
aoqi@0 156 interfaces[i], contentTree);
aoqi@0 157 counter++;
aoqi@0 158 }
aoqi@0 159 }
aoqi@0 160 if (counter > 0) {
aoqi@0 161 contentTree.addContent(")");
aoqi@0 162 }
aoqi@0 163 }
aoqi@0 164 }
aoqi@0 165
aoqi@0 166 /**
aoqi@0 167 * Add information about the class kind, if it's a "class" or "interface".
aoqi@0 168 *
aoqi@0 169 * @param cd the class being documented
aoqi@0 170 * @param contentTree the content tree to which the information will be added
aoqi@0 171 */
aoqi@0 172 protected void addPartialInfo(ClassDoc cd, Content contentTree) {
aoqi@0 173 addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree);
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 /**
aoqi@0 177 * Get the tree label for the navigation bar.
aoqi@0 178 *
aoqi@0 179 * @return a content tree for the tree label
aoqi@0 180 */
aoqi@0 181 protected Content getNavLinkTree() {
aoqi@0 182 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel);
aoqi@0 183 return li;
aoqi@0 184 }
aoqi@0 185 }

mercurial