PropertyBuilder.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.ExecutableElement; 32import javax.lang.model.element.TypeElement; 33 34import jdk.javadoc.internal.doclets.toolkit.Configuration; 35import jdk.javadoc.internal.doclets.toolkit.Content; 36import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; 37import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; 38 39 40/** 41 * Builds documentation for a property. 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 PropertyBuilder extends AbstractMemberBuilder { 52 53 /** 54 * The class whose properties are being documented. 55 */ 56 private final TypeElement typeElement; 57 58 /** 59 * The visible properties for the given class. 60 */ 61 private final VisibleMemberMap visibleMemberMap; 62 63 /** 64 * The writer to output the property documentation. 65 */ 66 private final PropertyWriter writer; 67 68 /** 69 * The list of properties being documented. 70 */ 71 private final SortedSet<Element> properties; 72 73 /** 74 * The index of the current property that is being documented at this point 75 * in time. 76 */ 77 private ExecutableElement currentProperty; 78 79 /** 80 * Construct a new PropertyBuilder. 81 * 82 * @param context the build context. 83 * @param typeElement the class whoses members are being documented. 84 * @param writer the doclet specific writer. 85 */ 86 private PropertyBuilder(Context context, 87 TypeElement typeElement, 88 PropertyWriter writer) { 89 super(context); 90 this.typeElement = typeElement; 91 this.writer = writer; 92 visibleMemberMap = 93 new VisibleMemberMap( 94 typeElement, 95 VisibleMemberMap.Kind.PROPERTIES, 96 configuration); 97 properties = visibleMemberMap.getMembersFor(typeElement); 98 } 99 100 /** 101 * Construct a new PropertyBuilder. 102 * 103 * @param context the build context. 104 * @param typeElement the class whoses members are being documented. 105 * @param writer the doclet specific writer. 106 */ 107 public static PropertyBuilder getInstance(Context context, 108 TypeElement typeElement, 109 PropertyWriter writer) { 110 return new PropertyBuilder(context, typeElement, writer); 111 } 112 113 /** 114 * {@inheritDoc} 115 */ 116 @Override 117 public String getName() { 118 return "PropertyDetails"; 119 } 120 121 /** 122 * Returns a list of properties that will be documented for the given class. 123 * This information can be used for doclet specific documentation 124 * generation. 125 * 126 * @param typeElement the {@link TypeElement} we want to check. 127 * @return a list of properties that will be documented. 128 */ 129 public SortedSet<Element> members(TypeElement typeElement) { 130 return visibleMemberMap.getMembersFor(typeElement); 131 } 132 133 /** 134 * Returns the visible member map for the properties of this class. 135 * 136 * @return the visible member map for the properties of this class. 137 */ 138 public VisibleMemberMap getVisibleMemberMap() { 139 return visibleMemberMap; 140 } 141 142 /** 143 * summaryOrder.size() 144 */ 145 @Override 146 public boolean hasMembersToDocument() { 147 return !properties.isEmpty(); 148 } 149 150 /** 151 * Build the property documentation. 152 * 153 * @param node the XML element that specifies which components to document 154 * @param memberDetailsTree the content tree to which the documentation will be added 155 */ 156 public void buildPropertyDoc(XMLNode node, Content memberDetailsTree) { 157 if (writer == null) { 158 return; 159 } 160 int size = properties.size(); 161 if (size > 0) { 162 Content propertyDetailsTree = writer.getPropertyDetailsTreeHeader(typeElement, 163 memberDetailsTree); 164 for (Element e : properties) { 165 currentProperty = (ExecutableElement) e; 166 Content propertyDocTree = writer.getPropertyDocTreeHeader(currentProperty, 167 propertyDetailsTree); 168 buildChildren(node, propertyDocTree); 169 propertyDetailsTree.addContent(writer.getPropertyDoc( 170 propertyDocTree, currentProperty == properties.last())); 171 } 172 memberDetailsTree.addContent( 173 writer.getPropertyDetails(propertyDetailsTree)); 174 } 175 } 176 177 /** 178 * Build the signature. 179 * 180 * @param node the XML element that specifies which components to document 181 * @param propertyDocTree the content tree to which the documentation will be added 182 */ 183 public void buildSignature(XMLNode node, Content propertyDocTree) { 184 propertyDocTree.addContent(writer.getSignature(currentProperty)); 185 } 186 187 /** 188 * Build the deprecation information. 189 * 190 * @param node the XML element that specifies which components to document 191 * @param propertyDocTree the content tree to which the documentation will be added 192 */ 193 public void buildDeprecationInfo(XMLNode node, Content propertyDocTree) { 194 writer.addDeprecated(currentProperty, propertyDocTree); 195 } 196 197 /** 198 * Build the comments for the property. Do nothing if 199 * {@link Configuration#nocomment} is set to true. 200 * 201 * @param node the XML element that specifies which components to document 202 * @param propertyDocTree the content tree to which the documentation will be added 203 */ 204 public void buildPropertyComments(XMLNode node, Content propertyDocTree) { 205 if (!configuration.nocomment) { 206 writer.addComments(currentProperty, propertyDocTree); 207 } 208 } 209 210 /** 211 * Build the tag information. 212 * 213 * @param node the XML element that specifies which components to document 214 * @param propertyDocTree the content tree to which the documentation will be added 215 */ 216 public void buildTagInfo(XMLNode node, Content propertyDocTree) { 217 writer.addTags(currentProperty, propertyDocTree); 218 } 219 220 /** 221 * Return the property writer for this builder. 222 * 223 * @return the property writer for this builder. 224 */ 225 public PropertyWriter getWriter() { 226 return writer; 227 } 228} 229