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