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; 033 034import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.ContentBuilder; 035import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Entity; 036import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle; 037import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlTree; 038import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Text; 039import org.jdrupes.mdoclet.internal.doclets.toolkit.Content; 040import org.jdrupes.mdoclet.internal.doclets.toolkit.MemberSummaryWriter; 041 042/** 043 * Writes nested class documentation in HTML format. 044 */ 045public class NestedClassWriterImpl extends AbstractMemberWriter 046 implements MemberSummaryWriter { 047 048 public NestedClassWriterImpl(SubWriterHolderWriter writer, 049 TypeElement typeElement) { 050 super(writer, typeElement); 051 } 052 053 public NestedClassWriterImpl(SubWriterHolderWriter writer) { 054 super(writer); 055 } 056 057 @Override 058 public Content getMemberSummaryHeader(TypeElement typeElement, 059 Content content) { 060 content.add(MarkerComments.START_OF_NESTED_CLASS_SUMMARY); 061 Content memberContent = new ContentBuilder(); 062 writer.addSummaryHeader(this, memberContent); 063 return memberContent; 064 } 065 066 @Override 067 public void addSummary(Content summariesList, Content content) { 068 writer.addSummary(HtmlStyle.nestedClassSummary, 069 HtmlIds.NESTED_CLASS_SUMMARY, summariesList, content); 070 } 071 072 @Override 073 public void addSummaryLabel(Content content) { 074 var label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, 075 contents.nestedClassSummary); 076 content.add(label); 077 } 078 079 @Override 080 public TableHeader getSummaryTableHeader(Element member) { 081 Content label = utils.isPlainInterface(member) ? contents.interfaceLabel 082 : contents.classLabel; 083 084 return new TableHeader(contents.modifierAndTypeLabel, label, 085 contents.descriptionLabel); 086 } 087 088 @Override 089 protected Table<Element> createSummaryTable() { 090 List<HtmlStyle> bodyRowStyles 091 = Arrays.asList(HtmlStyle.colFirst, HtmlStyle.colSecond, 092 HtmlStyle.colLast); 093 094 return new Table<Element>(HtmlStyle.summaryTable) 095 .setCaption(contents.getContent("doclet.Nested_Classes")) 096 .setHeader(getSummaryTableHeader(typeElement)) 097 .setColumnStyles(bodyRowStyles); 098 } 099 100 @Override 101 public void addInheritedSummaryLabel(TypeElement typeElement, 102 Content content) { 103 Content classLink = writer 104 .getPreQualifiedClassLink(HtmlLinkInfo.Kind.PLAIN, typeElement); 105 Content label; 106 if (options.summarizeOverriddenMethods()) { 107 label = Text.of(utils.isPlainInterface(typeElement) 108 ? resources.getText( 109 "doclet.Nested_Classes_Interfaces_Declared_In_Interface") 110 : resources.getText( 111 "doclet.Nested_Classes_Interfaces_Declared_In_Class")); 112 } else { 113 label = Text.of(utils.isPlainInterface(typeElement) 114 ? resources.getText( 115 "doclet.Nested_Classes_Interfaces_Inherited_From_Interface") 116 : resources.getText( 117 "doclet.Nested_Classes_Interfaces_Inherited_From_Class")); 118 } 119 var labelHeading 120 = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING, label); 121 labelHeading.setId(htmlIds.forInheritedClasses(typeElement)); 122 labelHeading.add(Entity.NO_BREAK_SPACE); 123 labelHeading.add(classLink); 124 content.add(labelHeading); 125 } 126 127 @Override 128 protected void addSummaryLink(HtmlLinkInfo.Kind context, 129 TypeElement typeElement, Element member, 130 Content content) { 131 Content memberLink = writer.getLink( 132 new HtmlLinkInfo(configuration, context, (TypeElement) member) 133 .style(HtmlStyle.typeNameLink)); 134 var code = HtmlTree.CODE(memberLink); 135 content.add(code); 136 } 137 138 @Override 139 protected void addInheritedSummaryLink(TypeElement typeElement, 140 Element member, Content target) { 141 target.add( 142 writer.getLink(new HtmlLinkInfo(configuration, 143 HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, 144 (TypeElement) member))); 145 } 146 147 @Override 148 protected void addSummaryType(Element member, Content content) { 149 addModifiersAndType(member, null, content); 150 } 151 152 @Override 153 protected void addSummaryLink(TypeElement typeElement, Element member, 154 Content content) { 155 addSummaryLink(HtmlLinkInfo.Kind.LINK_TYPE_PARAMS_AND_BOUNDS, 156 typeElement, member, content); 157 } 158 159 @Override 160 protected Content getSummaryLink(Element member) { 161 return writer.getQualifiedClassLink(HtmlLinkInfo.Kind.SHOW_PREVIEW, 162 member); 163 } 164}