001/* 002 * Copyright (c) 1997, 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 java.util.Arrays; 029import java.util.List; 030 031import javax.lang.model.element.Element; 032import javax.lang.model.element.TypeElement; 033import javax.lang.model.element.VariableElement; 034 035import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.ContentBuilder; 036import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Entity; 037import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle; 038import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlTree; 039import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Text; 040import org.jdrupes.mdoclet.internal.doclets.toolkit.Content; 041import org.jdrupes.mdoclet.internal.doclets.toolkit.FieldWriter; 042import org.jdrupes.mdoclet.internal.doclets.toolkit.MemberSummaryWriter; 043 044/** 045 * Writes field documentation in HTML format. 046 */ 047public class FieldWriterImpl extends AbstractMemberWriter 048 implements FieldWriter, MemberSummaryWriter { 049 050 public FieldWriterImpl(SubWriterHolderWriter writer, 051 TypeElement typeElement) { 052 super(writer, typeElement); 053 } 054 055 public FieldWriterImpl(SubWriterHolderWriter writer) { 056 super(writer); 057 } 058 059 @Override 060 public Content getMemberSummaryHeader(TypeElement typeElement, 061 Content content) { 062 content.add(MarkerComments.START_OF_FIELD_SUMMARY); 063 Content memberContent = new ContentBuilder(); 064 writer.addSummaryHeader(this, memberContent); 065 return memberContent; 066 } 067 068 @Override 069 public void addSummary(Content summariesList, Content content) { 070 writer.addSummary(HtmlStyle.fieldSummary, 071 HtmlIds.FIELD_SUMMARY, summariesList, content); 072 } 073 074 @Override 075 public Content getFieldDetailsHeader(Content content) { 076 content.add(MarkerComments.START_OF_FIELD_DETAILS); 077 Content fieldDetailsContent = new ContentBuilder(); 078 var heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING, 079 contents.fieldDetailsLabel); 080 fieldDetailsContent.add(heading); 081 return fieldDetailsContent; 082 } 083 084 @Override 085 public Content getFieldHeaderContent(VariableElement field) { 086 Content content = new ContentBuilder(); 087 var heading = HtmlTree.HEADING(Headings.TypeDeclaration.MEMBER_HEADING, 088 Text.of(name(field))); 089 content.add(heading); 090 return HtmlTree.SECTION(HtmlStyle.detail, content) 091 .setId(htmlIds.forMember(field)); 092 } 093 094 @Override 095 public Content getSignature(VariableElement field) { 096 return new Signatures.MemberSignature(field, this) 097 .setType(utils.asInstantiatedFieldType(typeElement, field)) 098 .setAnnotations(writer.getAnnotationInfo(field, true)) 099 .toContent(); 100 } 101 102 @Override 103 public void addDeprecated(VariableElement field, Content fieldContent) { 104 addDeprecatedInfo(field, fieldContent); 105 } 106 107 @Override 108 public void addPreview(VariableElement field, Content content) { 109 addPreviewInfo(field, content); 110 } 111 112 @Override 113 public void addComments(VariableElement field, Content fieldContent) { 114 if (!utils.getFullBody(field).isEmpty()) { 115 writer.addInlineComment(field, fieldContent); 116 } 117 } 118 119 @Override 120 public void addTags(VariableElement field, Content fieldContent) { 121 writer.addTagsInfo(field, fieldContent); 122 } 123 124 @Override 125 public Content getFieldDetails(Content memberDetailsHeaderContent, 126 Content memberContent) { 127 return writer.getDetailsListItem( 128 HtmlTree.SECTION(HtmlStyle.fieldDetails) 129 .setId(HtmlIds.FIELD_DETAIL) 130 .add(memberDetailsHeaderContent) 131 .add(memberContent)); 132 } 133 134 @Override 135 public void addSummaryLabel(Content content) { 136 var label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, 137 contents.fieldSummaryLabel); 138 content.add(label); 139 } 140 141 @Override 142 public TableHeader getSummaryTableHeader(Element member) { 143 return new TableHeader(contents.modifierAndTypeLabel, 144 contents.fieldLabel, 145 contents.descriptionLabel); 146 } 147 148 @Override 149 protected Table<Element> createSummaryTable() { 150 List<HtmlStyle> bodyRowStyles 151 = Arrays.asList(HtmlStyle.colFirst, HtmlStyle.colSecond, 152 HtmlStyle.colLast); 153 154 return new Table<Element>(HtmlStyle.summaryTable) 155 .setCaption(contents.fields) 156 .setHeader(getSummaryTableHeader(typeElement)) 157 .setColumnStyles(bodyRowStyles); 158 } 159 160 @Override 161 public void addInheritedSummaryLabel(TypeElement typeElement, 162 Content content) { 163 Content classLink = writer.getPreQualifiedClassLink( 164 HtmlLinkInfo.Kind.PLAIN, typeElement); 165 Content label; 166 if (options.summarizeOverriddenMethods()) { 167 label = Text.of(utils.isClass(typeElement) 168 ? resources.getText("doclet.Fields_Declared_In_Class") 169 : resources.getText("doclet.Fields_Declared_In_Interface")); 170 } else { 171 label = Text.of(utils.isClass(typeElement) 172 ? resources.getText("doclet.Fields_Inherited_From_Class") 173 : resources.getText("doclet.Fields_Inherited_From_Interface")); 174 } 175 var labelHeading = HtmlTree.HEADING( 176 Headings.TypeDeclaration.INHERITED_SUMMARY_HEADING, 177 label); 178 labelHeading.setId(htmlIds.forInheritedFields(typeElement)); 179 labelHeading.add(Entity.NO_BREAK_SPACE); 180 labelHeading.add(classLink); 181 content.add(labelHeading); 182 } 183 184 @Override 185 protected void addSummaryLink(HtmlLinkInfo.Kind context, 186 TypeElement typeElement, Element member, 187 Content content) { 188 Content memberLink 189 = writer.getDocLink(context, typeElement, member, name(member), 190 HtmlStyle.memberNameLink); 191 var code = HtmlTree.CODE(memberLink); 192 content.add(code); 193 } 194 195 @Override 196 protected void addInheritedSummaryLink(TypeElement typeElement, 197 Element member, Content target) { 198 target.add( 199 writer.getDocLink(HtmlLinkInfo.Kind.PLAIN, typeElement, member, 200 name(member))); 201 } 202 203 @Override 204 protected void addSummaryType(Element member, Content content) { 205 addModifiersAndType(member, utils.asInstantiatedFieldType(typeElement, 206 (VariableElement) member), content); 207 } 208 209 @Override 210 protected Content getSummaryLink(Element member) { 211 String name = utils.getFullyQualifiedName(member) + "." 212 + member.getSimpleName(); 213 return writer.getDocLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, member, name); 214 } 215 216 @Override 217 public Content getMemberHeader() { 218 return writer.getMemberHeader(); 219 } 220}