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