jdk/src/share/classes/sun/tools/java/MethodSet.java
author ntoda
Thu, 31 Jul 2014 17:01:24 -0700
changeset 25799 1afc4675dc75
parent 24969 afa6934dd8e8
permissions -rw-r--r--
8044867: Fix raw and unchecked lint warnings in sun.tools.* Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.java;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The MethodSet structure is used to store methods for a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * It maintains the invariant that it never stores two methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * with the same signature.  MethodSets are able to lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * all methods with a given name and the unique method with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * signature (name, args).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
class MethodSet {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * A Map containing Lists of MemberDefinitions.  The Lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * contain methods which share the same name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
    49
    private final Map<Identifier,List<MemberDefinition>> lookupMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * The number of methods stored in the MethodSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Is this MethodSet currently frozen?  See freeze() for more details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private boolean frozen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Creates a brand new MethodSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public MethodSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        frozen = false;
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
    66
        lookupMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns the number of distinct methods stored in the MethodSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Adds `method' to the MethodSet.  No method of the same signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * should be already defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void add(MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // Check for late additions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if (frozen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                throw new CompilerError("add()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // todo: Check for method??
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            Identifier name = method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            // Get a List containing all methods of this name.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
    92
            List<MemberDefinition> methodList = lookupMap.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (methodList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                // There is no method with this name already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                // Create a List, and insert it into the hash.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
    97
                methodList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                lookupMap.put(name, methodList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            // Make sure that no method with the same signature has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            // been added to the MethodSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            int size = methodList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            for (int i = 0; i < size; i++) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   105
                if ((methodList.get(i))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    .getType().equalArguments(method.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    throw new CompilerError("duplicate addition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // We add the method to the appropriate list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            methodList.add(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Adds `method' to the MethodSet, replacing any previous definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * with the same signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void replace(MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            // Check for late additions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (frozen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                throw new CompilerError("replace()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            // todo: Check for method??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            Identifier name = method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            // Get a List containing all methods of this name.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   131
            List<MemberDefinition> methodList = lookupMap.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (methodList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                // There is no method with this name already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                // Create a List, and insert it into the hash.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   136
                methodList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                lookupMap.put(name, methodList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // Replace the element which has the same signature as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // `method'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            int size = methodList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            for (int i = 0; i < size; i++) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   144
                if ((methodList.get(i))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    .getType().equalArguments(method.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    methodList.set(i, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            // We add the method to the appropriate list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            methodList.add(method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * If the MethodSet contains a method with the same signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * then lookup() returns it.  Otherwise, this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public MemberDefinition lookupSig(Identifier name, Type type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // Go through all methods of the same name and see if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // have the right signature.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   163
        Iterator<MemberDefinition> matches = lookupName(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        MemberDefinition candidate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        while (matches.hasNext()) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   167
            candidate = matches.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (candidate.getType().equalArguments(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return candidate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // No match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Returns an Iterator of all methods contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * MethodSet which have a given name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   181
    public Iterator<MemberDefinition> lookupName(Identifier name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Find the List containing all methods of this name, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        // return that List's Iterator.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   184
        List<MemberDefinition> methodList = lookupMap.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (methodList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // If there is no method of this name, return a bogus, empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            // Iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return Collections.emptyIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return methodList.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns an Iterator of all methods in the MethodSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   196
    public Iterator<MemberDefinition> iterator() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        //----------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // The inner class MethodIterator is used to create our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // Iterator of all methods in the MethodSet.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   201
        class MethodIterator implements Iterator<MemberDefinition> {
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   202
            Iterator<List<MemberDefinition>> hashIter = lookupMap.values().iterator();
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   203
            Iterator<MemberDefinition> listIter = Collections.emptyIterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                if (listIter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    if (hashIter.hasNext()) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   210
                        listIter = hashIter.next().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        // The following should be always true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        if (listIter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                CompilerError("iterator() in MethodSet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                // We've run out of Lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   226
            public MemberDefinition next() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                return listIter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // end MethodIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        //----------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // A one-liner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return new MethodIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * After freeze() is called, the MethodSet becomes (mostly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * immutable.  Any calls to add() or addMeet() lead to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * CompilerErrors.  Note that the entries themselves are still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * (unfortunately) open for mischievous and wanton modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void freeze() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        frozen = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Tells whether freeze() has been called on this MethodSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public boolean isFrozen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return frozen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returns a (big) string representation of this MethodSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        int len = size();
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   263
        StringBuilder sb = new StringBuilder();
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   264
        Iterator<MemberDefinition> all = iterator();
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   265
        sb.append("{");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        while (all.hasNext()) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   268
            sb.append(all.next().toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            len--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (len > 0) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   271
                sb.append(", ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   274
        sb.append("}");
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 5506
diff changeset
   275
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
}