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