src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesIndexWriter.java
changeset 50167 cc705c956798
child 51260 b7a307084247
equal deleted inserted replaced
50166:1d683e243d8d 50167:cc705c956798
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 package jdk.javadoc.internal.doclets.formats.html;
       
    26 
       
    27 import java.util.ArrayList;
       
    28 import java.util.List;
       
    29 
       
    30 import javax.lang.model.element.Element;
       
    31 import javax.lang.model.element.TypeElement;
       
    32 
       
    33 import com.sun.source.doctree.DocTree;
       
    34 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
       
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
       
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
       
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
       
    38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
       
    39 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation;
       
    40 import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode;
       
    41 import jdk.javadoc.internal.doclets.formats.html.markup.Table;
       
    42 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
       
    43 import jdk.javadoc.internal.doclets.toolkit.Content;
       
    44 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
       
    45 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
       
    46 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
       
    47 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
       
    48 
       
    49 /**
       
    50  * Generate the file with list of all the classes in this run.
       
    51  */
       
    52 public class AllClassesIndexWriter extends HtmlDocletWriter {
       
    53 
       
    54     /**
       
    55      * Index of all the classes.
       
    56      */
       
    57     protected IndexBuilder indexbuilder;
       
    58 
       
    59     /**
       
    60      * The HTML tree for main tag.
       
    61      */
       
    62     protected HtmlTree mainTree = HtmlTree.MAIN();
       
    63 
       
    64     private final Navigation navBar;
       
    65 
       
    66     /**
       
    67      * Construct AllClassesFrameWriter object. Also initializes the indexbuilder variable in this
       
    68      * class.
       
    69      *
       
    70      * @param configuration The current configuration
       
    71      * @param filename Path to the file which is getting generated.
       
    72      * @param indexbuilder Unicode based Index from {@link IndexBuilder}
       
    73      */
       
    74     public AllClassesIndexWriter(HtmlConfiguration configuration,
       
    75             DocPath filename, IndexBuilder indexbuilder) {
       
    76         super(configuration, filename);
       
    77         this.indexbuilder = indexbuilder;
       
    78         this.navBar = new Navigation(null, configuration, fixedNavDiv, PageMode.ALLCLASSES, path);
       
    79     }
       
    80 
       
    81     /**
       
    82      * Create AllClassesIndexWriter object.
       
    83      *
       
    84      * @param configuration The current configuration
       
    85      * @param indexBuilder IndexBuilder object for all classes index.
       
    86      * @throws DocFileIOException
       
    87      */
       
    88     public static void generate(HtmlConfiguration configuration,
       
    89             IndexBuilder indexBuilder) throws DocFileIOException {
       
    90         generate(configuration, indexBuilder, DocPaths.ALLCLASSES_INDEX);
       
    91     }
       
    92 
       
    93     private static void generate(HtmlConfiguration configuration, IndexBuilder indexBuilder,
       
    94             DocPath fileName) throws DocFileIOException {
       
    95         AllClassesIndexWriter allClassGen = new AllClassesIndexWriter(configuration,
       
    96                 fileName, indexBuilder);
       
    97         allClassGen.buildAllClassesFile();
       
    98     }
       
    99 
       
   100     /**
       
   101      * Print all the classes in the file.
       
   102      */
       
   103     protected void buildAllClassesFile() throws DocFileIOException {
       
   104         String label = configuration.getText("doclet.All_Classes");
       
   105         HtmlTree bodyTree = getBody(true, getWindowTitle(label));
       
   106         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
       
   107                 ? HtmlTree.HEADER()
       
   108                 : bodyTree;
       
   109         addTop(htmlTree);
       
   110         navBar.setUserHeader(getUserHeaderFooter(true));
       
   111         htmlTree.addContent(navBar.getContent(true));
       
   112         if (configuration.allowTag(HtmlTag.HEADER)) {
       
   113             bodyTree.addContent(htmlTree);
       
   114         }
       
   115         Content allClassesContent = new ContentBuilder();
       
   116         addContents(allClassesContent);
       
   117         if (configuration.allowTag(HtmlTag.MAIN)) {
       
   118             mainTree.addContent(allClassesContent);
       
   119             bodyTree.addContent(mainTree);
       
   120         } else {
       
   121             bodyTree.addContent(allClassesContent);
       
   122         }
       
   123         Content tree = (configuration.allowTag(HtmlTag.FOOTER))
       
   124                 ? HtmlTree.FOOTER()
       
   125                 : bodyTree;
       
   126         navBar.setUserFooter(getUserHeaderFooter(false));
       
   127         tree.addContent(navBar.getContent(false));
       
   128         addBottom(tree);
       
   129         if (configuration.allowTag(HtmlTag.FOOTER)) {
       
   130             bodyTree.addContent(tree);
       
   131         }
       
   132         printHtmlDocument(null, true, bodyTree);
       
   133     }
       
   134 
       
   135     /**
       
   136      * Add all types to the content tree.
       
   137      *
       
   138      * @param content HtmlTree content to which the links will be added
       
   139      */
       
   140     protected void addContents(Content content) {
       
   141         Table table = new Table(configuration.htmlVersion, HtmlStyle.typeSummary)
       
   142                 .setSummary(resources.classTableSummary)
       
   143                 .setHeader(new TableHeader(contents.classLabel, contents.descriptionLabel))
       
   144                 .setRowScopeColumn(1)
       
   145                 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast)
       
   146                 .setDefaultTab(resources.getText("doclet.All_Classes"))
       
   147                 .addTab(resources.interfaceSummary, utils::isInterface)
       
   148                 .addTab(resources.classSummary, e -> utils.isOrdinaryClass((TypeElement)e))
       
   149                 .addTab(resources.enumSummary, utils::isEnum)
       
   150                 .addTab(resources.exceptionSummary, e -> utils.isException((TypeElement)e))
       
   151                 .addTab(resources.errorSummary, e -> utils.isError((TypeElement)e))
       
   152                 .addTab(resources.annotationTypeSummary, utils::isAnnotationType)
       
   153                 .setTabScript(i -> "show(" + i + ");")
       
   154                 .setUseTBody(false)
       
   155                 .setPutIdFirst(true);
       
   156         for (Character unicode : indexbuilder.index()) {
       
   157             for (Element element : indexbuilder.getMemberList(unicode)) {
       
   158                 TypeElement typeElement = (TypeElement) element;
       
   159                 if (!utils.isCoreClass(typeElement)) {
       
   160                     continue;
       
   161                 }
       
   162                 addTableRow(table, typeElement);
       
   163             }
       
   164         }
       
   165         Content titleContent = contents.allClassesLabel;
       
   166         Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
       
   167                 HtmlStyle.title, titleContent);
       
   168         Content headerDiv = HtmlTree.DIV(HtmlStyle.header, pHeading);
       
   169         content.addContent(headerDiv);
       
   170         if (!table.isEmpty()) {
       
   171             HtmlTree li = HtmlTree.LI(HtmlStyle.blockList, table.toContent());
       
   172             HtmlTree ul = HtmlTree.UL(HtmlStyle.blockList, li);
       
   173             HtmlTree div = new HtmlTree(HtmlTag.DIV);
       
   174             div.setStyle(HtmlStyle.allClassesContainer);
       
   175             div.addContent(ul);
       
   176             content.addContent(div);
       
   177             if (table.needsScript()) {
       
   178                 getMainBodyScript().append(table.getScript());
       
   179             }
       
   180         }
       
   181     }
       
   182 
       
   183     /**
       
   184      * Add table row.
       
   185      *
       
   186      * @param table the table to which the row will be added
       
   187      * @param klass the type to be added to the table
       
   188      */
       
   189     protected void addTableRow(Table table, TypeElement klass) {
       
   190         List<Content> rowContents = new ArrayList<>();
       
   191         Content classLink = getLink(new LinkInfoImpl(
       
   192                 configuration, LinkInfoImpl.Kind.INDEX, klass));
       
   193         ContentBuilder description = new ContentBuilder();
       
   194         if (utils.isDeprecated(klass)) {
       
   195             description.addContent(getDeprecatedPhrase(klass));
       
   196             List<? extends DocTree> tags = utils.getDeprecatedTrees(klass);
       
   197             if (!tags.isEmpty()) {
       
   198                 addSummaryDeprecatedComment(klass, tags.get(0), description);
       
   199             }
       
   200         } else {
       
   201             addSummaryComment(klass, description);
       
   202         }
       
   203         rowContents.add(classLink);
       
   204         rowContents.add(description);
       
   205         table.addRow(klass, rowContents);
       
   206     }
       
   207 }