langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractTreeWriter.java
author bpatel
Thu, 08 Jan 2009 16:26:59 -0800
changeset 1787 1aa079321cd2
parent 10 06bc494ca11e
child 1789 7ac8c0815000
permissions -rw-r--r--
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2004 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.formats.html;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Abstract class to print the class hierarchy page for all the Classes. This
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * generate the Package Tree and global Tree(for all the classes and packages)
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * pages.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
public abstract class AbstractTreeWriter extends HtmlDocletWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     * The class and interface tree built by using {@link ClassTree}
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    protected final ClassTree classtree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     * Constructor initilises classtree variable. This constructor will be used
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
     * while generating global tree file "overview-tree.html".
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * @param filename   File to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * @param classtree  Tree built by {@link ClassTree}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    protected AbstractTreeWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
                                 String filename, ClassTree classtree)
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
                                 throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        super(configuration, filename);
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        this.classtree = classtree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * Create appropriate directory for the package and also initilise the
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     * relative path from this generated file to the current or
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * the destination directory. This constructor will be used while
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * generating "package tree" file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * @param path Directories in this path will be created if they are not
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * already there.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * @param filename Name of the package tree file to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @param classtree The tree built using {@link ClassTree}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * for the package pkg.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @param pkg PackageDoc for which tree file will be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @throws IOException
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * @throws DocletAbortException
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    protected AbstractTreeWriter(ConfigurationImpl configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
                                 String path, String filename,
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                                 ClassTree classtree, PackageDoc pkg)
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                                 throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        super(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
              path, filename, DirectoryManager.getRelativePath(pkg.name()));
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        this.classtree = classtree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * Generate each level of the class tree. For each sub-class or
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     * sub-interface indents the next level information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Recurses itself to generate subclasses info.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * To iterate is human, to recurse is divine - L. Peter Deutsch.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * @param parent the superclass or superinterface of the list.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * @param list list of the sub-classes at this level.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * @param isEnum true if we are generating a tree for enums.
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    protected void generateLevelInfo(ClassDoc parent, List list,
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
            boolean isEnum) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        if (list.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            ul();
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            for (int i = 0; i < list.size(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                ClassDoc local = (ClassDoc)list.get(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                printPartialInfo(local);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
                printExtendsImplements(parent, local);
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                generateLevelInfo(local, classtree.subs(local, isEnum),
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
                    isEnum);   // Recurse
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            ulEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     * Generate the heading for the tree depending upon tree type if it's a
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     * Class Tree or Interface tree and also print the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     * @param list List of classes which are at the most base level, all the
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
     * other classes in this run will derive from these classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * @param heading Heading for the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    protected void generateTree(List list, String heading) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        if (list.size() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
            ClassDoc firstClassDoc = (ClassDoc)list.get(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
            printTreeHeading(heading);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
            generateLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                list,
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                list == classtree.baseEnums());
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * Print the information regarding the classes which this class extends or
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * implements.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * @param cd The classdoc under consideration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        ClassDoc[] interfaces = cd.interfaces();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        if (interfaces.length > (cd.isInterface()? 1 : 0)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            Arrays.sort(interfaces);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            int counter = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            for (int i = 0; i < interfaces.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                if (parent != interfaces[i]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                    if (! (interfaces[i].isPublic() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                            Util.isLinkable(interfaces[i], configuration()))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                        continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                    if (counter == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                        if (cd.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                            print(" (" + configuration.getText("doclet.also") + " extends ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                            print(" (implements ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                        print(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                    printPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                        interfaces[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                    counter++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            if (counter > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                println(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Print information about the class kind, if it's a "class" or "interface".
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * @param cd classdoc.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    protected void printPartialInfo(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        li("circle");
1787
1aa079321cd2 6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents: 10
diff changeset
   176
        printPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * Print the heading for the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * @param heading Heading for the tree.
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    protected void printTreeHeading(String heading) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        h2();
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        println(configuration.getText(heading));
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        h2End();
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * Highlight "Tree" word in the navigation bar, since this is the tree page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    protected void navLinkTree() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        navCellRevStart();
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        fontStyle("NavBarFont1Rev");
1787
1aa079321cd2 6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents: 10
diff changeset
   196
        strongText("doclet.Tree");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        fontEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        navCellEnd();
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
}