langtools/src/share/classes/com/sun/tools/javadoc/SerializedForm.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22159 682da512ec17
child 25443 9187d77f2c64
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
     2
 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
10
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1264
diff changeset
    23
 * questions.
10
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
import com.sun.tools.javac.code.Flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Kinds;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.Symbol.ClassSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.Symbol.MethodSymbol;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    34
import com.sun.tools.javac.code.Symbol.VarSymbol;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 5520
diff changeset
    35
import com.sun.tools.javac.util.ListBuffer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.Name;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
    37
import com.sun.tools.javac.util.Names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * The serialized form is the specification of a class' serialization
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * state. <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * It consists of the following information:<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * 1. Whether class is Serializable or Externalizable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * 2. Javadoc for serialization methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *    a. For Serializable, the optional readObject, writeObject,
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *       readResolve and writeReplace.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *       serialData tag describes, in prose, the sequence and type
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *       of optional data written by writeObject.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *    b. For Externalizable, writeExternal and readExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *       serialData tag describes, in prose, the sequence and type
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *       of optional data written by writeExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * 3. Javadoc for serialization data layout.
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *    a. For Serializable, the name,type and description
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *       of each Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *    b. For Externalizable, data layout is described by 2(b).
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    61
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    62
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    63
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    64
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    65
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * @since 1.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * @author Joe Fialli
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * @author Neal Gafter (rewrite but not too proud)
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
class SerializedForm {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    71
    ListBuffer<MethodDoc> methods = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    /* List of FieldDocImpl - Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * Singleton list if class defines Serializable fields explicitly.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * Otherwise, list of default serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * 0 length list for Externalizable.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    78
    private final ListBuffer<FieldDocImpl> fields = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /* True if class specifies serializable fields explicitly.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * using special static member, serialPersistentFields.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private boolean definesSerializableFields = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    // Specially treated field/method names defined by Serialization.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    private static final String SERIALIZABLE_FIELDS = "serialPersistentFields";
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    private static final String READOBJECT  = "readObject";
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    private static final String WRITEOBJECT = "writeObject";
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    private static final String READRESOLVE  = "readResolve";
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    private static final String WRITEREPLACE = "writeReplace";
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    private static final String READOBJECTNODATA = "readObjectNoData";
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * Constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * Catalog Serializable fields for Serializable class.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * Catalog serialization methods for Serializable and
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * Externalizable classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    SerializedForm(DocEnv env, ClassSymbol def, ClassDocImpl cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        if (cd.isExternalizable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
            /* look up required public accessible methods,
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
             *   writeExternal and readExternal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
            String[] readExternalParamArr = { "java.io.ObjectInput" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            String[] writeExternalParamArr = { "java.io.ObjectOutput" };
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
            MethodDoc md = cd.findMethod("readExternal", readExternalParamArr);
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
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            md = cd.findMethod("writeExternal", writeExternalParamArr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            if (md != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
                methods.append(md);
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                Tag tag[] = md.tags("serialData");
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        // } else { // isSerializable() //### ???
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        } else if (cd.isSerializable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            VarSymbol dsf = getDefinedSerializableFields(def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            if (dsf != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                /* Define serializable fields with array of ObjectStreamField.
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                 * Each ObjectStreamField should be documented by a
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                 * serialField tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                definesSerializableFields = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                //### No modifier filtering applied here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                FieldDocImpl dsfDoc = env.getFieldDoc(dsf);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                fields.append(dsfDoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                mapSerialFieldTagImplsToFieldDocImpls(dsfDoc, env, def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                /* Calculate default Serializable fields as all
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
                 * non-transient, non-static fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
                 * Fields should be documented by serial tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
                 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                computeDefaultSerializableFields(env, def, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
           /* Check for optional customized readObject, writeObject,
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            * readResolve and writeReplace, which can all contain
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            * the serialData tag.        */
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            addMethodIfExist(env, def, READOBJECT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            addMethodIfExist(env, def, WRITEOBJECT);
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            addMethodIfExist(env, def, READRESOLVE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
            addMethodIfExist(env, def, WRITEREPLACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
            addMethodIfExist(env, def, READOBJECTNODATA);
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * Check for explicit Serializable fields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * Check for a private static array of ObjectStreamField with
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * name SERIALIZABLE_FIELDS.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    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
   157
        Names names = def.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        /* SERIALIZABLE_FIELDS can be private,
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
         * so must lookup by ClassSymbol, not by ClassDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            if (e.sym.kind == Kinds.VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                VarSymbol f = (VarSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                if ((f.flags() & Flags.STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                    (f.flags() & Flags.PRIVATE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                    return f;
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
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * Compute default Serializable fields from all members of ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * Since the fields of ClassDocImpl might not contain private or
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * package accessible fields, must walk over all members of ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    private void computeDefaultSerializableFields(DocEnv env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
                                                  ClassSymbol def,
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
                                                  ClassDocImpl cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        for (Scope.Entry e = def.members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            if (e.sym != null && e.sym.kind == Kinds.VAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                VarSymbol f = (VarSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                if ((f.flags() & Flags.STATIC) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                    (f.flags() & Flags.TRANSIENT) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
                    //### No modifier filtering applied here.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                    FieldDocImpl fd = env.getFieldDoc(f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
                    //### Add to beginning.
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                    //### Preserve order used by old 'javadoc'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                    fields.prepend(fd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * Catalog Serializable method if it exists in current ClassSymbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     * Do not look for method in superclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * Serialization requires these methods to be non-static.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * @param method should be an unqualified Serializable method
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     *               name either READOBJECT, WRITEOBJECT, READRESOLVE
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     *               or WRITEREPLACE.
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * @param visibility the visibility flag for the given method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    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
   210
        Names names = def.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        for (Scope.Entry e = def.members().lookup(names.fromString(methodName)); e.scope != null; e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            if (e.sym.kind == Kinds.MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                MethodSymbol md = (MethodSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                if ((md.flags() & Flags.STATIC) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                     * WARNING: not robust if unqualifiedMethodName is overloaded
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                     *          method. Signature checking could make more robust.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                     * READOBJECT takes a single parameter, java.io.ObjectInputStream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                     * WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                    methods.append(env.getMethodDoc(md));
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * Associate serialField tag fieldName with FieldDocImpl member.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * Note: A serialField tag does not have to map an existing field
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     *       of a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    private void mapSerialFieldTagImplsToFieldDocImpls(FieldDocImpl spfDoc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                                                       DocEnv env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                                                       ClassSymbol def) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 868
diff changeset
   236
        Names names = def.name.table.names;
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   237
        for (SerialFieldTag tag : spfDoc.serialFieldTags()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   238
            if (tag.fieldName() == null || tag.fieldType() == null) // ignore malformed @serialField tags
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   239
                continue;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
   240
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   241
            Name fieldName = names.fromString(tag.fieldName());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            // Look for a FieldDocImpl that is documented by serialFieldTagImpl.
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   244
            for (Scope.Entry e = def.members().lookup(fieldName);
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   245
                 e.scope != null; e = e.next()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                if (e.sym.kind == Kinds.VAR) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   247
                    VarSymbol f = (VarSymbol) e.sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                    FieldDocImpl fdi = env.getFieldDoc(f);
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14357
diff changeset
   249
                    ((SerialFieldTagImpl) (tag)).mapToFieldDocImpl(fdi);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     * Return serializable fields in class. <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * Returns either a list of default fields documented by serial tag comment or
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     *         javadoc comment<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * Or Returns a single FieldDocImpl for serialPersistentField. There is a
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     *         serialField tag for each serializable field.<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * @return an array of FieldDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     *         fields in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    FieldDoc[] fields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        return (FieldDoc[])fields.toArray(new FieldDocImpl[fields.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * Return serialization methods in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * @return an array of MethodDocImpl for serialization methods in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    MethodDoc[] methods() {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   277
        return methods.toArray(new MethodDoc[methods.length()]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * Returns true if Serializable fields are defined explicitly using
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * member, serialPersistentFields.
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * @see #fields()
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    boolean definesSerializableFields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        return definesSerializableFields;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
}