langtools/src/share/classes/com/sun/tools/javadoc/SerializedForm.java
author jjg
Wed, 01 Oct 2008 16:26:33 -0700
changeset 1363 d7fc53d64560
parent 1260 a772ba9ba43d
child 1264 076a3cde30d5
permissions -rw-r--r--
6748601: javadoc API should allow varargs use Reviewed-by: bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javadoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Kinds;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.Scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.Symbol.VarSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.code.Symbol.ClassSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.code.Symbol.MethodSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.Name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.util.ListBuffer;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
    38
import com.sun.tools.javac.util.Names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * The serialized form is the specification of a class' serialization
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * state. <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * It consists of the following information:<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * 1. Whether class is Serializable or Externalizable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * 2. Javadoc for serialization methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *    a. For Serializable, the optional readObject, writeObject,
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *       readResolve and writeReplace.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *       serialData tag describes, in prose, the sequence and type
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *       of optional data written by writeObject.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *    b. For Externalizable, writeExternal and readExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *       serialData tag describes, in prose, the sequence and type
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *       of optional data written by writeExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * 3. Javadoc for serialization data layout.
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *    a. For Serializable, the name,type and description
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *       of each Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *    b. For Externalizable, data layout is described by 2(b).
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * @since 1.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * @author Joe Fialli
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 * @author Neal Gafter (rewrite but not too proud)
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
class SerializedForm {
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    ListBuffer<MethodDoc> methods = new ListBuffer<MethodDoc>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /* List of FieldDocImpl - Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * Singleton list if class defines Serializable fields explicitly.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * Otherwise, list of default serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * 0 length list for Externalizable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private final ListBuffer<FieldDocImpl> fields = new ListBuffer<FieldDocImpl>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    /* True if class specifies serializable fields explicitly.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * using special static member, serialPersistentFields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    private boolean definesSerializableFields = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    // Specially treated field/method names defined by Serialization.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    private static final String SERIALIZABLE_FIELDS = "serialPersistentFields";
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private static final String READOBJECT  = "readObject";
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    private static final String WRITEOBJECT = "writeObject";
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    private static final String READRESOLVE  = "readResolve";
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private static final String WRITEREPLACE = "writeReplace";
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    private static final String READOBJECTNODATA = "readObjectNoData";
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Catalog Serializable fields for Serializable class.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * Catalog serialization methods for Serializable and
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * Externalizable classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    SerializedForm(DocEnv env, ClassSymbol def, ClassDocImpl cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        if (cd.isExternalizable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            /* look up required public accessible methods,
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
             *   writeExternal and readExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
            String[] readExternalParamArr = { "java.io.ObjectInput" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            String[] writeExternalParamArr = { "java.io.ObjectOutput" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            MethodDoc md = cd.findMethod("readExternal", readExternalParamArr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
            if (md != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                methods.append(md);
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
            md = cd.findMethod("writeExternal", writeExternalParamArr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            if (md != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                methods.append(md);
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
                Tag tag[] = md.tags("serialData");
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        // } else { // isSerializable() //### ???
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        } else if (cd.isSerializable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            VarSymbol dsf = getDefinedSerializableFields(def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            if (dsf != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                /* Define serializable fields with array of ObjectStreamField.
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                 * Each ObjectStreamField should be documented by a
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                 * serialField tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                definesSerializableFields = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                //### No modifier filtering applied here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                FieldDocImpl dsfDoc = env.getFieldDoc(dsf);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                fields.append(dsfDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                mapSerialFieldTagImplsToFieldDocImpls(dsfDoc, env, def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                /* Calculate default Serializable fields as all
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                 * non-transient, non-static fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                 * Fields should be documented by serial tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                computeDefaultSerializableFields(env, def, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
           /* Check for optional customized readObject, writeObject,
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            * readResolve and writeReplace, which can all contain
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            * the serialData tag.        */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
            addMethodIfExist(env, def, READOBJECT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            addMethodIfExist(env, def, WRITEOBJECT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            addMethodIfExist(env, def, READRESOLVE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            addMethodIfExist(env, def, WRITEREPLACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            addMethodIfExist(env, def, READOBJECTNODATA);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * Check for explicit Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * Check for a private static array of ObjectStreamField with
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * name SERIALIZABLE_FIELDS.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
   153
        Names names = def.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        /* SERIALIZABLE_FIELDS can be private,
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
         * so must lookup by ClassSymbol, not by ClassDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            if (e.sym.kind == Kinds.VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                VarSymbol f = (VarSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                if ((f.flags() & Flags.STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                    (f.flags() & Flags.PRIVATE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                    return f;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * Compute default Serializable fields from all members of ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * Since the fields of ClassDocImpl might not contain private or
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * package accessible fields, must walk over all members of ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    private void computeDefaultSerializableFields(DocEnv env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                                                  ClassSymbol def,
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                                                  ClassDocImpl cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        for (Scope.Entry e = def.members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            if (e.sym != null && e.sym.kind == Kinds.VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                VarSymbol f = (VarSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                if ((f.flags() & Flags.STATIC) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                    (f.flags() & Flags.TRANSIENT) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                    //### No modifier filtering applied here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                    FieldDocImpl fd = env.getFieldDoc(f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                    //### Add to beginning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                    //### Preserve order used by old 'javadoc'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                    fields.prepend(fd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Catalog Serializable method if it exists in current ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * Do not look for method in superclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     * Serialization requires these methods to be non-static.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * @param method should be an unqualified Serializable method
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *               name either READOBJECT, WRITEOBJECT, READRESOLVE
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *               or WRITEREPLACE.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @param visibility the visibility flag for the given method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
   206
        Names names = def.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        for (Scope.Entry e = def.members().lookup(names.fromString(methodName)); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            if (e.sym.kind == Kinds.MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                MethodSymbol md = (MethodSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                if ((md.flags() & Flags.STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                     * WARNING: not robust if unqualifiedMethodName is overloaded
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                     *          method. Signature checking could make more robust.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                     * READOBJECT takes a single parameter, java.io.ObjectInputStream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                     * WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    methods.append(env.getMethodDoc(md));
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * Associate serialField tag fieldName with FieldDocImpl member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * Note: A serialField tag does not have to map an existing field
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *       of a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    private void mapSerialFieldTagImplsToFieldDocImpls(FieldDocImpl spfDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                                                       DocEnv env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                                                       ClassSymbol def) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
   232
        Names names = def.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        SerialFieldTag[] sfTag = spfDoc.serialFieldTags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        for (int i = 0; i < sfTag.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            Name fieldName = names.fromString(sfTag[i].fieldName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            // Look for a FieldDocImpl that is documented by serialFieldTagImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            for (Scope.Entry e = def.members().lookup(fieldName); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                if (e.sym.kind == Kinds.VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                    VarSymbol f = (VarSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                    FieldDocImpl fdi = env.getFieldDoc(f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                    ((SerialFieldTagImpl)(sfTag[i])).mapToFieldDocImpl(fdi);
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * Return serializable fields in class. <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * Returns either a list of default fields documented by serial tag comment or
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     *         javadoc comment<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * Or Returns a single FieldDocImpl for serialPersistentField. There is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     *         serialField tag for each serializable field.<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * @return an array of FieldDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     *         fields in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    FieldDoc[] fields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        return (FieldDoc[])fields.toArray(new FieldDocImpl[fields.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * Return serialization methods in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @return an array of MethodDocImpl for serialization methods in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    MethodDoc[] methods() {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   271
        return methods.toArray(new MethodDoc[methods.length()]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * Returns true if Serializable fields are defined explicitly using
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * member, serialPersistentFields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * @see #fields()
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    boolean definesSerializableFields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        return definesSerializableFields;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
}