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