1 /*
   2  * Copyright (c) 2003, 2019, 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 
  26 package jdk.javadoc.internal.doclets.formats.html;
  27 
  28 
  29 import javax.lang.model.element.Element;
  30 import javax.lang.model.element.TypeElement;
  31 import javax.lang.model.element.VariableElement;
  32 
  33 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
  34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
  35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
  36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
  37 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
  38 import jdk.javadoc.internal.doclets.formats.html.markup.Table;
  39 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
  40 import jdk.javadoc.internal.doclets.toolkit.Content;
  41 import jdk.javadoc.internal.doclets.toolkit.EnumConstantWriter;
  42 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  43 
  44 /**
  45  * Writes enum constant documentation in HTML format.
  46  *
  47  *  <p><b>This is NOT part of any supported API.
  48  *  If you write code that depends on this, you do so at your own risk.
  49  *  This code and its internal interfaces are subject to change or
  50  *  deletion without notice.</b>
  51  *
  52  * @author Jamie Ho
  53  * @author Bhavesh Patel (Modified)
  54  */
  55 public class EnumConstantWriterImpl extends AbstractMemberWriter
  56     implements EnumConstantWriter, MemberSummaryWriter {
  57 
  58     public EnumConstantWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) {
  59         super(writer, typeElement);
  60     }
  61 
  62     public EnumConstantWriterImpl(SubWriterHolderWriter writer) {
  63         super(writer);
  64     }
  65 
  66     /**
  67      * {@inheritDoc}
  68      */
  69     @Override
  70     public Content getMemberSummaryHeader(TypeElement typeElement,
  71             Content memberSummaryTree) {
  72         memberSummaryTree.add(MarkerComments.START_OF_ENUM_CONSTANT_SUMMARY);
  73         Content memberTree = new ContentBuilder();
  74         writer.addSummaryHeader(this, typeElement, memberTree);
  75         return memberTree;
  76     }
  77 
  78     /**
  79      * {@inheritDoc}
  80      */
  81     @Override
  82     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  83         writer.addMemberTree(HtmlStyle.constantsSummary, memberSummaryTree, memberTree);
  84     }
  85 
  86     /**
  87      * {@inheritDoc}
  88      */
  89     @Override
  90     public Content getEnumConstantsDetailsTreeHeader(TypeElement typeElement,
  91             Content memberDetailsTree) {
  92         memberDetailsTree.add(MarkerComments.START_OF_ENUM_CONSTANT_DETAILS);
  93         Content enumConstantsDetailsTree = new ContentBuilder();
  94         Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
  95                 contents.enumConstantDetailLabel);
  96         enumConstantsDetailsTree.add(heading);
  97         enumConstantsDetailsTree.add(links.createAnchor(
  98                 SectionName.ENUM_CONSTANT_DETAIL));
  99         return enumConstantsDetailsTree;
 100     }
 101 
 102     /**
 103      * {@inheritDoc}
 104      */
 105     @Override
 106     public Content getEnumConstantsTreeHeader(VariableElement enumConstant,
 107             Content enumConstantsDetailsTree) {
 108         Content enumConstantsTree = new ContentBuilder();
 109         Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING);
 110         heading.add(name(enumConstant));
 111         enumConstantsTree.add(heading);
 112         enumConstantsTree.add(links.createAnchor(name(enumConstant)));
 113         return HtmlTree.SECTION(HtmlStyle.detail, enumConstantsTree);
 114     }
 115 
 116     /**
 117      * {@inheritDoc}
 118      */
 119     @Override
 120     public Content getSignature(VariableElement enumConstant) {
 121         Content pre = new HtmlTree(HtmlTag.PRE);
 122         writer.addAnnotationInfo(enumConstant, pre);
 123         addModifiers(enumConstant, pre);
 124         Content enumConstantLink = writer.getLink(new LinkInfoImpl(
 125                 configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.asType()));
 126         pre.add(enumConstantLink);
 127         pre.add(" ");
 128         if (configuration.linksource) {
 129             Content enumConstantName = new StringContent(name(enumConstant));
 130             writer.addSrcLink(enumConstant, enumConstantName, pre);
 131         } else {
 132             addName(name(enumConstant), pre);
 133         }
 134         return pre;
 135     }
 136 
 137     /**
 138      * {@inheritDoc}
 139      */
 140     @Override
 141     public void addDeprecated(VariableElement enumConstant, Content enumConstantsTree) {
 142         addDeprecatedInfo(enumConstant, enumConstantsTree);
 143     }
 144 
 145     /**
 146      * {@inheritDoc}
 147      */
 148     @Override
 149     public void addComments(VariableElement enumConstant, Content enumConstantsTree) {
 150         addComment(enumConstant, enumConstantsTree);
 151     }
 152 
 153     /**
 154      * {@inheritDoc}
 155      */
 156     @Override
 157     public void addTags(VariableElement enumConstant, Content enumConstantsTree) {
 158         writer.addTagsInfo(enumConstant, enumConstantsTree);
 159     }
 160 
 161     /**
 162      * {@inheritDoc}
 163      */
 164     @Override
 165     public Content getEnumConstantsDetails(Content enumConstantsDetailsTreeHeader,
 166             Content enumConstantsDetailsTree) {
 167         Content enumConstantsDetails =
 168                 new ContentBuilder(enumConstantsDetailsTreeHeader, enumConstantsDetailsTree);
 169         return getMemberTree(HtmlTree.SECTION(HtmlStyle.constantDetails, enumConstantsDetails));
 170     }
 171 
 172     /**
 173      * {@inheritDoc}
 174      */
 175     @Override
 176     public Content getEnumConstants(Content enumConstantsTree,
 177             boolean isLastContent) {
 178         return getMemberTree(enumConstantsTree, isLastContent);
 179     }
 180 
 181     /**
 182      * {@inheritDoc}
 183      */
 184     @Override
 185     public void addSummaryLabel(Content memberTree) {
 186         Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
 187                 contents.enumConstantSummary);
 188         memberTree.add(label);
 189     }
 190 
 191     /**
 192      * {@inheritDoc}
 193      */
 194     @Override
 195     public TableHeader getSummaryTableHeader(Element member) {
 196         return new TableHeader(contents.enumConstantLabel, contents.descriptionLabel);
 197     }
 198 
 199     /**
 200      * {@inheritDoc}
 201      */
 202     @Override
 203     protected Table createSummaryTable() {
 204         return new Table(HtmlStyle.memberSummary)
 205                 .setCaption(contents.getContent("doclet.Enum_Constants"))
 206                 .setHeader(getSummaryTableHeader(typeElement))
 207                 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
 208     }
 209 
 210     /**
 211      * {@inheritDoc}
 212      */
 213     @Override
 214     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 215         memberTree.add(links.createAnchor(SectionName.ENUM_CONSTANT_SUMMARY));
 216     }
 217 
 218     /**
 219      * {@inheritDoc}
 220      */
 221     @Override
 222     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 223     }
 224 
 225     /**
 226      * {@inheritDoc}
 227      */
 228     @Override
 229     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 230     }
 231 
 232     /**
 233      * {@inheritDoc}
 234      */
 235     @Override
 236     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 237             Content tdSummary) {
 238         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 239                 writer.getDocLink(context, member, name(member), false));
 240         Content code = HtmlTree.CODE(memberLink);
 241         tdSummary.add(code);
 242     }
 243 
 244     /**
 245      * {@inheritDoc}
 246      */
 247     @Override
 248     protected void addInheritedSummaryLink(TypeElement typeElement, Element member, Content linksTree) {
 249     }
 250 
 251     /**
 252      * {@inheritDoc}
 253      */
 254     @Override
 255     protected void addSummaryType(Element member, Content tdSummaryType) {
 256         //Not applicable.
 257     }
 258 
 259     /**
 260      * {@inheritDoc}
 261      */
 262     @Override
 263     protected Content getDeprecatedLink(Element member) {
 264         String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
 265         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
 266     }
 267 
 268     @Override
 269     public Content getMemberTreeHeader(){
 270         return writer.getMemberTreeHeader();
 271     }
 272 }