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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,185 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.formats.html;
    1.30 +
    1.31 +import java.io.*;
    1.32 +import java.util.*;
    1.33 +
    1.34 +import com.sun.javadoc.*;
    1.35 +import com.sun.tools.doclets.formats.html.markup.*;
    1.36 +import com.sun.tools.doclets.internal.toolkit.*;
    1.37 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.38 +
    1.39 +/**
    1.40 + * Abstract class to print the class hierarchy page for all the Classes. This
    1.41 + * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
    1.42 + * generate the Package Tree and global Tree(for all the classes and packages)
    1.43 + * pages.
    1.44 + *
    1.45 + *  <p><b>This is NOT part of any supported API.
    1.46 + *  If you write code that depends on this, you do so at your own risk.
    1.47 + *  This code and its internal interfaces are subject to change or
    1.48 + *  deletion without notice.</b>
    1.49 + *
    1.50 + * @author Atul M Dambalkar
    1.51 + */
    1.52 +public abstract class AbstractTreeWriter extends HtmlDocletWriter {
    1.53 +
    1.54 +    /**
    1.55 +     * The class and interface tree built by using {@link ClassTree}
    1.56 +     */
    1.57 +    protected final ClassTree classtree;
    1.58 +
    1.59 +    private static final String LI_CIRCLE  = "circle";
    1.60 +
    1.61 +    /**
    1.62 +     * Constructor initializes classtree variable. This constructor will be used
    1.63 +     * while generating global tree file "overview-tree.html".
    1.64 +     *
    1.65 +     * @param configuration  The current configuration
    1.66 +     * @param filename   File to be generated.
    1.67 +     * @param classtree  Tree built by {@link ClassTree}.
    1.68 +     * @throws IOException
    1.69 +     * @throws DocletAbortException
    1.70 +     */
    1.71 +    protected AbstractTreeWriter(ConfigurationImpl configuration,
    1.72 +                                 DocPath filename, ClassTree classtree)
    1.73 +                                 throws IOException {
    1.74 +        super(configuration, filename);
    1.75 +        this.classtree = classtree;
    1.76 +    }
    1.77 +
    1.78 +    /**
    1.79 +     * Add each level of the class tree. For each sub-class or
    1.80 +     * sub-interface indents the next level information.
    1.81 +     * Recurses itself to add subclasses info.
    1.82 +     *
    1.83 +     * @param parent the superclass or superinterface of the list
    1.84 +     * @param list list of the sub-classes at this level
    1.85 +     * @param isEnum true if we are generating a tree for enums
    1.86 +     * @param contentTree the content tree to which the level information will be added
    1.87 +     */
    1.88 +    protected void addLevelInfo(ClassDoc parent, List<ClassDoc> list,
    1.89 +            boolean isEnum, Content contentTree) {
    1.90 +        int size = list.size();
    1.91 +        if (size > 0) {
    1.92 +            Content ul = new HtmlTree(HtmlTag.UL);
    1.93 +            for (int i = 0; i < size; i++) {
    1.94 +                ClassDoc local = list.get(i);
    1.95 +                HtmlTree li = new HtmlTree(HtmlTag.LI);
    1.96 +                li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
    1.97 +                addPartialInfo(local, li);
    1.98 +                addExtendsImplements(parent, local, li);
    1.99 +                addLevelInfo(local, classtree.subs(local, isEnum),
   1.100 +                        isEnum, li);   // Recurse
   1.101 +                ul.addContent(li);
   1.102 +            }
   1.103 +            contentTree.addContent(ul);
   1.104 +        }
   1.105 +    }
   1.106 +
   1.107 +    /**
   1.108 +     * Add the heading for the tree depending upon tree type if it's a
   1.109 +     * Class Tree or Interface tree.
   1.110 +     *
   1.111 +     * @param list List of classes which are at the most base level, all the
   1.112 +     * other classes in this run will derive from these classes
   1.113 +     * @param heading heading for the tree
   1.114 +     * @param div the content tree to which the tree will be added
   1.115 +     */
   1.116 +    protected void addTree(List<ClassDoc> list, String heading, Content div) {
   1.117 +        if (list.size() > 0) {
   1.118 +            ClassDoc firstClassDoc = list.get(0);
   1.119 +            Content headingContent = getResource(heading);
   1.120 +            div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
   1.121 +                    headingContent));
   1.122 +            addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
   1.123 +                    list, list == classtree.baseEnums(), div);
   1.124 +        }
   1.125 +    }
   1.126 +
   1.127 +    /**
   1.128 +     * Add information regarding the classes which this class extends or
   1.129 +     * implements.
   1.130 +     *
   1.131 +     * @param parent the parent class of the class being documented
   1.132 +     * @param cd the classdoc under consideration
   1.133 +     * @param contentTree the content tree to which the information will be added
   1.134 +     */
   1.135 +    protected void addExtendsImplements(ClassDoc parent, ClassDoc cd,
   1.136 +            Content contentTree) {
   1.137 +        ClassDoc[] interfaces = cd.interfaces();
   1.138 +        if (interfaces.length > (cd.isInterface()? 1 : 0)) {
   1.139 +            Arrays.sort(interfaces);
   1.140 +            int counter = 0;
   1.141 +            for (int i = 0; i < interfaces.length; i++) {
   1.142 +                if (parent != interfaces[i]) {
   1.143 +                    if (! (interfaces[i].isPublic() ||
   1.144 +                            Util.isLinkable(interfaces[i], configuration))) {
   1.145 +                        continue;
   1.146 +                    }
   1.147 +                    if (counter == 0) {
   1.148 +                        if (cd.isInterface()) {
   1.149 +                            contentTree.addContent(" (");
   1.150 +                            contentTree.addContent(getResource("doclet.also"));
   1.151 +                            contentTree.addContent(" extends ");
   1.152 +                        } else {
   1.153 +                            contentTree.addContent(" (implements ");
   1.154 +                        }
   1.155 +                    } else {
   1.156 +                        contentTree.addContent(", ");
   1.157 +                    }
   1.158 +                    addPreQualifiedClassLink(LinkInfoImpl.Kind.TREE,
   1.159 +                            interfaces[i], contentTree);
   1.160 +                    counter++;
   1.161 +                }
   1.162 +            }
   1.163 +            if (counter > 0) {
   1.164 +                contentTree.addContent(")");
   1.165 +            }
   1.166 +        }
   1.167 +    }
   1.168 +
   1.169 +    /**
   1.170 +     * Add information about the class kind, if it's a "class" or "interface".
   1.171 +     *
   1.172 +     * @param cd the class being documented
   1.173 +     * @param contentTree the content tree to which the information will be added
   1.174 +     */
   1.175 +    protected void addPartialInfo(ClassDoc cd, Content contentTree) {
   1.176 +        addPreQualifiedStrongClassLink(LinkInfoImpl.Kind.TREE, cd, contentTree);
   1.177 +    }
   1.178 +
   1.179 +    /**
   1.180 +     * Get the tree label for the navigation bar.
   1.181 +     *
   1.182 +     * @return a content tree for the tree label
   1.183 +     */
   1.184 +    protected Content getNavLinkTree() {
   1.185 +        Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel);
   1.186 +        return li;
   1.187 +    }
   1.188 +}

mercurial