src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,595 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.internal.toolkit.builders;
    1.30 +
    1.31 +import java.io.*;
    1.32 +import java.util.*;
    1.33 +
    1.34 +import com.sun.javadoc.*;
    1.35 +import com.sun.tools.doclets.internal.toolkit.*;
    1.36 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.37 +import com.sun.tools.javac.util.StringUtils;
    1.38 +
    1.39 +/**
    1.40 + * Builds the serialized form.
    1.41 + *
    1.42 + *  <p><b>This is NOT part of any supported API.
    1.43 + *  If you write code that depends on this, you do so at your own risk.
    1.44 + *  This code and its internal interfaces are subject to change or
    1.45 + *  deletion without notice.</b>
    1.46 + *
    1.47 + * @author Jamie Ho
    1.48 + * @author Bhavesh Patel (Modified)
    1.49 + * @since 1.5
    1.50 + */
    1.51 +public class SerializedFormBuilder extends AbstractBuilder {
    1.52 +
    1.53 +    /**
    1.54 +     * The root element of the serialized form XML is {@value}.
    1.55 +     */
    1.56 +    public static final String NAME = "SerializedForm";
    1.57 +
    1.58 +    /**
    1.59 +     * The writer for this builder.
    1.60 +     */
    1.61 +    private SerializedFormWriter writer;
    1.62 +
    1.63 +    /**
    1.64 +     * The writer for serializable fields.
    1.65 +     */
    1.66 +    private SerializedFormWriter.SerialFieldWriter fieldWriter;
    1.67 +
    1.68 +    /**
    1.69 +     * The writer for serializable method documentation.
    1.70 +     */
    1.71 +    private SerializedFormWriter.SerialMethodWriter methodWriter;
    1.72 +
    1.73 +    /**
    1.74 +     * The header for the serial version UID.  Save the string
    1.75 +     * here instead of the properties file because we do not want
    1.76 +     * this string to be localized.
    1.77 +     */
    1.78 +    private static final String SERIAL_VERSION_UID_HEADER = "serialVersionUID:";
    1.79 +
    1.80 +    /**
    1.81 +     * The current package being documented.
    1.82 +     */
    1.83 +    private PackageDoc currentPackage;
    1.84 +
    1.85 +    /**
    1.86 +     * The current class being documented.
    1.87 +     */
    1.88 +    private ClassDoc currentClass;
    1.89 +
    1.90 +    /**
    1.91 +     * The current member being documented.
    1.92 +     */
    1.93 +    protected MemberDoc currentMember;
    1.94 +
    1.95 +    /**
    1.96 +     * The content that will be added to the serialized form documentation tree.
    1.97 +     */
    1.98 +    private Content contentTree;
    1.99 +
   1.100 +
   1.101 +    /**
   1.102 +     * Construct a new SerializedFormBuilder.
   1.103 +     * @param context  the build context.
   1.104 +     */
   1.105 +    private SerializedFormBuilder(Context context) {
   1.106 +        super(context);
   1.107 +    }
   1.108 +
   1.109 +    /**
   1.110 +     * Construct a new SerializedFormBuilder.
   1.111 +     * @param context  the build context.
   1.112 +     */
   1.113 +    public static SerializedFormBuilder getInstance(Context context) {
   1.114 +        return new SerializedFormBuilder(context);
   1.115 +    }
   1.116 +
   1.117 +    /**
   1.118 +     * Build the serialized form.
   1.119 +     */
   1.120 +    public void build() throws IOException {
   1.121 +        if (! serialClassFoundToDocument(configuration.root.classes())) {
   1.122 +            //Nothing to document.
   1.123 +            return;
   1.124 +        }
   1.125 +        try {
   1.126 +            writer = configuration.getWriterFactory().getSerializedFormWriter();
   1.127 +            if (writer == null) {
   1.128 +                //Doclet does not support this output.
   1.129 +                return;
   1.130 +            }
   1.131 +        } catch (Exception e) {
   1.132 +            throw new DocletAbortException(e);
   1.133 +        }
   1.134 +        build(layoutParser.parseXML(NAME), contentTree);
   1.135 +        writer.close();
   1.136 +    }
   1.137 +
   1.138 +    /**
   1.139 +     * {@inheritDoc}
   1.140 +     */
   1.141 +    public String getName() {
   1.142 +        return NAME;
   1.143 +    }
   1.144 +
   1.145 +    /**
   1.146 +     * Build the serialized form.
   1.147 +     *
   1.148 +     * @param node the XML element that specifies which components to document
   1.149 +     * @param serializedTree content tree to which the documentation will be added
   1.150 +     */
   1.151 +    public void buildSerializedForm(XMLNode node, Content serializedTree) throws Exception {
   1.152 +        serializedTree = writer.getHeader(configuration.getText(
   1.153 +                "doclet.Serialized_Form"));
   1.154 +        buildChildren(node, serializedTree);
   1.155 +        writer.addFooter(serializedTree);
   1.156 +        writer.printDocument(serializedTree);
   1.157 +        writer.close();
   1.158 +    }
   1.159 +
   1.160 +    /**
   1.161 +     * Build the serialized form summaries.
   1.162 +     *
   1.163 +     * @param node the XML element that specifies which components to document
   1.164 +     * @param serializedTree content tree to which the documentation will be added
   1.165 +     */
   1.166 +    public void buildSerializedFormSummaries(XMLNode node, Content serializedTree) {
   1.167 +        Content serializedSummariesTree = writer.getSerializedSummariesHeader();
   1.168 +        PackageDoc[] packages = configuration.packages;
   1.169 +        for (int i = 0; i < packages.length; i++) {
   1.170 +            currentPackage = packages[i];
   1.171 +            buildChildren(node, serializedSummariesTree);
   1.172 +        }
   1.173 +        serializedTree.addContent(writer.getSerializedContent(
   1.174 +                serializedSummariesTree));
   1.175 +    }
   1.176 +
   1.177 +    /**
   1.178 +     * Build the package serialized form for the current package being processed.
   1.179 +     *
   1.180 +     * @param node the XML element that specifies which components to document
   1.181 +     * @param serializedSummariesTree content tree to which the documentation will be added
   1.182 +     */
   1.183 +    public void buildPackageSerializedForm(XMLNode node, Content serializedSummariesTree) {
   1.184 +        Content packageSerializedTree = writer.getPackageSerializedHeader();
   1.185 +        String foo = currentPackage.name();
   1.186 +        ClassDoc[] classes = currentPackage.allClasses(false);
   1.187 +        if (classes == null || classes.length == 0) {
   1.188 +            return;
   1.189 +        }
   1.190 +        if (!serialInclude(currentPackage)) {
   1.191 +            return;
   1.192 +        }
   1.193 +        if (!serialClassFoundToDocument(classes)) {
   1.194 +            return;
   1.195 +        }
   1.196 +        buildChildren(node, packageSerializedTree);
   1.197 +        serializedSummariesTree.addContent(packageSerializedTree);
   1.198 +    }
   1.199 +
   1.200 +    /**
   1.201 +     * Build the package header.
   1.202 +     *
   1.203 +     * @param node the XML element that specifies which components to document
   1.204 +     * @param packageSerializedTree content tree to which the documentation will be added
   1.205 +     */
   1.206 +    public void buildPackageHeader(XMLNode node, Content packageSerializedTree) {
   1.207 +        packageSerializedTree.addContent(writer.getPackageHeader(
   1.208 +                Util.getPackageName(currentPackage)));
   1.209 +    }
   1.210 +
   1.211 +    /**
   1.212 +     * Build the class serialized form.
   1.213 +     *
   1.214 +     * @param node the XML element that specifies which components to document
   1.215 +     * @param packageSerializedTree content tree to which the documentation will be added
   1.216 +     */
   1.217 +    public void buildClassSerializedForm(XMLNode node, Content packageSerializedTree) {
   1.218 +        Content classSerializedTree = writer.getClassSerializedHeader();
   1.219 +        ClassDoc[] classes = currentPackage.allClasses(false);
   1.220 +        Arrays.sort(classes);
   1.221 +        for (int j = 0; j < classes.length; j++) {
   1.222 +            currentClass = classes[j];
   1.223 +            fieldWriter = writer.getSerialFieldWriter(currentClass);
   1.224 +            methodWriter = writer.getSerialMethodWriter(currentClass);
   1.225 +            if(currentClass.isClass() && currentClass.isSerializable()) {
   1.226 +                if(!serialClassInclude(currentClass)) {
   1.227 +                    continue;
   1.228 +                }
   1.229 +                Content classTree = writer.getClassHeader(currentClass);
   1.230 +                buildChildren(node, classTree);
   1.231 +                classSerializedTree.addContent(classTree);
   1.232 +            }
   1.233 +        }
   1.234 +        packageSerializedTree.addContent(classSerializedTree);
   1.235 +    }
   1.236 +
   1.237 +    /**
   1.238 +     * Build the serial UID information for the given class.
   1.239 +     *
   1.240 +     * @param node the XML element that specifies which components to document
   1.241 +     * @param classTree content tree to which the serial UID information will be added
   1.242 +     */
   1.243 +    public void buildSerialUIDInfo(XMLNode node, Content classTree) {
   1.244 +        Content serialUidTree = writer.getSerialUIDInfoHeader();
   1.245 +        FieldDoc[] fields = currentClass.fields(false);
   1.246 +        for (int i = 0; i < fields.length; i++) {
   1.247 +            if (fields[i].name().equals("serialVersionUID") &&
   1.248 +                fields[i].constantValueExpression() != null) {
   1.249 +                writer.addSerialUIDInfo(SERIAL_VERSION_UID_HEADER,
   1.250 +                        fields[i].constantValueExpression(), serialUidTree);
   1.251 +                break;
   1.252 +            }
   1.253 +        }
   1.254 +        classTree.addContent(serialUidTree);
   1.255 +    }
   1.256 +
   1.257 +    /**
   1.258 +     * Build the summaries for the methods and fields.
   1.259 +     *
   1.260 +     * @param node the XML element that specifies which components to document
   1.261 +     * @param classTree content tree to which the documentation will be added
   1.262 +     */
   1.263 +    public void buildClassContent(XMLNode node, Content classTree) {
   1.264 +        Content classContentTree = writer.getClassContentHeader();
   1.265 +        buildChildren(node, classContentTree);
   1.266 +        classTree.addContent(classContentTree);
   1.267 +    }
   1.268 +
   1.269 +    /**
   1.270 +     * Build the summaries for the methods that belong to the given
   1.271 +     * class.
   1.272 +     *
   1.273 +     * @param node the XML element that specifies which components to document
   1.274 +     * @param classContentTree content tree to which the documentation will be added
   1.275 +     */
   1.276 +    public void buildSerializableMethods(XMLNode node, Content classContentTree) {
   1.277 +        Content serializableMethodTree = methodWriter.getSerializableMethodsHeader();
   1.278 +        MemberDoc[] members = currentClass.serializationMethods();
   1.279 +        int membersLength = members.length;
   1.280 +        if (membersLength > 0) {
   1.281 +            for (int i = 0; i < membersLength; i++) {
   1.282 +                currentMember = members[i];
   1.283 +                Content methodsContentTree = methodWriter.getMethodsContentHeader(
   1.284 +                        (i == membersLength - 1));
   1.285 +                buildChildren(node, methodsContentTree);
   1.286 +                serializableMethodTree.addContent(methodsContentTree);
   1.287 +            }
   1.288 +        }
   1.289 +        if (currentClass.serializationMethods().length > 0) {
   1.290 +            classContentTree.addContent(methodWriter.getSerializableMethods(
   1.291 +                    configuration.getText("doclet.Serialized_Form_methods"),
   1.292 +                    serializableMethodTree));
   1.293 +            if (currentClass.isSerializable() && !currentClass.isExternalizable()) {
   1.294 +                if (currentClass.serializationMethods().length == 0) {
   1.295 +                    Content noCustomizationMsg = methodWriter.getNoCustomizationMsg(
   1.296 +                            configuration.getText(
   1.297 +                            "doclet.Serializable_no_customization"));
   1.298 +                    classContentTree.addContent(methodWriter.getSerializableMethods(
   1.299 +                    configuration.getText("doclet.Serialized_Form_methods"),
   1.300 +                    noCustomizationMsg));
   1.301 +                }
   1.302 +            }
   1.303 +        }
   1.304 +    }
   1.305 +
   1.306 +    /**
   1.307 +     * Build the method sub header.
   1.308 +     *
   1.309 +     * @param node the XML element that specifies which components to document
   1.310 +     * @param methodsContentTree content tree to which the documentation will be added
   1.311 +     */
   1.312 +    public void buildMethodSubHeader(XMLNode node, Content methodsContentTree)  {
   1.313 +        methodWriter.addMemberHeader((MethodDoc)currentMember, methodsContentTree);
   1.314 +    }
   1.315 +
   1.316 +    /**
   1.317 +     * Build the deprecated method description.
   1.318 +     *
   1.319 +     * @param node the XML element that specifies which components to document
   1.320 +     * @param methodsContentTree content tree to which the documentation will be added
   1.321 +     */
   1.322 +    public void buildDeprecatedMethodInfo(XMLNode node, Content methodsContentTree) {
   1.323 +        methodWriter.addDeprecatedMemberInfo((MethodDoc) currentMember, methodsContentTree);
   1.324 +    }
   1.325 +
   1.326 +    /**
   1.327 +     * Build the information for the method.
   1.328 +     *
   1.329 +     * @param node the XML element that specifies which components to document
   1.330 +     * @param methodsContentTree content tree to which the documentation will be added
   1.331 +     */
   1.332 +    public void buildMethodInfo(XMLNode node, Content methodsContentTree)  {
   1.333 +        if(configuration.nocomment){
   1.334 +            return;
   1.335 +        }
   1.336 +        buildChildren(node, methodsContentTree);
   1.337 +    }
   1.338 +
   1.339 +    /**
   1.340 +     * Build method description.
   1.341 +     *
   1.342 +     * @param node the XML element that specifies which components to document
   1.343 +     * @param methodsContentTree content tree to which the documentation will be added
   1.344 +     */
   1.345 +    public void buildMethodDescription(XMLNode node, Content methodsContentTree) {
   1.346 +        methodWriter.addMemberDescription((MethodDoc) currentMember, methodsContentTree);
   1.347 +    }
   1.348 +
   1.349 +    /**
   1.350 +     * Build the method tags.
   1.351 +     *
   1.352 +     * @param node the XML element that specifies which components to document
   1.353 +     * @param methodsContentTree content tree to which the documentation will be added
   1.354 +     */
   1.355 +    public void buildMethodTags(XMLNode node, Content methodsContentTree) {
   1.356 +        methodWriter.addMemberTags((MethodDoc) currentMember, methodsContentTree);
   1.357 +        MethodDoc method = (MethodDoc)currentMember;
   1.358 +        if (method.name().compareTo("writeExternal") == 0
   1.359 +                && method.tags("serialData").length == 0) {
   1.360 +            if (configuration.serialwarn) {
   1.361 +                configuration.getDocletSpecificMsg().warning(
   1.362 +                        currentMember.position(), "doclet.MissingSerialDataTag",
   1.363 +                        method.containingClass().qualifiedName(), method.name());
   1.364 +            }
   1.365 +        }
   1.366 +    }
   1.367 +
   1.368 +    /**
   1.369 +     * Build the field header.
   1.370 +     *
   1.371 +     * @param node the XML element that specifies which components to document
   1.372 +     * @param classContentTree content tree to which the documentation will be added
   1.373 +     */
   1.374 +    public void buildFieldHeader(XMLNode node, Content classContentTree) {
   1.375 +        if (currentClass.serializableFields().length > 0) {
   1.376 +            buildFieldSerializationOverview(currentClass, classContentTree);
   1.377 +        }
   1.378 +    }
   1.379 +
   1.380 +    /**
   1.381 +     * Build the serialization overview for the given class.
   1.382 +     *
   1.383 +     * @param classDoc the class to print the overview for.
   1.384 +     * @param classContentTree content tree to which the documentation will be added
   1.385 +     */
   1.386 +    public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) {
   1.387 +        if (classDoc.definesSerializableFields()) {
   1.388 +            FieldDoc serialPersistentField = classDoc.serializableFields()[0];
   1.389 +            // Check to see if there are inline comments, tags or deprecation
   1.390 +            // information to be printed.
   1.391 +            if (fieldWriter.shouldPrintOverview(serialPersistentField)) {
   1.392 +                Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader();
   1.393 +                Content fieldsOverviewContentTree = fieldWriter.getFieldsContentHeader(true);
   1.394 +                fieldWriter.addMemberDeprecatedInfo(serialPersistentField,
   1.395 +                        fieldsOverviewContentTree);
   1.396 +                if (!configuration.nocomment) {
   1.397 +                    fieldWriter.addMemberDescription(serialPersistentField,
   1.398 +                            fieldsOverviewContentTree);
   1.399 +                    fieldWriter.addMemberTags(serialPersistentField,
   1.400 +                            fieldsOverviewContentTree);
   1.401 +                }
   1.402 +                serializableFieldsTree.addContent(fieldsOverviewContentTree);
   1.403 +                classContentTree.addContent(fieldWriter.getSerializableFields(
   1.404 +                        configuration.getText("doclet.Serialized_Form_class"),
   1.405 +                        serializableFieldsTree));
   1.406 +            }
   1.407 +        }
   1.408 +    }
   1.409 +
   1.410 +    /**
   1.411 +     * Build the summaries for the fields that belong to the given class.
   1.412 +     *
   1.413 +     * @param node the XML element that specifies which components to document
   1.414 +     * @param classContentTree content tree to which the documentation will be added
   1.415 +     */
   1.416 +    public void buildSerializableFields(XMLNode node, Content classContentTree) {
   1.417 +        MemberDoc[] members = currentClass.serializableFields();
   1.418 +        int membersLength = members.length;
   1.419 +        if (membersLength > 0) {
   1.420 +            Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader();
   1.421 +            for (int i = 0; i < membersLength; i++) {
   1.422 +                currentMember = members[i];
   1.423 +                if (!currentClass.definesSerializableFields()) {
   1.424 +                    Content fieldsContentTree = fieldWriter.getFieldsContentHeader(
   1.425 +                            (i == membersLength - 1));
   1.426 +                    buildChildren(node, fieldsContentTree);
   1.427 +                    serializableFieldsTree.addContent(fieldsContentTree);
   1.428 +                }
   1.429 +                else {
   1.430 +                    buildSerialFieldTagsInfo(serializableFieldsTree);
   1.431 +                }
   1.432 +            }
   1.433 +            classContentTree.addContent(fieldWriter.getSerializableFields(
   1.434 +                    configuration.getText("doclet.Serialized_Form_fields"),
   1.435 +                    serializableFieldsTree));
   1.436 +        }
   1.437 +    }
   1.438 +
   1.439 +    /**
   1.440 +     * Build the field sub header.
   1.441 +     *
   1.442 +     * @param node the XML element that specifies which components to document
   1.443 +     * @param fieldsContentTree content tree to which the documentation will be added
   1.444 +     */
   1.445 +    public void buildFieldSubHeader(XMLNode node, Content fieldsContentTree) {
   1.446 +        if (!currentClass.definesSerializableFields()) {
   1.447 +            FieldDoc field = (FieldDoc) currentMember;
   1.448 +            fieldWriter.addMemberHeader(field.type().asClassDoc(),
   1.449 +                    field.type().typeName(), field.type().dimension(), field.name(),
   1.450 +                    fieldsContentTree);
   1.451 +        }
   1.452 +    }
   1.453 +
   1.454 +    /**
   1.455 +     * Build the field deprecation information.
   1.456 +     *
   1.457 +     * @param node the XML element that specifies which components to document
   1.458 +     * @param fieldsContentTree content tree to which the documentation will be added
   1.459 +     */
   1.460 +    public void buildFieldDeprecationInfo(XMLNode node, Content fieldsContentTree) {
   1.461 +        if (!currentClass.definesSerializableFields()) {
   1.462 +            FieldDoc field = (FieldDoc)currentMember;
   1.463 +            fieldWriter.addMemberDeprecatedInfo(field, fieldsContentTree);
   1.464 +        }
   1.465 +    }
   1.466 +
   1.467 +    /**
   1.468 +     * Build the serial field tags information.
   1.469 +     *
   1.470 +     * @param serializableFieldsTree content tree to which the documentation will be added
   1.471 +     */
   1.472 +    public void buildSerialFieldTagsInfo(Content serializableFieldsTree) {
   1.473 +        if(configuration.nocomment){
   1.474 +            return;
   1.475 +        }
   1.476 +        FieldDoc field = (FieldDoc)currentMember;
   1.477 +        // Process Serializable Fields specified as array of
   1.478 +        // ObjectStreamFields. Print a member for each serialField tag.
   1.479 +        // (There should be one serialField tag per ObjectStreamField
   1.480 +        // element.)
   1.481 +        SerialFieldTag[] tags = field.serialFieldTags();
   1.482 +        Arrays.sort(tags);
   1.483 +        int tagsLength = tags.length;
   1.484 +        for (int i = 0; i < tagsLength; i++) {
   1.485 +            if (tags[i].fieldName() == null || tags[i].fieldType() == null) // ignore malformed @serialField tags
   1.486 +                continue;
   1.487 +            Content fieldsContentTree = fieldWriter.getFieldsContentHeader(
   1.488 +                    (i == tagsLength - 1));
   1.489 +            fieldWriter.addMemberHeader(tags[i].fieldTypeDoc(),
   1.490 +                    tags[i].fieldType(), "", tags[i].fieldName(), fieldsContentTree);
   1.491 +            fieldWriter.addMemberDescription(tags[i], fieldsContentTree);
   1.492 +            serializableFieldsTree.addContent(fieldsContentTree);
   1.493 +        }
   1.494 +    }
   1.495 +
   1.496 +    /**
   1.497 +     * Build the field information.
   1.498 +     *
   1.499 +     * @param node the XML element that specifies which components to document
   1.500 +     * @param fieldsContentTree content tree to which the documentation will be added
   1.501 +     */
   1.502 +    public void buildFieldInfo(XMLNode node, Content fieldsContentTree) {
   1.503 +        if(configuration.nocomment){
   1.504 +            return;
   1.505 +        }
   1.506 +        FieldDoc field = (FieldDoc)currentMember;
   1.507 +        ClassDoc cd = field.containingClass();
   1.508 +        // Process default Serializable field.
   1.509 +        if ((field.tags("serial").length == 0) && ! field.isSynthetic()
   1.510 +                && configuration.serialwarn) {
   1.511 +            configuration.message.warning(field.position(),
   1.512 +                    "doclet.MissingSerialTag", cd.qualifiedName(),
   1.513 +                    field.name());
   1.514 +        }
   1.515 +        fieldWriter.addMemberDescription(field, fieldsContentTree);
   1.516 +        fieldWriter.addMemberTags(field, fieldsContentTree);
   1.517 +    }
   1.518 +
   1.519 +    /**
   1.520 +     * Return true if the given Doc should be included
   1.521 +     * in the serialized form.
   1.522 +     *
   1.523 +     * @param doc the Doc object to check for serializability.
   1.524 +     */
   1.525 +    public static boolean serialInclude(Doc doc) {
   1.526 +        if (doc == null) {
   1.527 +            return false;
   1.528 +        }
   1.529 +        return doc.isClass() ?
   1.530 +            serialClassInclude((ClassDoc)doc) :
   1.531 +            serialDocInclude(doc);
   1.532 +    }
   1.533 +
   1.534 +    /**
   1.535 +     * Return true if the given ClassDoc should be included
   1.536 +     * in the serialized form.
   1.537 +     *
   1.538 +     * @param cd the ClassDoc object to check for serializability.
   1.539 +     */
   1.540 +    private static boolean serialClassInclude(ClassDoc cd) {
   1.541 +        if (cd.isEnum()) {
   1.542 +            return false;
   1.543 +        }
   1.544 +        try {
   1.545 +            cd.superclassType();
   1.546 +        } catch (NullPointerException e) {
   1.547 +            //Workaround for null pointer bug in ClassDoc.superclassType().
   1.548 +            return false;
   1.549 +        }
   1.550 +        if (cd.isSerializable()) {
   1.551 +            if (cd.tags("serial").length > 0) {
   1.552 +                return serialDocInclude(cd);
   1.553 +            } else if (cd.isPublic() || cd.isProtected()) {
   1.554 +                return true;
   1.555 +            } else {
   1.556 +                return false;
   1.557 +            }
   1.558 +        }
   1.559 +        return false;
   1.560 +    }
   1.561 +
   1.562 +    /**
   1.563 +     * Return true if the given Doc should be included
   1.564 +     * in the serialized form.
   1.565 +     *
   1.566 +     * @param doc the Doc object to check for serializability.
   1.567 +     */
   1.568 +    private static boolean serialDocInclude(Doc doc) {
   1.569 +        if (doc.isEnum()) {
   1.570 +            return false;
   1.571 +        }
   1.572 +        Tag[] serial = doc.tags("serial");
   1.573 +        if (serial.length > 0) {
   1.574 +            String serialtext = StringUtils.toLowerCase(serial[0].text());
   1.575 +            if (serialtext.indexOf("exclude") >= 0) {
   1.576 +                return false;
   1.577 +            } else if (serialtext.indexOf("include") >= 0) {
   1.578 +                return true;
   1.579 +            }
   1.580 +        }
   1.581 +        return true;
   1.582 +    }
   1.583 +
   1.584 +    /**
   1.585 +     * Return true if any of the given classes have a @serialinclude tag.
   1.586 +     *
   1.587 +     * @param classes the classes to check.
   1.588 +     * @return true if any of the given classes have a @serialinclude tag.
   1.589 +     */
   1.590 +    private boolean serialClassFoundToDocument(ClassDoc[] classes) {
   1.591 +        for (int i = 0; i < classes.length; i++) {
   1.592 +            if (serialClassInclude(classes[i])) {
   1.593 +                return true;
   1.594 +            }
   1.595 +        }
   1.596 +        return false;
   1.597 +    }
   1.598 +}

mercurial