src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.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/ConstantsSummaryWriterImpl.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,314 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 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 + * Write the Constants Summary Page in HTML format.
    1.41 + *
    1.42 + *  <p><b>This is NOT part of any supported API.
    1.43 + *  If you write code that depends on this, you do so at your own risk.
    1.44 + *  This code and its internal interfaces are subject to change or
    1.45 + *  deletion without notice.</b>
    1.46 + *
    1.47 + * @author Jamie Ho
    1.48 + * @author Bhavesh Patel (Modified)
    1.49 + * @since 1.4
    1.50 + */
    1.51 +public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
    1.52 +        implements ConstantsSummaryWriter {
    1.53 +
    1.54 +    /**
    1.55 +     * The configuration used in this run of the standard doclet.
    1.56 +     */
    1.57 +    ConfigurationImpl configuration;
    1.58 +
    1.59 +    /**
    1.60 +     * The current class being documented.
    1.61 +     */
    1.62 +    private ClassDoc currentClassDoc;
    1.63 +
    1.64 +    private final String constantsTableSummary;
    1.65 +
    1.66 +    private final String[] constantsTableHeader;
    1.67 +
    1.68 +    /**
    1.69 +     * Construct a ConstantsSummaryWriter.
    1.70 +     * @param configuration the configuration used in this run
    1.71 +     *        of the standard doclet.
    1.72 +     */
    1.73 +    public ConstantsSummaryWriterImpl(ConfigurationImpl configuration)
    1.74 +            throws IOException {
    1.75 +        super(configuration, DocPaths.CONSTANT_VALUES);
    1.76 +        this.configuration = configuration;
    1.77 +        constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary",
    1.78 +                configuration.getText("doclet.Constants_Summary"));
    1.79 +        constantsTableHeader = new String[] {
    1.80 +            getModifierTypeHeader(),
    1.81 +            configuration.getText("doclet.ConstantField"),
    1.82 +            configuration.getText("doclet.Value")
    1.83 +        };
    1.84 +    }
    1.85 +
    1.86 +    /**
    1.87 +     * {@inheritDoc}
    1.88 +     */
    1.89 +    public Content getHeader() {
    1.90 +        String label = configuration.getText("doclet.Constants_Summary");
    1.91 +        Content bodyTree = getBody(true, getWindowTitle(label));
    1.92 +        addTop(bodyTree);
    1.93 +        addNavLinks(true, bodyTree);
    1.94 +        return bodyTree;
    1.95 +    }
    1.96 +
    1.97 +    /**
    1.98 +     * {@inheritDoc}
    1.99 +     */
   1.100 +    public Content getContentsHeader() {
   1.101 +        return new HtmlTree(HtmlTag.UL);
   1.102 +    }
   1.103 +
   1.104 +    /**
   1.105 +     * {@inheritDoc}
   1.106 +     */
   1.107 +    public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName,
   1.108 +            Set<String> printedPackageHeaders, Content contentListTree) {
   1.109 +        String packageName = pkg.name();
   1.110 +        //add link to summary
   1.111 +        Content link;
   1.112 +        if (packageName.length() == 0) {
   1.113 +            link = getHyperLink(getDocLink(
   1.114 +                    SectionName.UNNAMED_PACKAGE_ANCHOR),
   1.115 +                    defaultPackageLabel, "", "");
   1.116 +        } else {
   1.117 +            Content packageNameContent = getPackageLabel(parsedPackageName);
   1.118 +            packageNameContent.addContent(".*");
   1.119 +            link = getHyperLink(DocLink.fragment(parsedPackageName),
   1.120 +                    packageNameContent, "", "");
   1.121 +            printedPackageHeaders.add(parsedPackageName);
   1.122 +        }
   1.123 +        contentListTree.addContent(HtmlTree.LI(link));
   1.124 +    }
   1.125 +
   1.126 +    /**
   1.127 +     * {@inheritDoc}
   1.128 +     */
   1.129 +    public Content getContentsList(Content contentListTree) {
   1.130 +        Content titleContent = getResource(
   1.131 +                "doclet.Constants_Summary");
   1.132 +        Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
   1.133 +                HtmlStyle.title, titleContent);
   1.134 +        Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
   1.135 +        Content headingContent = getResource(
   1.136 +                "doclet.Contents");
   1.137 +        div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
   1.138 +                headingContent));
   1.139 +        div.addContent(contentListTree);
   1.140 +        return div;
   1.141 +    }
   1.142 +
   1.143 +    /**
   1.144 +     * {@inheritDoc}
   1.145 +     */
   1.146 +    public Content getConstantSummaries() {
   1.147 +        HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV);
   1.148 +        summariesDiv.addStyle(HtmlStyle.constantValuesContainer);
   1.149 +        return summariesDiv;
   1.150 +    }
   1.151 +
   1.152 +    /**
   1.153 +     * {@inheritDoc}
   1.154 +     */
   1.155 +    public void addPackageName(PackageDoc pkg, String parsedPackageName,
   1.156 +            Content summariesTree) {
   1.157 +        Content pkgNameContent;
   1.158 +        if (parsedPackageName.length() == 0) {
   1.159 +            summariesTree.addContent(getMarkerAnchor(
   1.160 +                    SectionName.UNNAMED_PACKAGE_ANCHOR));
   1.161 +            pkgNameContent = defaultPackageLabel;
   1.162 +        } else {
   1.163 +            summariesTree.addContent(getMarkerAnchor(
   1.164 +                    parsedPackageName));
   1.165 +            pkgNameContent = getPackageLabel(parsedPackageName);
   1.166 +        }
   1.167 +        Content headingContent = new StringContent(".*");
   1.168 +        Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
   1.169 +                pkgNameContent);
   1.170 +        heading.addContent(headingContent);
   1.171 +        summariesTree.addContent(heading);
   1.172 +    }
   1.173 +
   1.174 +    /**
   1.175 +     * {@inheritDoc}
   1.176 +     */
   1.177 +    public Content getClassConstantHeader() {
   1.178 +        HtmlTree ul = new HtmlTree(HtmlTag.UL);
   1.179 +        ul.addStyle(HtmlStyle.blockList);
   1.180 +        return ul;
   1.181 +    }
   1.182 +
   1.183 +    /**
   1.184 +     * Get the table caption and header for the constant summary table
   1.185 +     *
   1.186 +     * @param cd classdoc to be documented
   1.187 +     * @return constant members header content
   1.188 +     */
   1.189 +    public Content getConstantMembersHeader(ClassDoc cd) {
   1.190 +        //generate links backward only to public classes.
   1.191 +        Content classlink = (cd.isPublic() || cd.isProtected()) ?
   1.192 +            getLink(new LinkInfoImpl(configuration,
   1.193 +                    LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)) :
   1.194 +            new StringContent(cd.qualifiedName());
   1.195 +        String name = cd.containingPackage().name();
   1.196 +        if (name.length() > 0) {
   1.197 +            Content cb = new ContentBuilder();
   1.198 +            cb.addContent(name);
   1.199 +            cb.addContent(".");
   1.200 +            cb.addContent(classlink);
   1.201 +            return getClassName(cb);
   1.202 +        } else {
   1.203 +            return getClassName(classlink);
   1.204 +        }
   1.205 +    }
   1.206 +
   1.207 +    /**
   1.208 +     * Get the class name in the table caption and the table header.
   1.209 +     *
   1.210 +     * @param classStr the class name to print.
   1.211 +     * @return the table caption and header
   1.212 +     */
   1.213 +    protected Content getClassName(Content classStr) {
   1.214 +        Content table = HtmlTree.TABLE(HtmlStyle.constantsSummary, 0, 3, 0, constantsTableSummary,
   1.215 +                getTableCaption(classStr));
   1.216 +        table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
   1.217 +        return table;
   1.218 +    }
   1.219 +
   1.220 +    /**
   1.221 +     * {@inheritDoc}
   1.222 +     */
   1.223 +    public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields,
   1.224 +            Content classConstantTree) {
   1.225 +        currentClassDoc = cd;
   1.226 +        Content tbody = new HtmlTree(HtmlTag.TBODY);
   1.227 +        for (int i = 0; i < fields.size(); ++i) {
   1.228 +            HtmlTree tr = new HtmlTree(HtmlTag.TR);
   1.229 +            if (i%2 == 0)
   1.230 +                tr.addStyle(HtmlStyle.altColor);
   1.231 +            else
   1.232 +                tr.addStyle(HtmlStyle.rowColor);
   1.233 +            addConstantMember(fields.get(i), tr);
   1.234 +            tbody.addContent(tr);
   1.235 +        }
   1.236 +        Content table = getConstantMembersHeader(cd);
   1.237 +        table.addContent(tbody);
   1.238 +        Content li = HtmlTree.LI(HtmlStyle.blockList, table);
   1.239 +        classConstantTree.addContent(li);
   1.240 +    }
   1.241 +
   1.242 +    /**
   1.243 +     * Add the row for the constant summary table.
   1.244 +     *
   1.245 +     * @param member the field to be documented.
   1.246 +     * @param trTree an htmltree object for the table row
   1.247 +     */
   1.248 +    private void addConstantMember(FieldDoc member, HtmlTree trTree) {
   1.249 +        trTree.addContent(getTypeColumn(member));
   1.250 +        trTree.addContent(getNameColumn(member));
   1.251 +        trTree.addContent(getValue(member));
   1.252 +    }
   1.253 +
   1.254 +    /**
   1.255 +     * Get the type column for the constant summary table row.
   1.256 +     *
   1.257 +     * @param member the field to be documented.
   1.258 +     * @return the type column of the constant table row
   1.259 +     */
   1.260 +    private Content getTypeColumn(FieldDoc member) {
   1.261 +        Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() +
   1.262 +                "." + member.name());
   1.263 +        Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor);
   1.264 +        Content code = new HtmlTree(HtmlTag.CODE);
   1.265 +        StringTokenizer mods = new StringTokenizer(member.modifiers());
   1.266 +        while(mods.hasMoreTokens()) {
   1.267 +            Content modifier = new StringContent(mods.nextToken());
   1.268 +            code.addContent(modifier);
   1.269 +            code.addContent(getSpace());
   1.270 +        }
   1.271 +        Content type = getLink(new LinkInfoImpl(configuration,
   1.272 +                LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type()));
   1.273 +        code.addContent(type);
   1.274 +        tdType.addContent(code);
   1.275 +        return tdType;
   1.276 +    }
   1.277 +
   1.278 +    /**
   1.279 +     * Get the name column for the constant summary table row.
   1.280 +     *
   1.281 +     * @param member the field to be documented.
   1.282 +     * @return the name column of the constant table row
   1.283 +     */
   1.284 +    private Content getNameColumn(FieldDoc member) {
   1.285 +        Content nameContent = getDocLink(
   1.286 +                LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false);
   1.287 +        Content code = HtmlTree.CODE(nameContent);
   1.288 +        return HtmlTree.TD(code);
   1.289 +    }
   1.290 +
   1.291 +    /**
   1.292 +     * Get the value column for the constant summary table row.
   1.293 +     *
   1.294 +     * @param member the field to be documented.
   1.295 +     * @return the value column of the constant table row
   1.296 +     */
   1.297 +    private Content getValue(FieldDoc member) {
   1.298 +        Content valueContent = new StringContent(member.constantValueExpression());
   1.299 +        Content code = HtmlTree.CODE(valueContent);
   1.300 +        return HtmlTree.TD(HtmlStyle.colLast, code);
   1.301 +    }
   1.302 +
   1.303 +    /**
   1.304 +     * {@inheritDoc}
   1.305 +     */
   1.306 +    public void addFooter(Content contentTree) {
   1.307 +        addNavLinks(false, contentTree);
   1.308 +        addBottom(contentTree);
   1.309 +    }
   1.310 +
   1.311 +    /**
   1.312 +     * {@inheritDoc}
   1.313 +     */
   1.314 +    public void printDocument(Content contentTree) throws IOException {
   1.315 +        printHtmlDocument(null, true, contentTree);
   1.316 +    }
   1.317 +}

mercurial