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