001/*
002 * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package org.jdrupes.mdoclet.internal.doclets.formats.html;
027
028import javax.lang.model.element.Element;
029import javax.lang.model.element.TypeElement;
030import javax.lang.model.element.VariableElement;
031
032import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.ContentBuilder;
033import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle;
034import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlTree;
035import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Text;
036import org.jdrupes.mdoclet.internal.doclets.toolkit.Content;
037import org.jdrupes.mdoclet.internal.doclets.toolkit.EnumConstantWriter;
038import org.jdrupes.mdoclet.internal.doclets.toolkit.MemberSummaryWriter;
039
040/**
041 * Writes enum constant documentation in HTML format.
042 */
043public class EnumConstantWriterImpl extends AbstractMemberWriter
044        implements EnumConstantWriter, MemberSummaryWriter {
045
046    public EnumConstantWriterImpl(SubWriterHolderWriter writer,
047            TypeElement typeElement) {
048        super(writer, typeElement);
049    }
050
051    public EnumConstantWriterImpl(SubWriterHolderWriter writer) {
052        super(writer);
053    }
054
055    @Override
056    public Content getMemberSummaryHeader(TypeElement typeElement,
057            Content content) {
058        content.add(MarkerComments.START_OF_ENUM_CONSTANT_SUMMARY);
059        Content memberContent = new ContentBuilder();
060        writer.addSummaryHeader(this, memberContent);
061        return memberContent;
062    }
063
064    @Override
065    public void addSummary(Content summariesList, Content content) {
066        writer.addSummary(HtmlStyle.constantsSummary,
067            HtmlIds.ENUM_CONSTANT_SUMMARY, summariesList, content);
068    }
069
070    @Override
071    public Content getEnumConstantsDetailsHeader(TypeElement typeElement,
072            Content memberDetails) {
073        memberDetails.add(MarkerComments.START_OF_ENUM_CONSTANT_DETAILS);
074        var enumConstantsDetailsContent = new ContentBuilder();
075        var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
076            contents.enumConstantDetailLabel);
077        enumConstantsDetailsContent.add(heading);
078        return enumConstantsDetailsContent;
079    }
080
081    @Override
082    public Content getEnumConstantsHeader(VariableElement enumConstant,
083            Content enumConstantsDetails) {
084        Content enumConstantsContent = new ContentBuilder();
085        var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING,
086            Text.of(name(enumConstant)));
087        enumConstantsContent.add(heading);
088        return HtmlTree.SECTION(HtmlStyle.detail, enumConstantsContent)
089            .setId(htmlIds.forMember(enumConstant));
090    }
091
092    @Override
093    public Content getSignature(VariableElement enumConstant) {
094        return new Signatures.MemberSignature(enumConstant, this)
095            .setType(enumConstant.asType())
096            .setAnnotations(writer.getAnnotationInfo(enumConstant, true))
097            .toContent();
098    }
099
100    @Override
101    public void addDeprecated(VariableElement enumConstant, Content content) {
102        addDeprecatedInfo(enumConstant, content);
103    }
104
105    @Override
106    public void addPreview(VariableElement enumConstant, Content content) {
107        addPreviewInfo(enumConstant, content);
108    }
109
110    @Override
111    public void addComments(VariableElement enumConstant,
112            Content enumConstants) {
113        addComment(enumConstant, enumConstants);
114    }
115
116    @Override
117    public void addTags(VariableElement enumConstant, Content content) {
118        writer.addTagsInfo(enumConstant, content);
119    }
120
121    @Override
122    public Content getEnumConstantsDetails(Content memberDetailsHeader,
123            Content content) {
124        return writer.getDetailsListItem(
125            HtmlTree.SECTION(HtmlStyle.constantDetails)
126                .setId(HtmlIds.ENUM_CONSTANT_DETAIL)
127                .add(memberDetailsHeader)
128                .add(content));
129    }
130
131    @Override
132    public void addSummaryLabel(Content content) {
133        var label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
134            contents.enumConstantSummary);
135        content.add(label);
136    }
137
138    @Override
139    public TableHeader getSummaryTableHeader(Element member) {
140        return new TableHeader(contents.enumConstantLabel,
141            contents.descriptionLabel);
142    }
143
144    @Override
145    protected Table<Element> createSummaryTable() {
146        return new Table<Element>(HtmlStyle.summaryTable)
147            .setCaption(contents.getContent("doclet.Enum_Constants"))
148            .setHeader(getSummaryTableHeader(typeElement))
149            .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast);
150    }
151
152    @Override
153    public void addInheritedSummaryLabel(TypeElement typeElement,
154            Content content) {
155    }
156
157    @Override
158    protected void addSummaryLink(HtmlLinkInfo.Kind context,
159            TypeElement typeElement, Element member,
160            Content content) {
161        Content memberLink = writer.getDocLink(context,
162            utils.getEnclosingTypeElement(member), member,
163            name(member), HtmlStyle.memberNameLink);
164        var code = HtmlTree.CODE(memberLink);
165        content.add(code);
166    }
167
168    @Override
169    protected void addInheritedSummaryLink(TypeElement typeElement,
170            Element member, Content target) {
171    }
172
173    @Override
174    protected void addSummaryType(Element member, Content content) {
175        // Not applicable.
176    }
177
178    @Override
179    protected Content getSummaryLink(Element member) {
180        String name = utils.getFullyQualifiedName(member) + "."
181            + member.getSimpleName();
182        return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name);
183    }
184
185    @Override
186    public Content getMemberHeader() {
187        return writer.getMemberHeader();
188    }
189}