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 34 /** 35 * Writes annotation type optional member documentation in HTML format. 36 * 37 * <p><b>This is NOT part of any supported API. 38 * If you write code that depends on this, you do so at your own risk. 39 * This code and its internal interfaces are subject to change or 40 * deletion without notice.</b> 41 * 42 * @author Jamie Ho 43 * @author Bhavesh Patel (Modified) 44 */ 45 public class AnnotationTypeOptionalMemberWriterImpl extends 46 AnnotationTypeRequiredMemberWriterImpl 47 implements AnnotationTypeOptionalMemberWriter, MemberSummaryWriter { 48 49 /** 50 * Construct a new AnnotationTypeOptionalMemberWriterImpl. 51 * 52 * @param writer the writer that will write the output. 53 * @param annotationType the AnnotationType that holds this member. 54 */ 55 public AnnotationTypeOptionalMemberWriterImpl(SubWriterHolderWriter writer, 56 AnnotationTypeDoc annotationType) { 57 super(writer, annotationType); 58 } 59 60 /** 61 * {@inheritDoc} 62 */ 63 public Content getMemberSummaryHeader(ClassDoc classDoc, 64 Content memberSummaryTree) { 65 memberSummaryTree.addContent( 66 HtmlConstants.START_OF_ANNOTATION_TYPE_OPTIONAL_MEMBER_SUMMARY); 67 Content memberTree = writer.getMemberTreeHeader(); 68 writer.addSummaryHeader(this, classDoc, memberTree); 69 return memberTree; 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 76 writer.addMemberTree(memberSummaryTree, memberTree); 77 } 78 79 /** 80 * {@inheritDoc} 81 */ 82 public void addDefaultValueInfo(MemberDoc member, Content annotationDocTree) { 83 if (((AnnotationTypeElementDoc) member).defaultValue() != null) { 84 Content dt = HtmlTree.DT(writer.getResource("doclet.Default")); 85 Content dl = HtmlTree.DL(dt); 86 Content dd = HtmlTree.DD(new StringContent( 87 ((AnnotationTypeElementDoc) member).defaultValue().toString())); 88 dl.addContent(dd); 89 annotationDocTree.addContent(dl); 90 } 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 public void close() throws IOException { 97 writer.close(); 98 } 99 100 /** 101 * {@inheritDoc} 102 */ 103 public void addSummaryLabel(Content memberTree) { 104 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 105 writer.getResource("doclet.Annotation_Type_Optional_Member_Summary")); 106 memberTree.addContent(label); 107 } 108 109 /** 110 * {@inheritDoc} 111 */ 112 public String getTableSummary() { 113 return configuration.getText("doclet.Member_Table_Summary", 114 configuration.getText("doclet.Annotation_Type_Optional_Member_Summary"), 115 configuration.getText("doclet.annotation_type_optional_members")); 116 } 117 118 /** 119 * {@inheritDoc} 120 */ 121 public Content getCaption() { 122 return configuration.getResource("doclet.Annotation_Type_Optional_Members"); 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 public String[] getSummaryTableHeader(ProgramElementDoc member) { 129 String[] header = new String[] { 130 writer.getModifierTypeHeader(), 131 configuration.getText("doclet.0_and_1", 132 configuration.getText("doclet.Annotation_Type_Optional_Member"), 133 configuration.getText("doclet.Description")) 134 }; 135 return header; 136 } 137 138 /** 139 * {@inheritDoc} 140 */ 141 public void addSummaryAnchor(ClassDoc cd, Content memberTree) { 142 memberTree.addContent(writer.getMarkerAnchor( 143 SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY)); 144 } 145 146 /** 147 * {@inheritDoc} 148 */ 149 protected Content getNavSummaryLink(ClassDoc cd, boolean link) { 150 if (link) { 151 return writer.getHyperLink( 152 SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY, 153 writer.getResource("doclet.navAnnotationTypeOptionalMember")); 154 } else { 155 return writer.getResource("doclet.navAnnotationTypeOptionalMember"); 156 } 157 } 158 } | 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.AnnotationValue; 34 import javax.lang.model.element.Element; 35 import javax.lang.model.element.ExecutableElement; 36 import javax.lang.model.element.TypeElement; 37 38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 39 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 40 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 41 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter; 42 import jdk.javadoc.internal.doclets.toolkit.Content; 43 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 44 45 46 /** 47 * Writes annotation type optional member 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 AnnotationTypeOptionalMemberWriterImpl extends 58 AnnotationTypeRequiredMemberWriterImpl 59 implements AnnotationTypeOptionalMemberWriter, MemberSummaryWriter { 60 61 /** 62 * Construct a new AnnotationTypeOptionalMemberWriterImpl. 63 * 64 * @param writer the writer that will write the output. 65 * @param annotationType the AnnotationType that holds this member. 66 */ 67 public AnnotationTypeOptionalMemberWriterImpl(SubWriterHolderWriter writer, 68 TypeElement annotationType) { 69 super(writer, annotationType); 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 public Content getMemberSummaryHeader(TypeElement typeElement, 76 Content memberSummaryTree) { 77 memberSummaryTree.addContent( 78 HtmlConstants.START_OF_ANNOTATION_TYPE_OPTIONAL_MEMBER_SUMMARY); 79 Content memberTree = writer.getMemberTreeHeader(); 80 writer.addSummaryHeader(this, typeElement, memberTree); 81 return memberTree; 82 } 83 84 /** 85 * {@inheritDoc} 86 */ 87 public void addMemberTree(Content memberSummaryTree, Content memberTree) { 88 writer.addMemberTree(memberSummaryTree, memberTree); 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 public void addDefaultValueInfo(Element member, Content annotationDocTree) { 95 if (utils.isAnnotationType(member)) { 96 ExecutableElement ee = (ExecutableElement)member; 97 AnnotationValue value = ee.getDefaultValue(); 98 if (value != null) { 99 Content dt = HtmlTree.DT(writer.getResource("doclet.Default")); 100 Content dl = HtmlTree.DL(dt); 101 Content dd = HtmlTree.DD(new StringContent(value.toString())); 102 dl.addContent(dd); 103 annotationDocTree.addContent(dl); 104 } 105 } 106 } 107 108 /** 109 * {@inheritDoc} 110 */ 111 public void close() throws IOException { 112 writer.close(); 113 } 114 115 /** 116 * {@inheritDoc} 117 */ 118 public void addSummaryLabel(Content memberTree) { 119 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, 120 writer.getResource("doclet.Annotation_Type_Optional_Member_Summary")); 121 memberTree.addContent(label); 122 } 123 124 /** 125 * {@inheritDoc} 126 */ 127 public String getTableSummary() { 128 return configuration.getText("doclet.Member_Table_Summary", 129 configuration.getText("doclet.Annotation_Type_Optional_Member_Summary"), 130 configuration.getText("doclet.annotation_type_optional_members")); 131 } 132 133 /** 134 * {@inheritDoc} 135 */ 136 public Content getCaption() { 137 return configuration.getResource("doclet.Annotation_Type_Optional_Members"); 138 } 139 140 /** 141 * {@inheritDoc} 142 */ 143 public List<String> getSummaryTableHeader(Element member) { 144 List<String> header = Arrays.asList(writer.getModifierTypeHeader(), 145 configuration.getText("doclet.0_and_1", 146 configuration.getText("doclet.Annotation_Type_Optional_Member"), 147 configuration.getText("doclet.Description"))); 148 return header; 149 } 150 151 /** 152 * {@inheritDoc} 153 */ 154 public void addSummaryAnchor(TypeElement typeElement, Content memberTree) { 155 memberTree.addContent(writer.getMarkerAnchor( 156 SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY)); 157 } 158 159 /** 160 * {@inheritDoc} 161 */ 162 protected Content getNavSummaryLink(TypeElement typeElement, boolean link) { 163 if (link) { 164 return writer.getHyperLink( 165 SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY, 166 writer.getResource("doclet.navAnnotationTypeOptionalMember")); 167 } else { 168 return writer.getResource("doclet.navAnnotationTypeOptionalMember"); 169 } 170 } 171 } |