jdk/src/share/classes/sun/tools/java/MemberDefinition.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18137
diff changeset
     2
 * Copyright (c) 1994, 2013, 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 sun.tools.tree.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.tools.tree.Vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.tools.tree.Expression;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.tools.tree.Statement;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.tools.tree.Context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.tools.asm.Assembler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This class defines a member of a Java class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * a variable, a method, or an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
class MemberDefinition implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected long where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected int modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected String documentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected IdentifierToken expIds[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected ClassDeclaration exp[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected Node value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected ClassDefinition clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected Identifier name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected ClassDefinition innerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected MemberDefinition nextMember;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected MemberDefinition nextMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected MemberDefinition accessPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected boolean superAccessMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public MemberDefinition(long where, ClassDefinition clazz, int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                            Type type, Identifier name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                            IdentifierToken expIds[], Node value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (expIds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            expIds = new IdentifierToken[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.where = where;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.expIds = expIds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Constructor for an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Inner classes are represented as fields right along with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * variables and methods for simplicity of data structure,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * and to reflect properly the textual declaration order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * This constructor calls the generic constructor for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * class, extracting all necessary values from the innerClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public MemberDefinition(ClassDefinition innerClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        this(innerClass.getWhere(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
             innerClass.getOuterClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
             innerClass.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
             innerClass.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
             innerClass.getName().getFlatName().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
             null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.innerClass = innerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * A cache of previously created proxy members.  Used to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * uniqueness of proxy objects.  See the makeProxyMember method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * defined below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   106
    static private Map<String,MemberDefinition> proxyCache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Create a member which is externally the same as `field' but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * is defined in class `classDef'.  This is used by code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * in sun.tools.tree.(MethodExpression,FieldExpression) as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * part of the fix for bug 4135692.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Proxy members should not be added, ala addMember(), to classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * They are merely "stand-ins" to produce modified MethodRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * constant pool entries during code generation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * We keep a cache of previously created proxy members not to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * save time or space, but to ensure uniqueness of the proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * member for any (field,classDef) pair.  If these are not made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * unique then we can end up generating duplicate MethodRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * constant pool entries during code generation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static MemberDefinition makeProxyMember(MemberDefinition field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                                   ClassDefinition classDef,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                                   Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (proxyCache == null) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   129
            proxyCache = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        String key = field.toString() + "@" + classDef.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // System.out.println("Key is : " + key);
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   134
        MemberDefinition proxy = proxyCache.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (proxy != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        proxy = new MemberDefinition(field.getWhere(), classDef,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                     field.getModifiers(), field.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                     field.getName(), field.getExceptionIds(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        proxy.exp = field.getExceptions(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        proxyCache.put(key, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Get the position in the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public final long getWhere() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return where;
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
     * Get the class declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public final ClassDeclaration getClassDeclaration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return clazz.getClassDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * A stub.  Subclasses can do more checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void resolveTypeStructure(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Get the class declaration in which the field is actually defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public ClassDeclaration getDefiningClassDeclaration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return getClassDeclaration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Get the class definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public final ClassDefinition getClassDefinition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Get the field's top-level enclosing class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public final ClassDefinition getTopClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return clazz.getTopClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Get the field's modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public final int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public final void subModifiers(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        modifiers &= ~mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public final void addModifiers(int mod) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        modifiers |= mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Get the field's type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public final Type getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Get the field's name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public final Identifier getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Get arguments (a vector of LocalMember)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   220
    public Vector<MemberDefinition> getArguments() {
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 24969
diff changeset
   221
        return isMethod() ? new Vector<>() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Get the exceptions that are thrown by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public ClassDeclaration[] getExceptions(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (expIds != null && exp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (expIds.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                exp = new ClassDeclaration[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                // we should have translated this already!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                throw new CompilerError("getExceptions "+this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return exp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public final IdentifierToken[] getExceptionIds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return expIds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Get an inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public ClassDefinition getInnerClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return innerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Is this a synthetic field which holds a copy of,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * or reference to, a local variable or enclosing instance?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public boolean isUplevelValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (!isSynthetic() || !isVariable() || isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        String name = this.name.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return name.startsWith(prefixVal)
18137
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 5506
diff changeset
   259
            || name.startsWith(prefixLoc)
264000e285e9 8015470: Remove redundant calls of toString() on String objects
dholmes
parents: 5506
diff changeset
   260
            || name.startsWith(prefixThis);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public boolean isAccessMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // This no longer works, because access methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // for constructors do not use the standard naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // scheme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        //    return isSynthetic() && isMethod()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        //        && name.toString().startsWith(prefixAccess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Assume that a method is an access method if it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // an access peer.  NOTE: An access method will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // recognized as such until 'setAccessMethodTarget' has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // been called on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return isSynthetic() && isMethod() && (accessPeer != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Is this a synthetic method which provides access to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * visible private member?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public MemberDefinition getAccessMethodTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (isAccessMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            for (MemberDefinition f = accessPeer; f != null; f = f.accessPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                // perhaps skip over another access for the same field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if (!f.isAccessMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void setAccessMethodTarget(MemberDefinition target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (getAccessMethodTarget() != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            /*-------------------*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (!isAccessMethod() || accessPeer != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    target.accessPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                throw new CompilerError("accessPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            *-------------------*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (accessPeer != null || target.accessPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                throw new CompilerError("accessPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            accessPeer = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * If this method is a getter for a private field, return the setter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public MemberDefinition getAccessUpdateMember() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (isAccessMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            for (MemberDefinition f = accessPeer; f != null; f = f.accessPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                if (f.isAccessMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void setAccessUpdateMember(MemberDefinition updater) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (getAccessUpdateMember() != updater) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (!isAccessMethod() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    updater.getAccessMethodTarget() != getAccessMethodTarget()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                throw new CompilerError("accessPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            updater.accessPeer = accessPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            accessPeer = updater;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Is this an access method for a field selection or method call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * of the form '...super.foo' or '...super.foo()'?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public final boolean isSuperAccessMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return superAccessMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Mark this member as an access method for a field selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * or method call via the 'super' keyword.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public final void setIsSuperAccessMethod(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        superAccessMethod = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Tell if this is a final variable without an initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Such variables are subject to definite single assignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public final boolean isBlankFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return isFinal() && !isSynthetic() && getValue() == null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public boolean isNeverNull() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (isUplevelValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            // loc$x and this$C are never null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return !name.toString().startsWith(prefixVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * Get the field's final value (may return null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public Node getValue(Environment env) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public final Node getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public final void setValue(Node value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public Object getInitialValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Get the next field or the next match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public final MemberDefinition getNextMember() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return nextMember;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public final MemberDefinition getNextMatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return nextMatch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Get the field's documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public String getDocumentation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return documentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Request a check of the field definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public void check(Environment env) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Really check the field definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public Vset check(Environment env, Context ctx, Vset vset) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Generate code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public void code(Environment env, Assembler asm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        throw new CompilerError("code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public void codeInit(Environment env, Context ctx, Assembler asm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        throw new CompilerError("codeInit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Tells whether to report a deprecation error for this field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public boolean reportDeprecated(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return (isDeprecated() || clazz.reportDeprecated(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Check if a field can reach another field (only considers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * forward references, not the access modifiers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public final boolean canReach(Environment env, MemberDefinition f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (f.isLocal() || !f.isVariable() || !(isVariable() || isInitializer()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if ((getClassDeclaration().equals(f.getClassDeclaration())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            (isStatic() == f.isStatic())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // They are located in the same class, and are either both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // static or both non-static.  Check the initialization order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            while (((f = f.getNextMember()) != null) && (f != this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return f != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    //-----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    // The code in this section is intended to test certain kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // compatibility between methods.  There are two kinds of compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // that the compiler may need to test.  The first is whether one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // method can legally override another.  The second is whether two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    // method definitions can legally coexist.  We use the word `meet'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // to mean the intersection of two legally coexisting methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    // For more information on these kinds of compatibility, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    // comments/code for checkOverride() and checkMeet() below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Constants used by getAccessLevel() to represent the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * modifiers as numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    static final int PUBLIC_ACCESS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    static final int PROTECTED_ACCESS = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    static final int PACKAGE_ACCESS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    static final int PRIVATE_ACCESS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Return the access modifier of this member as a number.  The idea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * is that this number may be used to check properties like "the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * access modifier of x is more restrictive than the access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * modifier of y" with a simple inequality test:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * "x.getAccessLevel() > y.getAccessLevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * This is an internal utility method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private int getAccessLevel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // Could just compute this once instead of recomputing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // Check to see if this is worth it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (isPublic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return PUBLIC_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        } else if (isProtected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return PROTECTED_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        } else if (isPackagePrivate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return PACKAGE_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        } else if (isPrivate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            return PRIVATE_ACCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            throw new CompilerError("getAccessLevel()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Munge our error message to report whether the override conflict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * came from an inherited method or a declared method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private void reportError(Environment env, String errorString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                             ClassDeclaration clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                             MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            // For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            // "Instance method BLAH inherited from CLASSBLAH1 cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            //  overridden by the static method declared in CLASSBLAH2."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            env.error(getWhere(), errorString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                      this, getClassDeclaration(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                      method.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            // For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            // "In CLASSBLAH1, instance method BLAH inherited from CLASSBLAH2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            //  cannot be overridden by the static method inherited from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            //  CLASSBLAH3."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            env.error(clazz.getClassDefinition().getWhere(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                      //"inherit." + errorString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                      errorString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                      //clazz,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                      this, getClassDeclaration(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                      method.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Convenience method to see if two methods return the same type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public boolean sameReturnType(MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        // Make sure both are methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (!isMethod() || !method.isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            throw new CompilerError("sameReturnType: not method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        Type myReturnType = getType().getReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        Type yourReturnType = method.getType().getReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return (myReturnType == yourReturnType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Check to see if `this' can override/hide `method'.  Caller is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * responsible for verifying that `method' has the same signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * as `this'.  Caller is also responsible for verifying that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * `method' is visible to the class where this override is occurring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * This method is called for the case when class B extends A and both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * A and B define some method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *       A - void foo() throws e1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *       |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *       |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *       B - void foo() throws e2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public boolean checkOverride(Environment env, MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return checkOverride(env, method, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Checks whether `this' can override `method'.  It `clazz' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * null, it reports the errors in the class where `this' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * declared.  If `clazz' is not null, it reports the error in `clazz'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private boolean checkOverride(Environment env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                  MemberDefinition method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                  ClassDeclaration clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        // This section of code is largely based on section 8.4.6.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // of the JLS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        boolean success = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        // Sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (!isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            throw new CompilerError("checkOverride(), expected method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // Suppress checks for synthetic methods, as the compiler presumably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // knows what it is doing, e.g., access methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (isSynthetic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            // Sanity check: We generally do not intend for one synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            // method to override another, though hiding of static members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // is expected.  This check may need to be changed if new uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            // of synthetic methods are devised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            // Query: this code was copied from elsewhere.  What
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            // exactly is the role of the !isStatic() in the test?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            if (method.isFinal() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                (!method.isConstructor() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                 !method.isStatic() && !isStatic())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                // NMG 2003-01-28 removed the following test because it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                // invalidated by bridge methods inserted by the "generic"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                // (1.5) Java compiler.  In 1.5, this code is used,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                // indirectly, by rmic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                // throw new CompilerError("checkOverride() synthetic");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            // We trust the compiler.  (Ha!)  We're done checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // Our caller should have verified that the method had the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // same signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (getName() != method.getName() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            !getType().equalArguments(method.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw new CompilerError("checkOverride(), signature mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        // It is forbidden to `override' a static method with an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        // method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (method.isStatic() && !isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            reportError(env, "override.static.with.instance", clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        // It is forbidden to `hide' an instance method with a static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        // method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (!method.isStatic() && isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            reportError(env, "hide.instance.with.static", clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // We cannot override a final method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        if (method.isFinal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            reportError(env, "override.final.method", clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        // Give a warning when we override a deprecated method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // a non-deprecated one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // We bend over backwards to suppress this warning if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        // the `method' has not been already compiled or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // `this' has been already compiled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (method.reportDeprecated(env) && !isDeprecated()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
               && this instanceof sun.tools.javac.SourceMember) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            reportError(env, "warn.override.is.deprecated",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // Visibility may not be more restrictive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (getAccessLevel() > method.getAccessLevel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            reportError(env, "override.more.restrictive", clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        // Return type equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (!sameReturnType(method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // PCJ 2003-07-30 removed the following error because it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            // invalidated by the covariant return type feature of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            // 1.5 compiler.  The resulting check is now much looser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            // than the actual 1.5 language spec, but that should be OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            // because this code is only still used by rmic.  See 4892308.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            // reportError(env, "override.different.return", clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            // success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            ////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // Exception agreeement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (!exceptionsFit(env, method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            reportError(env, "override.incompatible.exceptions",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                        clazz, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            success = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Check to see if two method definitions are compatible, that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * do they have a `meet'.  The meet of two methods is essentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * and `intersection' of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * two methods.  This method is called when some class C inherits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * declarations for some method foo from two parents (superclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * interfaces) but it does not, itself, have a declaration of foo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Caller is responsible for making sure that both methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * indeed visible in clazz.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *     A - void foo() throws e1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *       \     B void foo() throws e2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *        \   /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *         \ /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *          C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public boolean checkMeet(Environment env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                             MemberDefinition method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                             ClassDeclaration clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // This section of code is largely based on Section 8.4.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // and 9.4.1 of the JLS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // Sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (!isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            throw new CompilerError("checkMeet(), expected method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        // Check for both non-abstract.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (!isAbstract() && !method.isAbstract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            throw new CompilerError("checkMeet(), no abstract method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // If either method is non-abstract, then we need to check that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // the abstract method can be properly overridden.  We call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        // the checkOverride method to check this and generate any errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // This test must follow the previous test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        else if (!isAbstract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            return checkOverride(env, method, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        } else if (!method.isAbstract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            return method.checkOverride(env, this, clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        // Both methods are abstract.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // Our caller should have verified that the method has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        // same signature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (getName() != method.getName() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            !getType().equalArguments(method.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            throw new CompilerError("checkMeet(), signature mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        // Check for return type equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (!sameReturnType(method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            // More args?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            env.error(clazz.getClassDefinition().getWhere(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                      "meet.different.return",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                      this, this.getClassDeclaration(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                      method.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        // We don't have to check visibility -- there always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        // potentially exists a meet.  Similarly with exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        // There does exist a meet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * This method is meant to be used to determine if one of two inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * methods could override the other.  Unlike checkOverride(), failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * is not an error.  This method is only meant to be called after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * checkMeet() has succeeded on the two methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * If you call couldOverride() without doing a checkMeet() first, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * you are on your own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public boolean couldOverride(Environment env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                 MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        // Sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        if (!isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            throw new CompilerError("coulcOverride(), expected method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        // couldOverride() is only called with `this' and `method' both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        // being inherited methods.  Neither of them is defined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        // class which we are currently working on.  Even though an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        // abstract method defined *in* a class can override a non-abstract
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        // method defined in a superclass, an abstract method inherited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        // from an interface *never* can override a non-abstract method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        // This comment may sound odd, but that's the way inheritance is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        // The following check makes sure we aren't trying to override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        // an inherited non-abstract definition with an abstract definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        // from an interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        if (!method.isAbstract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        // Visibility should be less restrictive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        if (getAccessLevel() > method.getAccessLevel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        // Exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (!exceptionsFit(env, method)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        // Potentially some deprecation warnings could be given here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        // when we merge two abstract methods, one of which is deprecated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        // This is not currently reported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Check to see if the exceptions of `this' fit within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * exceptions of `method'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    private boolean exceptionsFit(Environment env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                  MemberDefinition method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        ClassDeclaration e1[] = getExceptions(env);        // my exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        ClassDeclaration e2[] = method.getExceptions(env); // parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        // This code is taken nearly verbatim from the old implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        // of checkOverride() in SourceClass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    outer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        for (int i = 0 ; i < e1.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                ClassDefinition c1 = e1[i].getClassDefinition(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                for (int j = 0 ; j < e2.length ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    if (c1.subClassOf(env, e2[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                        continue outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                if (c1.subClassOf(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                                  env.getClassDeclaration(idJavaLangError)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    continue outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                if (c1.subClassOf(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                  env.getClassDeclaration(idJavaLangRuntimeException)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    continue outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                // the throws was neither something declared by a parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                // nor one of the ignorables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                // We were unable to find one of the exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                env.error(getWhere(), "class.not.found",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                          ee.name, method.getClassDeclaration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        // All of the exceptions `fit'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    //-----------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    public final boolean isPublic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return (modifiers & M_PUBLIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public final boolean isPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        return (modifiers & M_PRIVATE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    public final boolean isProtected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return (modifiers & M_PROTECTED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public final boolean isPackagePrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        return (modifiers & (M_PUBLIC | M_PRIVATE | M_PROTECTED)) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    public final boolean isFinal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        return (modifiers & M_FINAL) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    public final boolean isStatic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return (modifiers & M_STATIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public final boolean isSynchronized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        return (modifiers & M_SYNCHRONIZED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public final boolean isAbstract() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return (modifiers & M_ABSTRACT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    public final boolean isNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        return (modifiers & M_NATIVE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    public final boolean isVolatile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        return (modifiers & M_VOLATILE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public final boolean isTransient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        return (modifiers & M_TRANSIENT) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public final boolean isMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        return type.isType(TC_METHOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public final boolean isVariable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return !type.isType(TC_METHOD) && innerClass == null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public final boolean isSynthetic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return (modifiers & M_SYNTHETIC) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    public final boolean isDeprecated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        return (modifiers & M_DEPRECATED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    public final boolean isStrict() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        return (modifiers & M_STRICTFP) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    public final boolean isInnerClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        return innerClass != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    public final boolean isInitializer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        return getName().equals(idClassInit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    public final boolean isConstructor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return getName().equals(idInit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    public boolean isLocal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public boolean isInlineable(Environment env, boolean fromFinal) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        return (isStatic() || isPrivate() || isFinal() || isConstructor() || fromFinal) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            !(isSynchronized() || isNative());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * Check if constant:  Will it inline away to a constant?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public boolean isConstant() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        if (isFinal() && isVariable() && value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                // If an infinite regress requeries this name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                // deny that it is a constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                modifiers &= ~M_FINAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                return ((Expression)value).isConstant();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                modifiers |= M_FINAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        Identifier name = getClassDefinition().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        if (isInitializer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            return isStatic() ? "static {}" : "instance {}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        } else if (isConstructor()) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   922
            StringBuilder sb = new StringBuilder();
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   923
            sb.append(name);
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   924
            sb.append('(');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            Type argTypes[] = getType().getArgumentTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            for (int i = 0 ; i < argTypes.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                if (i > 0) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   928
                    sb.append(',');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   930
                sb.append(argTypes[i].toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   932
            sb.append(')');
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   933
            return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        } else if (isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            return getInnerClass().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        return type.typeString(getName().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * Print for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    public void print(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (isPublic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            out.print("public ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        if (isPrivate()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            out.print("private ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        if (isProtected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            out.print("protected ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (isFinal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            out.print("final ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (isStatic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            out.print("static ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (isSynchronized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            out.print("synchronized ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        if (isAbstract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            out.print("abstract ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        if (isNative()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            out.print("native ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        if (isVolatile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            out.print("volatile ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        if (isTransient()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            out.print("transient ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        out.println(toString() + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    public void cleanup(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        documentation = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (isMethod() && value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            int cost = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            if (isPrivate() || isInitializer()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                value = Statement.empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            } else if ((cost =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                        ((Statement)value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                       .costInline(Statement.MAXINLINECOST, null, null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                                >= Statement.MAXINLINECOST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                // will never be inlined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                value = Statement.empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    if (!isInlineable(null, true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                        value = Statement.empty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                catch (ClassNotFound ee) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            if (value != Statement.empty && env.dump()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                env.output("[after cleanup of " + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                           cost + " expression cost units remain]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        } else if (isVariable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (isPrivate() || !isFinal() || type.isType(TC_ARRAY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
}