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