Wed, 01 Dec 2010 11:02:38 -0800
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.internal.toolkit.builders; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.*; |
duke@1 | 29 | import java.util.*; |
bpatel@233 | 30 | import com.sun.javadoc.*; |
bpatel@233 | 31 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@233 | 32 | import com.sun.tools.doclets.internal.toolkit.*; |
bpatel@233 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Builds the serialized form. |
duke@1 | 36 | * |
duke@1 | 37 | * This code is not part of an API. |
duke@1 | 38 | * It is implementation that is subject to change. |
duke@1 | 39 | * Do not use it as an API |
duke@1 | 40 | * |
duke@1 | 41 | * @author Jamie Ho |
bpatel@233 | 42 | * @author Bhavesh Patel (Modified) |
duke@1 | 43 | * @since 1.5 |
duke@1 | 44 | */ |
duke@1 | 45 | public class SerializedFormBuilder extends AbstractBuilder { |
duke@1 | 46 | |
duke@1 | 47 | /** |
duke@1 | 48 | * The root element of the serialized form XML is {@value}. |
duke@1 | 49 | */ |
duke@1 | 50 | public static final String NAME = "SerializedForm"; |
duke@1 | 51 | |
duke@1 | 52 | /** |
duke@1 | 53 | * The writer for this builder. |
duke@1 | 54 | */ |
duke@1 | 55 | private SerializedFormWriter writer; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * The writer for serializable fields. |
duke@1 | 59 | */ |
duke@1 | 60 | private SerializedFormWriter.SerialFieldWriter fieldWriter; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * The writer for serializable method documentation. |
duke@1 | 64 | */ |
duke@1 | 65 | private SerializedFormWriter.SerialMethodWriter methodWriter; |
duke@1 | 66 | |
duke@1 | 67 | /** |
duke@1 | 68 | * The header for the serial version UID. Save the string |
duke@1 | 69 | * here instead of the properties file because we do not want |
duke@1 | 70 | * this string to be localized. |
duke@1 | 71 | */ |
duke@1 | 72 | private static final String SERIAL_VERSION_UID_HEADER = "serialVersionUID:"; |
duke@1 | 73 | |
duke@1 | 74 | /** |
duke@1 | 75 | * The current package being documented. |
duke@1 | 76 | */ |
duke@1 | 77 | private PackageDoc currentPackage; |
duke@1 | 78 | |
duke@1 | 79 | /** |
duke@1 | 80 | * The current class being documented. |
duke@1 | 81 | */ |
duke@1 | 82 | private ClassDoc currentClass; |
duke@1 | 83 | |
duke@1 | 84 | /** |
duke@1 | 85 | * The current member being documented. |
duke@1 | 86 | */ |
duke@1 | 87 | protected MemberDoc currentMember; |
duke@1 | 88 | |
bpatel@766 | 89 | /** |
bpatel@766 | 90 | * The content that will be added to the serialized form documentation tree. |
bpatel@766 | 91 | */ |
bpatel@766 | 92 | private Content contentTree; |
bpatel@766 | 93 | |
duke@1 | 94 | private SerializedFormBuilder(Configuration configuration) { |
duke@1 | 95 | super(configuration); |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * Construct a new SerializedFormBuilder. |
duke@1 | 100 | * @param configuration the current configuration of the doclet. |
duke@1 | 101 | */ |
duke@1 | 102 | public static SerializedFormBuilder getInstance(Configuration configuration) { |
duke@1 | 103 | SerializedFormBuilder builder = new SerializedFormBuilder(configuration); |
duke@1 | 104 | return builder; |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Build the serialized form. |
duke@1 | 109 | */ |
duke@1 | 110 | public void build() throws IOException { |
duke@1 | 111 | if (! serialClassFoundToDocument(configuration.root.classes())) { |
duke@1 | 112 | //Nothing to document. |
duke@1 | 113 | return; |
duke@1 | 114 | } |
duke@1 | 115 | try { |
duke@1 | 116 | writer = configuration.getWriterFactory().getSerializedFormWriter(); |
duke@1 | 117 | if (writer == null) { |
duke@1 | 118 | //Doclet does not support this output. |
duke@1 | 119 | return; |
duke@1 | 120 | } |
duke@1 | 121 | } catch (Exception e) { |
duke@1 | 122 | throw new DocletAbortException(); |
duke@1 | 123 | } |
bpatel@766 | 124 | build(LayoutParser.getInstance(configuration).parseXML(NAME), contentTree); |
duke@1 | 125 | writer.close(); |
duke@1 | 126 | } |
duke@1 | 127 | |
duke@1 | 128 | /** |
duke@1 | 129 | * {@inheritDoc} |
duke@1 | 130 | */ |
duke@1 | 131 | public String getName() { |
duke@1 | 132 | return NAME; |
duke@1 | 133 | } |
duke@1 | 134 | |
duke@1 | 135 | /** |
duke@1 | 136 | * Build the serialized form. |
bpatel@766 | 137 | * |
bpatel@766 | 138 | * @param node the XML element that specifies which components to document |
bpatel@766 | 139 | * @param serializedTree content tree to which the documentation will be added |
duke@1 | 140 | */ |
bpatel@766 | 141 | public void buildSerializedForm(XMLNode node, Content serializedTree) throws Exception { |
bpatel@766 | 142 | serializedTree = writer.getHeader(configuration.getText( |
bpatel@766 | 143 | "doclet.Serialized_Form")); |
bpatel@766 | 144 | buildChildren(node, serializedTree); |
bpatel@766 | 145 | writer.addFooter(serializedTree); |
bpatel@766 | 146 | writer.printDocument(serializedTree); |
duke@1 | 147 | writer.close(); |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** |
bpatel@766 | 151 | * Build the serialized form summaries. |
bpatel@766 | 152 | * |
bpatel@766 | 153 | * @param node the XML element that specifies which components to document |
bpatel@766 | 154 | * @param serializedTree content tree to which the documentation will be added |
duke@1 | 155 | */ |
bpatel@766 | 156 | public void buildSerializedFormSummaries(XMLNode node, Content serializedTree) { |
bpatel@766 | 157 | Content serializedSummariesTree = writer.getSerializedSummariesHeader(); |
bpatel@766 | 158 | PackageDoc[] packages = configuration.packages; |
bpatel@766 | 159 | for (int i = 0; i < packages.length; i++) { |
bpatel@766 | 160 | currentPackage = packages[i]; |
bpatel@766 | 161 | buildChildren(node, serializedSummariesTree); |
bpatel@766 | 162 | } |
bpatel@766 | 163 | serializedTree.addContent(writer.getSerializedContent( |
bpatel@766 | 164 | serializedSummariesTree)); |
duke@1 | 165 | } |
duke@1 | 166 | |
duke@1 | 167 | /** |
bpatel@766 | 168 | * Build the package serialized form for the current package being processed. |
bpatel@766 | 169 | * |
bpatel@766 | 170 | * @param node the XML element that specifies which components to document |
bpatel@766 | 171 | * @param serializedSummariesTree content tree to which the documentation will be added |
duke@1 | 172 | */ |
bpatel@766 | 173 | public void buildPackageSerializedForm(XMLNode node, Content serializedSummariesTree) { |
bpatel@766 | 174 | Content packageSerializedTree = writer.getPackageSerializedHeader(); |
duke@1 | 175 | String foo = currentPackage.name(); |
duke@1 | 176 | ClassDoc[] classes = currentPackage.allClasses(false); |
duke@1 | 177 | if (classes == null || classes.length == 0) { |
duke@1 | 178 | return; |
duke@1 | 179 | } |
duke@1 | 180 | if (!serialInclude(currentPackage)) { |
duke@1 | 181 | return; |
duke@1 | 182 | } |
duke@1 | 183 | if (!serialClassFoundToDocument(classes)) { |
duke@1 | 184 | return; |
duke@1 | 185 | } |
bpatel@766 | 186 | buildChildren(node, packageSerializedTree); |
bpatel@766 | 187 | serializedSummariesTree.addContent(packageSerializedTree); |
duke@1 | 188 | } |
duke@1 | 189 | |
bpatel@766 | 190 | /** |
bpatel@766 | 191 | * Build the package header. |
bpatel@766 | 192 | * |
bpatel@766 | 193 | * @param node the XML element that specifies which components to document |
bpatel@766 | 194 | * @param packageSerializedTree content tree to which the documentation will be added |
bpatel@766 | 195 | */ |
bpatel@766 | 196 | public void buildPackageHeader(XMLNode node, Content packageSerializedTree) { |
bpatel@766 | 197 | packageSerializedTree.addContent(writer.getPackageHeader( |
bpatel@766 | 198 | Util.getPackageName(currentPackage))); |
duke@1 | 199 | } |
duke@1 | 200 | |
bpatel@766 | 201 | /** |
bpatel@766 | 202 | * Build the class serialized form. |
bpatel@766 | 203 | * |
bpatel@766 | 204 | * @param node the XML element that specifies which components to document |
bpatel@766 | 205 | * @param packageSerializedTree content tree to which the documentation will be added |
bpatel@766 | 206 | */ |
bpatel@766 | 207 | public void buildClassSerializedForm(XMLNode node, Content packageSerializedTree) { |
bpatel@766 | 208 | Content classSerializedTree = writer.getClassSerializedHeader(); |
duke@1 | 209 | ClassDoc[] classes = currentPackage.allClasses(false); |
duke@1 | 210 | Arrays.sort(classes); |
duke@1 | 211 | for (int j = 0; j < classes.length; j++) { |
duke@1 | 212 | currentClass = classes[j]; |
duke@1 | 213 | fieldWriter = writer.getSerialFieldWriter(currentClass); |
duke@1 | 214 | methodWriter = writer.getSerialMethodWriter(currentClass); |
duke@1 | 215 | if(currentClass.isClass() && currentClass.isSerializable()) { |
duke@1 | 216 | if(!serialClassInclude(currentClass)) { |
duke@1 | 217 | continue; |
duke@1 | 218 | } |
bpatel@766 | 219 | Content classTree = writer.getClassHeader(currentClass); |
bpatel@766 | 220 | buildChildren(node, classTree); |
bpatel@766 | 221 | classSerializedTree.addContent(classTree); |
duke@1 | 222 | } |
duke@1 | 223 | } |
bpatel@766 | 224 | packageSerializedTree.addContent(classSerializedTree); |
duke@1 | 225 | } |
duke@1 | 226 | |
duke@1 | 227 | /** |
duke@1 | 228 | * Build the serial UID information for the given class. |
bpatel@766 | 229 | * |
bpatel@766 | 230 | * @param node the XML element that specifies which components to document |
bpatel@766 | 231 | * @param classTree content tree to which the serial UID information will be added |
duke@1 | 232 | */ |
bpatel@766 | 233 | public void buildSerialUIDInfo(XMLNode node, Content classTree) { |
bpatel@766 | 234 | Content serialUidTree = writer.getSerialUIDInfoHeader(); |
duke@1 | 235 | FieldDoc[] fields = currentClass.fields(false); |
duke@1 | 236 | for (int i = 0; i < fields.length; i++) { |
duke@1 | 237 | if (fields[i].name().equals("serialVersionUID") && |
duke@1 | 238 | fields[i].constantValueExpression() != null) { |
bpatel@766 | 239 | writer.addSerialUIDInfo(SERIAL_VERSION_UID_HEADER, |
bpatel@766 | 240 | fields[i].constantValueExpression(), serialUidTree); |
bpatel@766 | 241 | break; |
bpatel@766 | 242 | } |
bpatel@766 | 243 | } |
bpatel@766 | 244 | classTree.addContent(serialUidTree); |
bpatel@766 | 245 | } |
bpatel@766 | 246 | |
bpatel@766 | 247 | /** |
bpatel@766 | 248 | * Build the summaries for the methods and fields. |
bpatel@766 | 249 | * |
bpatel@766 | 250 | * @param node the XML element that specifies which components to document |
bpatel@766 | 251 | * @param classTree content tree to which the documentation will be added |
bpatel@766 | 252 | */ |
bpatel@766 | 253 | public void buildClassContent(XMLNode node, Content classTree) { |
bpatel@766 | 254 | Content classContentTree = writer.getClassContentHeader(); |
bpatel@766 | 255 | buildChildren(node, classContentTree); |
bpatel@766 | 256 | classTree.addContent(classContentTree); |
bpatel@766 | 257 | } |
bpatel@766 | 258 | |
bpatel@766 | 259 | /** |
bpatel@766 | 260 | * Build the summaries for the methods that belong to the given |
bpatel@766 | 261 | * class. |
bpatel@766 | 262 | * |
bpatel@766 | 263 | * @param node the XML element that specifies which components to document |
bpatel@766 | 264 | * @param classContentTree content tree to which the documentation will be added |
bpatel@766 | 265 | */ |
bpatel@766 | 266 | public void buildSerializableMethods(XMLNode node, Content classContentTree) { |
bpatel@766 | 267 | Content serializableMethodTree = methodWriter.getSerializableMethodsHeader(); |
bpatel@766 | 268 | MemberDoc[] members = currentClass.serializationMethods(); |
bpatel@766 | 269 | int membersLength = members.length; |
bpatel@766 | 270 | if (membersLength > 0) { |
bpatel@766 | 271 | for (int i = 0; i < membersLength; i++) { |
bpatel@766 | 272 | currentMember = members[i]; |
bpatel@766 | 273 | Content methodsContentTree = methodWriter.getMethodsContentHeader( |
bpatel@766 | 274 | (i == membersLength - 1)); |
bpatel@766 | 275 | buildChildren(node, methodsContentTree); |
bpatel@766 | 276 | serializableMethodTree.addContent(methodsContentTree); |
bpatel@766 | 277 | } |
bpatel@766 | 278 | } |
bpatel@766 | 279 | if (currentClass.serializationMethods().length > 0) { |
bpatel@766 | 280 | classContentTree.addContent(methodWriter.getSerializableMethods( |
bpatel@766 | 281 | configuration.getText("doclet.Serialized_Form_methods"), |
bpatel@766 | 282 | serializableMethodTree)); |
bpatel@766 | 283 | if (currentClass.isSerializable() && !currentClass.isExternalizable()) { |
bpatel@766 | 284 | if (currentClass.serializationMethods().length == 0) { |
bpatel@766 | 285 | Content noCustomizationMsg = methodWriter.getNoCustomizationMsg( |
bpatel@766 | 286 | configuration.getText( |
bpatel@766 | 287 | "doclet.Serializable_no_customization")); |
bpatel@766 | 288 | classContentTree.addContent(methodWriter.getSerializableMethods( |
bpatel@766 | 289 | configuration.getText("doclet.Serialized_Form_methods"), |
bpatel@766 | 290 | noCustomizationMsg)); |
bpatel@766 | 291 | } |
duke@1 | 292 | } |
duke@1 | 293 | } |
duke@1 | 294 | } |
duke@1 | 295 | |
duke@1 | 296 | /** |
bpatel@766 | 297 | * Build the method sub header. |
bpatel@766 | 298 | * |
bpatel@766 | 299 | * @param node the XML element that specifies which components to document |
bpatel@766 | 300 | * @param methodsContentTree content tree to which the documentation will be added |
duke@1 | 301 | */ |
bpatel@766 | 302 | public void buildMethodSubHeader(XMLNode node, Content methodsContentTree) { |
bpatel@766 | 303 | methodWriter.addMemberHeader((MethodDoc)currentMember, methodsContentTree); |
bpatel@766 | 304 | } |
bpatel@766 | 305 | |
bpatel@766 | 306 | /** |
bpatel@766 | 307 | * Build the deprecated method description. |
bpatel@766 | 308 | * |
bpatel@766 | 309 | * @param node the XML element that specifies which components to document |
bpatel@766 | 310 | * @param methodsContentTree content tree to which the documentation will be added |
bpatel@766 | 311 | */ |
bpatel@766 | 312 | public void buildDeprecatedMethodInfo(XMLNode node, Content methodsContentTree) { |
bpatel@766 | 313 | methodWriter.addDeprecatedMemberInfo((MethodDoc) currentMember, methodsContentTree); |
bpatel@766 | 314 | } |
bpatel@766 | 315 | |
bpatel@766 | 316 | /** |
bpatel@766 | 317 | * Build the information for the method. |
bpatel@766 | 318 | * |
bpatel@766 | 319 | * @param node the XML element that specifies which components to document |
bpatel@766 | 320 | * @param methodsContentTree content tree to which the documentation will be added |
bpatel@766 | 321 | */ |
bpatel@766 | 322 | public void buildMethodInfo(XMLNode node, Content methodsContentTree) { |
bpatel@766 | 323 | if(configuration.nocomment){ |
bpatel@766 | 324 | return; |
bpatel@766 | 325 | } |
bpatel@766 | 326 | buildChildren(node, methodsContentTree); |
bpatel@766 | 327 | } |
bpatel@766 | 328 | |
bpatel@766 | 329 | /** |
bpatel@766 | 330 | * Build method description. |
bpatel@766 | 331 | * |
bpatel@766 | 332 | * @param node the XML element that specifies which components to document |
bpatel@766 | 333 | * @param methodsContentTree content tree to which the documentation will be added |
bpatel@766 | 334 | */ |
bpatel@766 | 335 | public void buildMethodDescription(XMLNode node, Content methodsContentTree) { |
bpatel@766 | 336 | methodWriter.addMemberDescription((MethodDoc) currentMember, methodsContentTree); |
bpatel@766 | 337 | } |
bpatel@766 | 338 | |
bpatel@766 | 339 | /** |
bpatel@766 | 340 | * Build the method tags. |
bpatel@766 | 341 | * |
bpatel@766 | 342 | * @param node the XML element that specifies which components to document |
bpatel@766 | 343 | * @param methodsContentTree content tree to which the documentation will be added |
bpatel@766 | 344 | */ |
bpatel@766 | 345 | public void buildMethodTags(XMLNode node, Content methodsContentTree) { |
bpatel@766 | 346 | methodWriter.addMemberTags((MethodDoc) currentMember, methodsContentTree); |
bpatel@766 | 347 | MethodDoc method = (MethodDoc)currentMember; |
bpatel@766 | 348 | if (method.name().compareTo("writeExternal") == 0 |
bpatel@766 | 349 | && method.tags("serialData").length == 0) { |
bpatel@766 | 350 | if (configuration.serialwarn) { |
bpatel@766 | 351 | configuration.getDocletSpecificMsg().warning( |
bpatel@766 | 352 | currentMember.position(), "doclet.MissingSerialDataTag", |
bpatel@766 | 353 | method.containingClass().qualifiedName(), method.name()); |
bpatel@766 | 354 | } |
bpatel@766 | 355 | } |
bpatel@766 | 356 | } |
bpatel@766 | 357 | |
bpatel@766 | 358 | /** |
bpatel@766 | 359 | * Build the field header. |
bpatel@766 | 360 | * |
bpatel@766 | 361 | * @param node the XML element that specifies which components to document |
bpatel@766 | 362 | * @param classContentTree content tree to which the documentation will be added |
bpatel@766 | 363 | */ |
bpatel@766 | 364 | public void buildFieldHeader(XMLNode node, Content classContentTree) { |
bpatel@766 | 365 | if (currentClass.serializableFields().length > 0) { |
bpatel@766 | 366 | buildFieldSerializationOverview(currentClass, classContentTree); |
bpatel@766 | 367 | } |
bpatel@766 | 368 | } |
bpatel@766 | 369 | |
bpatel@766 | 370 | /** |
bpatel@766 | 371 | * Build the serialization overview for the given class. |
bpatel@766 | 372 | * |
bpatel@766 | 373 | * @param classDoc the class to print the overview for. |
bpatel@766 | 374 | * @param classContentTree content tree to which the documentation will be added |
bpatel@766 | 375 | */ |
bpatel@766 | 376 | public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) { |
bpatel@766 | 377 | if (classDoc.definesSerializableFields()) { |
bpatel@766 | 378 | FieldDoc serialPersistentField = |
bpatel@766 | 379 | Util.asList(classDoc.serializableFields()).get(0); |
bpatel@766 | 380 | // Check to see if there are inline comments, tags or deprecation |
bpatel@766 | 381 | // information to be printed. |
bpatel@766 | 382 | if (fieldWriter.shouldPrintOverview(serialPersistentField)) { |
bpatel@766 | 383 | Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader(); |
bpatel@766 | 384 | Content fieldsOverviewContentTree = fieldWriter.getFieldsContentHeader(true); |
bpatel@766 | 385 | fieldWriter.addMemberDeprecatedInfo(serialPersistentField, |
bpatel@766 | 386 | fieldsOverviewContentTree); |
bpatel@766 | 387 | if (!configuration.nocomment) { |
bpatel@766 | 388 | fieldWriter.addMemberDescription(serialPersistentField, |
bpatel@766 | 389 | fieldsOverviewContentTree); |
bpatel@766 | 390 | fieldWriter.addMemberTags(serialPersistentField, |
bpatel@766 | 391 | fieldsOverviewContentTree); |
bpatel@766 | 392 | } |
bpatel@766 | 393 | serializableFieldsTree.addContent(fieldsOverviewContentTree); |
bpatel@766 | 394 | classContentTree.addContent(fieldWriter.getSerializableFields( |
bpatel@766 | 395 | configuration.getText("doclet.Serialized_Form_class"), |
bpatel@766 | 396 | serializableFieldsTree)); |
bpatel@766 | 397 | } |
bpatel@766 | 398 | } |
bpatel@766 | 399 | } |
bpatel@766 | 400 | |
bpatel@766 | 401 | /** |
bpatel@766 | 402 | * Build the summaries for the fields that belong to the given class. |
bpatel@766 | 403 | * |
bpatel@766 | 404 | * @param node the XML element that specifies which components to document |
bpatel@766 | 405 | * @param classContentTree content tree to which the documentation will be added |
bpatel@766 | 406 | */ |
bpatel@766 | 407 | public void buildSerializableFields(XMLNode node, Content classContentTree) { |
bpatel@766 | 408 | MemberDoc[] members = currentClass.serializableFields(); |
bpatel@766 | 409 | int membersLength = members.length; |
bpatel@766 | 410 | if (membersLength > 0) { |
bpatel@766 | 411 | Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader(); |
bpatel@766 | 412 | for (int i = 0; i < membersLength; i++) { |
bpatel@766 | 413 | currentMember = members[i]; |
bpatel@766 | 414 | if (!currentClass.definesSerializableFields()) { |
bpatel@766 | 415 | Content fieldsContentTree = fieldWriter.getFieldsContentHeader( |
bpatel@766 | 416 | (i == membersLength - 1)); |
bpatel@766 | 417 | buildChildren(node, fieldsContentTree); |
bpatel@766 | 418 | serializableFieldsTree.addContent(fieldsContentTree); |
bpatel@766 | 419 | } |
bpatel@766 | 420 | else { |
bpatel@766 | 421 | buildSerialFieldTagsInfo(serializableFieldsTree); |
bpatel@766 | 422 | } |
bpatel@766 | 423 | } |
bpatel@766 | 424 | classContentTree.addContent(fieldWriter.getSerializableFields( |
bpatel@766 | 425 | configuration.getText("doclet.Serialized_Form_fields"), |
bpatel@766 | 426 | serializableFieldsTree)); |
bpatel@766 | 427 | } |
bpatel@766 | 428 | } |
bpatel@766 | 429 | |
bpatel@766 | 430 | /** |
bpatel@766 | 431 | * Build the field sub header. |
bpatel@766 | 432 | * |
bpatel@766 | 433 | * @param node the XML element that specifies which components to document |
bpatel@766 | 434 | * @param fieldsContentTree content tree to which the documentation will be added |
bpatel@766 | 435 | */ |
bpatel@766 | 436 | public void buildFieldSubHeader(XMLNode node, Content fieldsContentTree) { |
bpatel@766 | 437 | if (!currentClass.definesSerializableFields()) { |
bpatel@766 | 438 | FieldDoc field = (FieldDoc) currentMember; |
bpatel@766 | 439 | fieldWriter.addMemberHeader(field.type().asClassDoc(), |
bpatel@766 | 440 | field.type().typeName(), field.type().dimension(), field.name(), |
bpatel@766 | 441 | fieldsContentTree); |
bpatel@766 | 442 | } |
bpatel@766 | 443 | } |
bpatel@766 | 444 | |
bpatel@766 | 445 | /** |
bpatel@766 | 446 | * Build the field deprecation information. |
bpatel@766 | 447 | * |
bpatel@766 | 448 | * @param node the XML element that specifies which components to document |
bpatel@766 | 449 | * @param fieldsContentTree content tree to which the documentation will be added |
bpatel@766 | 450 | */ |
bpatel@766 | 451 | public void buildFieldDeprecationInfo(XMLNode node, Content fieldsContentTree) { |
bpatel@766 | 452 | if (!currentClass.definesSerializableFields()) { |
bpatel@766 | 453 | FieldDoc field = (FieldDoc)currentMember; |
bpatel@766 | 454 | fieldWriter.addMemberDeprecatedInfo(field, fieldsContentTree); |
bpatel@766 | 455 | } |
bpatel@766 | 456 | } |
bpatel@766 | 457 | |
bpatel@766 | 458 | /** |
bpatel@766 | 459 | * Build the serial field tags information. |
bpatel@766 | 460 | * |
bpatel@766 | 461 | * @param serializableFieldsTree content tree to which the documentation will be added |
bpatel@766 | 462 | */ |
bpatel@766 | 463 | public void buildSerialFieldTagsInfo(Content serializableFieldsTree) { |
bpatel@766 | 464 | if(configuration.nocomment){ |
bpatel@766 | 465 | return; |
bpatel@766 | 466 | } |
bpatel@766 | 467 | FieldDoc field = (FieldDoc)currentMember; |
bpatel@766 | 468 | // Process Serializable Fields specified as array of |
bpatel@766 | 469 | // ObjectStreamFields. Print a member for each serialField tag. |
bpatel@766 | 470 | // (There should be one serialField tag per ObjectStreamField |
bpatel@766 | 471 | // element.) |
bpatel@766 | 472 | SerialFieldTag[] tags = field.serialFieldTags(); |
bpatel@766 | 473 | Arrays.sort(tags); |
bpatel@766 | 474 | int tagsLength = tags.length; |
bpatel@766 | 475 | for (int i = 0; i < tagsLength; i++) { |
bpatel@766 | 476 | Content fieldsContentTree = fieldWriter.getFieldsContentHeader( |
bpatel@766 | 477 | (i == tagsLength - 1)); |
bpatel@766 | 478 | fieldWriter.addMemberHeader(tags[i].fieldTypeDoc(), |
bpatel@766 | 479 | tags[i].fieldType(), "", tags[i].fieldName(), fieldsContentTree); |
bpatel@766 | 480 | fieldWriter.addMemberDescription(tags[i], fieldsContentTree); |
bpatel@766 | 481 | serializableFieldsTree.addContent(fieldsContentTree); |
bpatel@766 | 482 | } |
bpatel@766 | 483 | } |
bpatel@766 | 484 | |
bpatel@766 | 485 | /** |
bpatel@766 | 486 | * Build the field information. |
bpatel@766 | 487 | * |
bpatel@766 | 488 | * @param node the XML element that specifies which components to document |
bpatel@766 | 489 | * @param fieldsContentTree content tree to which the documentation will be added |
bpatel@766 | 490 | */ |
bpatel@766 | 491 | public void buildFieldInfo(XMLNode node, Content fieldsContentTree) { |
bpatel@766 | 492 | if(configuration.nocomment){ |
bpatel@766 | 493 | return; |
bpatel@766 | 494 | } |
bpatel@766 | 495 | FieldDoc field = (FieldDoc)currentMember; |
bpatel@766 | 496 | ClassDoc cd = field.containingClass(); |
bpatel@766 | 497 | // Process default Serializable field. |
bpatel@766 | 498 | if ((field.tags("serial").length == 0) && ! field.isSynthetic() |
bpatel@766 | 499 | && configuration.serialwarn) { |
bpatel@766 | 500 | configuration.message.warning(field.position(), |
bpatel@766 | 501 | "doclet.MissingSerialTag", cd.qualifiedName(), |
bpatel@766 | 502 | field.name()); |
bpatel@766 | 503 | } |
bpatel@766 | 504 | fieldWriter.addMemberDescription(field, fieldsContentTree); |
bpatel@766 | 505 | fieldWriter.addMemberTags(field, fieldsContentTree); |
duke@1 | 506 | } |
duke@1 | 507 | |
duke@1 | 508 | /** |
duke@1 | 509 | * Return true if the given Doc should be included |
duke@1 | 510 | * in the serialized form. |
duke@1 | 511 | * |
duke@1 | 512 | * @param doc the Doc object to check for serializability. |
duke@1 | 513 | */ |
duke@1 | 514 | public static boolean serialInclude(Doc doc) { |
duke@1 | 515 | if (doc == null) { |
duke@1 | 516 | return false; |
duke@1 | 517 | } |
duke@1 | 518 | return doc.isClass() ? |
duke@1 | 519 | serialClassInclude((ClassDoc)doc) : |
duke@1 | 520 | serialDocInclude(doc); |
duke@1 | 521 | } |
duke@1 | 522 | |
duke@1 | 523 | /** |
duke@1 | 524 | * Return true if the given ClassDoc should be included |
duke@1 | 525 | * in the serialized form. |
duke@1 | 526 | * |
duke@1 | 527 | * @param cd the ClassDoc object to check for serializability. |
duke@1 | 528 | */ |
duke@1 | 529 | private static boolean serialClassInclude(ClassDoc cd) { |
duke@1 | 530 | if (cd.isEnum()) { |
duke@1 | 531 | return false; |
duke@1 | 532 | } |
duke@1 | 533 | try { |
duke@1 | 534 | cd.superclassType(); |
duke@1 | 535 | } catch (NullPointerException e) { |
duke@1 | 536 | //Workaround for null pointer bug in ClassDoc.superclassType(). |
duke@1 | 537 | return false; |
duke@1 | 538 | } |
duke@1 | 539 | if (cd.isSerializable()) { |
duke@1 | 540 | if (cd.tags("serial").length > 0) { |
duke@1 | 541 | return serialDocInclude(cd); |
duke@1 | 542 | } else if (cd.isPublic() || cd.isProtected()) { |
duke@1 | 543 | return true; |
duke@1 | 544 | } else { |
duke@1 | 545 | return false; |
duke@1 | 546 | } |
duke@1 | 547 | } |
duke@1 | 548 | return false; |
duke@1 | 549 | } |
duke@1 | 550 | |
duke@1 | 551 | /** |
duke@1 | 552 | * Return true if the given Doc should be included |
duke@1 | 553 | * in the serialized form. |
duke@1 | 554 | * |
duke@1 | 555 | * @param doc the Doc object to check for serializability. |
duke@1 | 556 | */ |
duke@1 | 557 | private static boolean serialDocInclude(Doc doc) { |
duke@1 | 558 | if (doc.isEnum()) { |
duke@1 | 559 | return false; |
duke@1 | 560 | } |
duke@1 | 561 | Tag[] serial = doc.tags("serial"); |
duke@1 | 562 | if (serial.length > 0) { |
duke@1 | 563 | String serialtext = serial[0].text().toLowerCase(); |
duke@1 | 564 | if (serialtext.indexOf("exclude") >= 0) { |
duke@1 | 565 | return false; |
duke@1 | 566 | } else if (serialtext.indexOf("include") >= 0) { |
duke@1 | 567 | return true; |
duke@1 | 568 | } |
duke@1 | 569 | } |
duke@1 | 570 | return true; |
duke@1 | 571 | } |
duke@1 | 572 | |
duke@1 | 573 | /** |
duke@1 | 574 | * Return true if any of the given classes have a @serialinclude tag. |
duke@1 | 575 | * |
duke@1 | 576 | * @param classes the classes to check. |
duke@1 | 577 | * @return true if any of the given classes have a @serialinclude tag. |
duke@1 | 578 | */ |
duke@1 | 579 | private boolean serialClassFoundToDocument(ClassDoc[] classes) { |
duke@1 | 580 | for (int i = 0; i < classes.length; i++) { |
duke@1 | 581 | if (serialClassInclude(classes[i])) { |
duke@1 | 582 | return true; |
duke@1 | 583 | } |
duke@1 | 584 | } |
duke@1 | 585 | return false; |
duke@1 | 586 | } |
duke@1 | 587 | } |