src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/EnumConstantWriterImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2015, 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 com.sun.tools.doclets.formats.html;
  27 
  28 import java.io.*;
  29 
  30 import com.sun.javadoc.*;
  31 import com.sun.tools.doclets.formats.html.markup.*;
  32 import com.sun.tools.doclets.internal.toolkit.*;
  33 import com.sun.tools.doclets.internal.toolkit.util.*;
  34 













  35 /**
  36  * Writes enum constant documentation in HTML format.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  *
  43  * @author Jamie Ho
  44  * @author Bhavesh Patel (Modified)
  45  */
  46 public class EnumConstantWriterImpl extends AbstractMemberWriter
  47     implements EnumConstantWriter, MemberSummaryWriter {
  48 
  49     public EnumConstantWriterImpl(SubWriterHolderWriter writer,
  50         ClassDoc classdoc) {
  51         super(writer, classdoc);
  52     }
  53 
  54     public EnumConstantWriterImpl(SubWriterHolderWriter writer) {
  55         super(writer);
  56     }
  57 
  58     /**
  59      * {@inheritDoc}
  60      */
  61     public Content getMemberSummaryHeader(ClassDoc classDoc,

  62             Content memberSummaryTree) {
  63         memberSummaryTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_SUMMARY);
  64         Content memberTree = writer.getMemberTreeHeader();
  65         writer.addSummaryHeader(this, classDoc, memberTree);
  66         return memberTree;
  67     }
  68 
  69     /**
  70      * {@inheritDoc}
  71      */
  72     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  73         writer.addMemberTree(memberSummaryTree, memberTree);
  74     }
  75 
  76     /**
  77      * {@inheritDoc}
  78      */
  79     public Content getEnumConstantsDetailsTreeHeader(ClassDoc classDoc,

  80             Content memberDetailsTree) {
  81         memberDetailsTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_DETAILS);
  82         Content enumConstantsDetailsTree = writer.getMemberTreeHeader();
  83         enumConstantsDetailsTree.addContent(writer.getMarkerAnchor(
  84                 SectionName.ENUM_CONSTANT_DETAIL));
  85         Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
  86                 writer.enumConstantsDetailsLabel);
  87         enumConstantsDetailsTree.addContent(heading);
  88         return enumConstantsDetailsTree;
  89     }
  90 
  91     /**
  92      * {@inheritDoc}
  93      */
  94     public Content getEnumConstantsTreeHeader(FieldDoc enumConstant,

  95             Content enumConstantsDetailsTree) {
  96         enumConstantsDetailsTree.addContent(
  97                 writer.getMarkerAnchor(enumConstant.name()));
  98         Content enumConstantsTree = writer.getMemberTreeHeader();
  99         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
 100         heading.addContent(enumConstant.name());
 101         enumConstantsTree.addContent(heading);
 102         return enumConstantsTree;
 103     }
 104 
 105     /**
 106      * {@inheritDoc}
 107      */
 108     public Content getSignature(FieldDoc enumConstant) {

 109         Content pre = new HtmlTree(HtmlTag.PRE);
 110         writer.addAnnotationInfo(enumConstant, pre);
 111         addModifiers(enumConstant, pre);
 112         Content enumConstantLink = writer.getLink(new LinkInfoImpl(
 113                 configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.type()));
 114         pre.addContent(enumConstantLink);
 115         pre.addContent(" ");
 116         if (configuration.linksource) {
 117             Content enumConstantName = new StringContent(enumConstant.name());
 118             writer.addSrcLink(enumConstant, enumConstantName, pre);
 119         } else {
 120             addName(enumConstant.name(), pre);
 121         }
 122         return pre;
 123     }
 124 
 125     /**
 126      * {@inheritDoc}
 127      */
 128     public void addDeprecated(FieldDoc enumConstant, Content enumConstantsTree) {

 129         addDeprecatedInfo(enumConstant, enumConstantsTree);
 130     }
 131 
 132     /**
 133      * {@inheritDoc}
 134      */
 135     public void addComments(FieldDoc enumConstant, Content enumConstantsTree) {

 136         addComment(enumConstant, enumConstantsTree);
 137     }
 138 
 139     /**
 140      * {@inheritDoc}
 141      */
 142     public void addTags(FieldDoc enumConstant, Content enumConstantsTree) {

 143         writer.addTagsInfo(enumConstant, enumConstantsTree);
 144     }
 145 
 146     /**
 147      * {@inheritDoc}
 148      */

 149     public Content getEnumConstantsDetails(Content enumConstantsDetailsTree) {
 150         if (configuration.allowTag(HtmlTag.SECTION)) {
 151             HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(enumConstantsDetailsTree));
 152             return htmlTree;
 153         }
 154         return getMemberTree(enumConstantsDetailsTree);
 155     }
 156 
 157     /**
 158      * {@inheritDoc}
 159      */

 160     public Content getEnumConstants(Content enumConstantsTree,
 161             boolean isLastContent) {
 162         return getMemberTree(enumConstantsTree, isLastContent);
 163     }
 164 
 165     /**
 166      * {@inheritDoc}
 167      */

 168     public void close() throws IOException {
 169         writer.close();
 170     }
 171 
 172     public int getMemberKind() {
 173         return VisibleMemberMap.ENUM_CONSTANTS;
 174     }
 175 
 176     /**
 177      * {@inheritDoc}
 178      */

 179     public void addSummaryLabel(Content memberTree) {
 180         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
 181                 writer.getResource("doclet.Enum_Constant_Summary"));
 182         memberTree.addContent(label);
 183     }
 184 
 185     /**
 186      * {@inheritDoc}
 187      */

 188     public String getTableSummary() {
 189         return configuration.getText("doclet.Member_Table_Summary",
 190                 configuration.getText("doclet.Enum_Constant_Summary"),
 191                 configuration.getText("doclet.enum_constants"));
 192     }
 193 
 194     /**
 195      * {@inheritDoc}
 196      */

 197     public Content getCaption() {
 198         return configuration.getResource("doclet.Enum_Constants");
 199     }
 200 
 201     /**
 202      * {@inheritDoc}
 203      */
 204     public String[] getSummaryTableHeader(ProgramElementDoc member) {
 205         String[] header = new String[] {
 206             configuration.getText("doclet.0_and_1",
 207                     configuration.getText("doclet.Enum_Constant"),
 208                     configuration.getText("doclet.Description"))
 209         };
 210         return header;
 211     }
 212 
 213     /**
 214      * {@inheritDoc}
 215      */
 216     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {

 217         memberTree.addContent(writer.getMarkerAnchor(
 218                 SectionName.ENUM_CONSTANT_SUMMARY));
 219     }
 220 
 221     /**
 222      * {@inheritDoc}
 223      */
 224     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {

 225     }
 226 
 227     /**
 228      * {@inheritDoc}
 229      */
 230     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {

 231     }
 232 
 233     /**
 234      * {@inheritDoc}
 235      */
 236     protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,

 237             Content tdSummary) {
 238         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 239                 writer.getDocLink(context, (MemberDoc) member, member.name(), false));
 240         Content code = HtmlTree.CODE(memberLink);
 241         tdSummary.addContent(code);
 242     }
 243 
 244     /**
 245      * {@inheritDoc}
 246      */
 247     @Override
 248     public void setSummaryColumnStyle(HtmlTree tdTree) {
 249         tdTree.addStyle(HtmlStyle.colOne);
 250     }
 251 
 252     /**
 253      * {@inheritDoc}
 254      */
 255     protected void addInheritedSummaryLink(ClassDoc cd,
 256             ProgramElementDoc member, Content linksTree) {
 257     }
 258 
 259     /**
 260      * {@inheritDoc}
 261      */
 262     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {

 263         //Not applicable.
 264     }
 265 
 266     /**
 267      * {@inheritDoc}
 268      */
 269     protected Content getDeprecatedLink(ProgramElementDoc member) {
 270         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
 271                 (MemberDoc) member, ((FieldDoc)member).qualifiedName());

 272     }
 273 
 274     /**
 275      * {@inheritDoc}
 276      */
 277     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {

 278         if (link) {
 279             if (cd == null) {
 280                 return writer.getHyperLink(SectionName.ENUM_CONSTANT_SUMMARY,
 281                         writer.getResource("doclet.navEnum"));
 282             } else {
 283                 return writer.getHyperLink(
 284                         SectionName.ENUM_CONSTANTS_INHERITANCE,
 285                         configuration.getClassName(cd), writer.getResource("doclet.navEnum"));
 286             }
 287         } else {
 288             return writer.getResource("doclet.navEnum");
 289         }
 290     }
 291 
 292     /**
 293      * {@inheritDoc}
 294      */

 295     protected void addNavDetailLink(boolean link, Content liNav) {
 296         if (link) {
 297             liNav.addContent(writer.getHyperLink(
 298                     SectionName.ENUM_CONSTANT_DETAIL,
 299                     writer.getResource("doclet.navEnum")));
 300         } else {
 301             liNav.addContent(writer.getResource("doclet.navEnum"));
 302         }
 303     }
 304 }
   1 /*
   2  * Copyright (c) 2003, 2016, 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 import java.io.*;
  29 
  30 import java.util.Arrays;
  31 import java.util.List;


  32 
  33 import javax.lang.model.element.Element;
  34 import javax.lang.model.element.TypeElement;
  35 import javax.lang.model.element.VariableElement;
  36 
  37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
  38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
  39 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
  40 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
  41 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
  42 import jdk.javadoc.internal.doclets.toolkit.Content;
  43 import jdk.javadoc.internal.doclets.toolkit.EnumConstantWriter;
  44 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  45 
  46 /**
  47  * Writes enum constant documentation in HTML format.
  48  *
  49  *  <p><b>This is NOT part of any supported API.
  50  *  If you write code that depends on this, you do so at your own risk.
  51  *  This code and its internal interfaces are subject to change or
  52  *  deletion without notice.</b>
  53  *
  54  * @author Jamie Ho
  55  * @author Bhavesh Patel (Modified)
  56  */
  57 public class EnumConstantWriterImpl extends AbstractMemberWriter
  58     implements EnumConstantWriter, MemberSummaryWriter {
  59 
  60     public EnumConstantWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) {
  61         super(writer, typeElement);

  62     }
  63 
  64     public EnumConstantWriterImpl(SubWriterHolderWriter writer) {
  65         super(writer);
  66     }
  67 
  68     /**
  69      * {@inheritDoc}
  70      */
  71     @Override
  72     public Content getMemberSummaryHeader(TypeElement typeElement,
  73             Content memberSummaryTree) {
  74         memberSummaryTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_SUMMARY);
  75         Content memberTree = writer.getMemberTreeHeader();
  76         writer.addSummaryHeader(this, typeElement, memberTree);
  77         return memberTree;
  78     }
  79 
  80     /**
  81      * {@inheritDoc}
  82      */
  83     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  84         writer.addMemberTree(memberSummaryTree, memberTree);
  85     }
  86 
  87     /**
  88      * {@inheritDoc}
  89      */
  90     @Override
  91     public Content getEnumConstantsDetailsTreeHeader(TypeElement typeElement,
  92             Content memberDetailsTree) {
  93         memberDetailsTree.addContent(HtmlConstants.START_OF_ENUM_CONSTANT_DETAILS);
  94         Content enumConstantsDetailsTree = writer.getMemberTreeHeader();
  95         enumConstantsDetailsTree.addContent(writer.getMarkerAnchor(
  96                 SectionName.ENUM_CONSTANT_DETAIL));
  97         Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
  98                 writer.enumConstantsDetailsLabel);
  99         enumConstantsDetailsTree.addContent(heading);
 100         return enumConstantsDetailsTree;
 101     }
 102 
 103     /**
 104      * {@inheritDoc}
 105      */
 106     @Override
 107     public Content getEnumConstantsTreeHeader(VariableElement enumConstant,
 108             Content enumConstantsDetailsTree) {
 109         enumConstantsDetailsTree.addContent(
 110                 writer.getMarkerAnchor(name(enumConstant)));
 111         Content enumConstantsTree = writer.getMemberTreeHeader();
 112         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
 113         heading.addContent(name(enumConstant));
 114         enumConstantsTree.addContent(heading);
 115         return enumConstantsTree;
 116     }
 117 
 118     /**
 119      * {@inheritDoc}
 120      */
 121     @Override
 122     public Content getSignature(VariableElement enumConstant) {
 123         Content pre = new HtmlTree(HtmlTag.PRE);
 124         writer.addAnnotationInfo(enumConstant, pre);
 125         addModifiers(enumConstant, pre);
 126         Content enumConstantLink = writer.getLink(new LinkInfoImpl(
 127                 configuration, LinkInfoImpl.Kind.MEMBER, enumConstant.asType()));
 128         pre.addContent(enumConstantLink);
 129         pre.addContent(" ");
 130         if (configuration.linksource) {
 131             Content enumConstantName = new StringContent(name(enumConstant));
 132             writer.addSrcLink(enumConstant, enumConstantName, pre);
 133         } else {
 134             addName(name(enumConstant), pre);
 135         }
 136         return pre;
 137     }
 138 
 139     /**
 140      * {@inheritDoc}
 141      */
 142     @Override
 143     public void addDeprecated(VariableElement enumConstant, Content enumConstantsTree) {
 144         addDeprecatedInfo(enumConstant, enumConstantsTree);
 145     }
 146 
 147     /**
 148      * {@inheritDoc}
 149      */
 150     @Override
 151     public void addComments(VariableElement enumConstant, Content enumConstantsTree) {
 152         addComment(enumConstant, enumConstantsTree);
 153     }
 154 
 155     /**
 156      * {@inheritDoc}
 157      */
 158     @Override
 159     public void addTags(VariableElement enumConstant, Content enumConstantsTree) {
 160         writer.addTagsInfo(enumConstant, enumConstantsTree);
 161     }
 162 
 163     /**
 164      * {@inheritDoc}
 165      */
 166     @Override
 167     public Content getEnumConstantsDetails(Content enumConstantsDetailsTree) {
 168         if (configuration.allowTag(HtmlTag.SECTION)) {
 169             HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(enumConstantsDetailsTree));
 170             return htmlTree;
 171         }
 172         return getMemberTree(enumConstantsDetailsTree);
 173     }
 174 
 175     /**
 176      * {@inheritDoc}
 177      */
 178     @Override
 179     public Content getEnumConstants(Content enumConstantsTree,
 180             boolean isLastContent) {
 181         return getMemberTree(enumConstantsTree, isLastContent);
 182     }
 183 
 184     /**
 185      * {@inheritDoc}
 186      */
 187     @Override
 188     public void close() throws IOException {
 189         writer.close();
 190     }
 191 




 192     /**
 193      * {@inheritDoc}
 194      */
 195     @Override
 196     public void addSummaryLabel(Content memberTree) {
 197         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
 198                 writer.getResource("doclet.Enum_Constant_Summary"));
 199         memberTree.addContent(label);
 200     }
 201 
 202     /**
 203      * {@inheritDoc}
 204      */
 205     @Override
 206     public String getTableSummary() {
 207         return configuration.getText("doclet.Member_Table_Summary",
 208                 configuration.getText("doclet.Enum_Constant_Summary"),
 209                 configuration.getText("doclet.enum_constants"));
 210     }
 211 
 212     /**
 213      * {@inheritDoc}
 214      */
 215     @Override
 216     public Content getCaption() {
 217         return configuration.getResource("doclet.Enum_Constants");
 218     }
 219 
 220     /**
 221      * {@inheritDoc}
 222      */
 223     @Override
 224     public List<String> getSummaryTableHeader(Element member) {
 225         List<String> header = Arrays.asList(configuration.getText("doclet.0_and_1",
 226                 configuration.getText("doclet.Enum_Constant"),
 227                 configuration.getText("doclet.Description")));

 228         return header;
 229     }
 230 
 231     /**
 232      * {@inheritDoc}
 233      */
 234     @Override
 235     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 236         memberTree.addContent(writer.getMarkerAnchor(
 237                 SectionName.ENUM_CONSTANT_SUMMARY));
 238     }
 239 
 240     /**
 241      * {@inheritDoc}
 242      */
 243     @Override
 244     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 245     }
 246 
 247     /**
 248      * {@inheritDoc}
 249      */
 250     @Override
 251     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 252     }
 253 
 254     /**
 255      * {@inheritDoc}
 256      */
 257     @Override
 258     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 259             Content tdSummary) {
 260         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 261                 writer.getDocLink(context, member, name(member), false));
 262         Content code = HtmlTree.CODE(memberLink);
 263         tdSummary.addContent(code);
 264     }
 265 
 266     /**
 267      * {@inheritDoc}
 268      */
 269     @Override
 270     public void setSummaryColumnStyle(HtmlTree tdTree) {
 271         tdTree.addStyle(HtmlStyle.colOne);
 272     }
 273 
 274     /**
 275      * {@inheritDoc}
 276      */
 277     @Override
 278     protected void addInheritedSummaryLink(TypeElement typeElement, Element member, Content linksTree) {
 279     }
 280 
 281     /**
 282      * {@inheritDoc}
 283      */
 284     @Override
 285     protected void addSummaryType(Element member, Content tdSummaryType) {
 286         //Not applicable.
 287     }
 288 
 289     /**
 290      * {@inheritDoc}
 291      */
 292     @Override
 293     protected Content getDeprecatedLink(Element member) {
 294         String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
 295         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
 296     }
 297 
 298     /**
 299      * {@inheritDoc}
 300      */
 301     @Override
 302     protected Content getNavSummaryLink(TypeElement typeElement, boolean link) {
 303         if (link) {
 304             if (typeElement == null) {
 305                 return writer.getHyperLink(SectionName.ENUM_CONSTANT_SUMMARY,
 306                         writer.getResource("doclet.navEnum"));
 307             } else {
 308                 return writer.getHyperLink(
 309                         SectionName.ENUM_CONSTANTS_INHERITANCE,
 310                         configuration.getClassName(typeElement), writer.getResource("doclet.navEnum"));
 311             }
 312         } else {
 313             return writer.getResource("doclet.navEnum");
 314         }
 315     }
 316 
 317     /**
 318      * {@inheritDoc}
 319      */
 320     @Override
 321     protected void addNavDetailLink(boolean link, Content liNav) {
 322         if (link) {
 323             liNav.addContent(writer.getHyperLink(
 324                     SectionName.ENUM_CONSTANT_DETAIL,
 325                     writer.getResource("doclet.navEnum")));
 326         } else {
 327             liNav.addContent(writer.getResource("doclet.navEnum"));
 328         }
 329     }
 330 }