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