AnnotationTypeRequiredMemberBuilder.java revision 3233:b5d08bc0d224
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 26package jdk.javadoc.internal.doclets.toolkit.builders; 27 28import java.util.*; 29 30import javax.lang.model.element.Element; 31import javax.lang.model.element.TypeElement; 32 33import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter; 34import jdk.javadoc.internal.doclets.toolkit.Configuration; 35import jdk.javadoc.internal.doclets.toolkit.Content; 36import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; 37 38 39/** 40 * Builds documentation for required annotation type members. 41 * 42 * <p><b>This is NOT part of any supported API. 43 * If you write code that depends on this, you do so at your own risk. 44 * This code and its internal interfaces are subject to change or 45 * deletion without notice.</b> 46 * 47 * @author Jamie Ho 48 * @author Bhavesh Patel (Modified) 49 */ 50public class AnnotationTypeRequiredMemberBuilder extends AbstractMemberBuilder { 51 52 /** 53 * The annotation type whose members are being documented. 54 */ 55 protected TypeElement typeElement; 56 57 /** 58 * The visible members for the given class. 59 */ 60 protected VisibleMemberMap visibleMemberMap; 61 62 /** 63 * The writer to output the member documentation. 64 */ 65 protected AnnotationTypeRequiredMemberWriter writer; 66 67 /** 68 * The list of members being documented. 69 */ 70 protected SortedSet<Element> members; 71 72 /** 73 * The index of the current member that is being documented at this point 74 * in time. 75 */ 76 protected Element currentMember; 77 78 /** 79 * Construct a new AnnotationTypeRequiredMemberBuilder. 80 * 81 * @param context the build context. 82 * @param typeElement the class whose members are being documented. 83 * @param writer the doclet specific writer. 84 */ 85 protected AnnotationTypeRequiredMemberBuilder(Context context, 86 TypeElement typeElement, 87 AnnotationTypeRequiredMemberWriter writer, 88 VisibleMemberMap.Kind memberType) { 89 super(context); 90 this.typeElement = typeElement; 91 this.writer = writer; 92 this.visibleMemberMap = new VisibleMemberMap(typeElement, memberType, configuration); 93 this.members = this.visibleMemberMap.getMembersFor(typeElement); 94 } 95 96 97 /** 98 * Construct a new AnnotationTypeMemberBuilder. 99 * 100 * @param context the build context. 101 * @param typeElement the class whose members are being documented. 102 * @param writer the doclet specific writer. 103 */ 104 public static AnnotationTypeRequiredMemberBuilder getInstance( 105 Context context, TypeElement typeElement, 106 AnnotationTypeRequiredMemberWriter writer) { 107 return new AnnotationTypeRequiredMemberBuilder(context, typeElement, 108 writer, 109 VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_REQUIRED); 110 } 111 112 /** 113 * {@inheritDoc} 114 */ 115 @Override 116 public String getName() { 117 return "AnnotationTypeRequiredMemberDetails"; 118 } 119 120 /** 121 * Returns a list of members that will be documented for the given class. 122 * This information can be used for doclet specific documentation 123 * generation. 124 * 125 * @param typeElement the {@link TypeElement} we want to check. 126 * @return a list of members that will be documented. 127 */ 128 public SortedSet<Element> members(TypeElement typeElement) { 129 return visibleMemberMap.getMembersFor(typeElement); 130 } 131 132 /** 133 * Returns the visible member map for the members of this class. 134 * 135 * @return the visible member map for the members of this class. 136 */ 137 public VisibleMemberMap getVisibleMemberMap() { 138 return visibleMemberMap; 139 } 140 141 /** 142 * summaryOrder.size() 143 */ 144 @Override 145 public boolean hasMembersToDocument() { 146 return members.size() > 0; 147 } 148 149 /** 150 * Build the annotation type required member documentation. 151 * 152 * @param node the XML element that specifies which components to document 153 * @param memberDetailsTree the content tree to which the documentation will be added 154 */ 155 public void buildAnnotationTypeRequiredMember(XMLNode node, Content memberDetailsTree) { 156 buildAnnotationTypeMember(node, memberDetailsTree); 157 } 158 159 /** 160 * Build the member documentation. 161 * 162 * @param node the XML element that specifies which components to document 163 * @param memberDetailsTree the content tree to which the documentation will be added 164 */ 165 public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) { 166 if (writer == null) { 167 return; 168 } 169 int size = members.size(); 170 if (size > 0) { 171 writer.addAnnotationDetailsMarker(memberDetailsTree); 172 for (Element element : members) { 173 currentMember = element; 174 Content detailsTree = writer.getMemberTreeHeader(); 175 writer.addAnnotationDetailsTreeHeader(typeElement, detailsTree); 176 Content annotationDocTree = writer.getAnnotationDocTreeHeader( 177 element, detailsTree); 178 buildChildren(node, annotationDocTree); 179 detailsTree.addContent(writer.getAnnotationDoc( 180 annotationDocTree, currentMember == members.last())); 181 memberDetailsTree.addContent(writer.getAnnotationDetails(detailsTree)); 182 } 183 } 184 } 185 186 /** 187 * Build the signature. 188 * 189 * @param node the XML element that specifies which components to document 190 * @param annotationDocTree the content tree to which the documentation will be added 191 */ 192 public void buildSignature(XMLNode node, Content annotationDocTree) { 193 annotationDocTree.addContent(writer.getSignature(currentMember)); 194 } 195 196 /** 197 * Build the deprecation information. 198 * 199 * @param node the XML element that specifies which components to document 200 * @param annotationDocTree the content tree to which the documentation will be added 201 */ 202 public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) { 203 writer.addDeprecated(currentMember, annotationDocTree); 204 } 205 206 /** 207 * Build the comments for the member. Do nothing if 208 * {@link Configuration#nocomment} is set to true. 209 * 210 * @param node the XML element that specifies which components to document 211 * @param annotationDocTree the content tree to which the documentation will be added 212 */ 213 public void buildMemberComments(XMLNode node, Content annotationDocTree) { 214 if(! configuration.nocomment) { 215 writer.addComments(currentMember, annotationDocTree); 216 } 217 } 218 219 /** 220 * Build the tag information. 221 * 222 * @param node the XML element that specifies which components to document 223 * @param annotationDocTree the content tree to which the documentation will be added 224 */ 225 public void buildTagInfo(XMLNode node, Content annotationDocTree) { 226 writer.addTags(currentMember, annotationDocTree); 227 } 228 229 /** 230 * Return the annotation type required member writer for this builder. 231 * 232 * @return the annotation type required member constant writer for this 233 * builder. 234 */ 235 public AnnotationTypeRequiredMemberWriter getWriter() { 236 return writer; 237 } 238} 239