corba/src/share/classes/sun/rmi/rmic/iiop/CompoundType.java
author alanb
Mon, 10 Jun 2013 17:15:42 +0100
changeset 18302 3b06314efbd0
parent 5555 b2b5ed3f0d0d
child 22131 4d7b21463768
permissions -rw-r--r--
8016218: Warnings building corba repo due to missing hashCode methods Reviewed-by: chegar, coffeys, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
package sun.rmi.rmic.iiop;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
18302
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
    35
import java.util.Arrays;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import sun.tools.java.Identifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import sun.tools.java.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import sun.tools.java.ClassDeclaration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import sun.tools.java.MemberDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import sun.tools.tree.Node;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import sun.tools.tree.LocalMember;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import sun.tools.tree.CharExpression;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import sun.tools.tree.IntegerExpression;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import sun.rmi.rmic.IndentingWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.HashSet;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * A CompoundType is an abstract base class for all IIOP class and
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * interface types.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
public abstract class CompoundType extends Type {
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    protected Method[] methods;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    protected InterfaceType[] interfaces;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    protected Member[] members;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    protected ClassDefinition classDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    protected ClassDeclaration classDecl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
    protected boolean isCORBAObject = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    protected boolean isIDLEntity = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    protected boolean isAbstractBase = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    protected boolean isValueBase = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    protected boolean isCORBAUserException = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    protected boolean isException = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    protected boolean isCheckedException = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    protected boolean isRemoteExceptionOrSubclass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    protected String idlExceptionName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    protected String qualifiedIDLExceptionName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
     * Return true if this type implements
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
     * org.omg.CORBA.Object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    public boolean isCORBAObject () {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        return isCORBAObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
     * Return true if this type implements
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
     * org.omg.CORBA.portable.IDLEntity.
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    public boolean isIDLEntity () {
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        return isIDLEntity;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
     * Return true if this type implements
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
     * org.omg.CORBA.portable.ValueBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    public boolean isValueBase () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        return isValueBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
     * Return true if this type is a CORBA
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * abstract interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    public boolean isAbstractBase () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        return isAbstractBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
     * Return true if this type is an exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    public boolean isException () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        return isException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
     * Return true if this type is a "checked" exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
     * Result if valid iff isException() returns true.
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    public boolean isCheckedException () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        return isCheckedException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
     * Return true if this type is a java.rmi.RemoteException
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
     * or one of its subclasses. Result if valid iff isException()
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
     * returns true.
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    public boolean isRemoteExceptionOrSubclass () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        return isRemoteExceptionOrSubclass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
     * Return true if this type is exactly
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
     * org.omg.CORBA.UserException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    public boolean isCORBAUserException () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        return isCORBAUserException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
     * Return true if this type implements
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
     * isIDLEntity() && isException().
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    public boolean isIDLEntityException () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        return isIDLEntity() && isException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
     * Return true if isIDLEntity() && !isValueBase()
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
     * && !isAbstractBase() && !isCORBAObject()
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
     * && !isIDLEntityException().
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    public boolean isBoxed () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        return (isIDLEntity() && !isValueBase() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                !isAbstractBase() && !isCORBAObject() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
                !isIDLEntityException());
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * If this type represents an exception, return the
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * IDL name including the "Ex" mangling, otherwise
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     * return null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    public String getIDLExceptionName () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
        return idlExceptionName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     * If this type represents an exception, return the
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
     * qualified IDL name including the "Ex" mangling,
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
     * otherwise return null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
     * @param global If true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    public String getQualifiedIDLExceptionName (boolean global) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
        if (qualifiedIDLExceptionName != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
            global &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
            getIDLModuleNames().length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
            return IDL_NAME_SEPARATOR + qualifiedIDLExceptionName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
            return qualifiedIDLExceptionName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
     * Return signature for this type  (e.g. com.acme.Dynamite
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
     * would return "com.acme.Dynamite", byte = "B")
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    public String getSignature() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
        String sig = classDecl.getType().getTypeSignature();
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        if (sig.endsWith(";")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
            sig = sig.substring(0,sig.length()-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        return sig;
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * Return the ClassDeclaration for this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    public ClassDeclaration getClassDeclaration() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
        return classDecl;
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
     * Return the ClassDefinition for this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    public ClassDefinition getClassDefinition() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        return classDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
     * Return the parent class of this type. Returns null if this
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
     * type is an interface or if there is no parent.
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    public ClassType getSuperclass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
     * Return an array of interfaces directly implemented by this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
     * The order of the array returned is arbitrary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    public InterfaceType[] getInterfaces() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        if( interfaces != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
            return (InterfaceType[]) interfaces.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
     * Return an array of Type.Method objects representing all
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
     * of the methods implemented directly by this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    public Method[] getMethods() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        if( methods != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            return (Method[]) methods.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
     * Return an array of Type.Member objects representing all of
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
     * the data members directly implemented by this interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    public Member[] getMembers() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        if( members != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            return (Member[]) members.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
     * Create a CompoundType object for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
     * If the class is not a properly formed or if some other error occurs, the
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
     * return value will be null, and errors will have been reported to the
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
     * supplied BatchEnvironment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    public static CompoundType forCompound (ClassDefinition classDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                                            ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
        CompoundType result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            result = (CompoundType) makeType(classDef.getType(),classDef,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        } catch (ClassCastException e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    // Subclass/Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
     * Release all resources.
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
    protected void destroy () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        if (!destroyed) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            super.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
            if (methods != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
                for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                    if (methods[i] != null) methods[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
                methods = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
            if (interfaces != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
                for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
                    if (interfaces[i] != null) interfaces[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                interfaces = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
            if (members != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
                for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
                    if (members[i] != null) members[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
                members = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
            classDef = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
            classDecl = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
     * Load a Class instance. Return null if fail.
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    protected Class loadClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        Class ourClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        // To avoid getting out-of-date Class instances, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        // to ensure that there is an instance, we must compile
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        // any classes that we've seen and which are not yet
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
        // compiled. We can't just compile this class, 'cuz it
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        // may have dependencies on classes which have not been
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
        // compiled...
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
            env.getMain().compileAllClasses(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        } catch (Exception e1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
            for (Enumeration e = env.getClasses() ; e.hasMoreElements() ; ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
                ClassDeclaration c = (ClassDeclaration)e.nextElement();
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            failedConstraint(26,false,stack,"required classes");
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            env.flushErrors();
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
        // Now try to get the Class...
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
        // The outer try block is there for people who might want to use
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
        // the compiler at run-time of their AS.
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        // They could set and use their own context class loader for loading
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
        // classes directly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
            ourClass = cl.loadClass(getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        } catch(ClassNotFoundException cfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                ourClass = env.classPathLoader.loadClass(getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            } catch (NullPointerException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                // This should never happen
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
            } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                // Fall through to the next case (which is to look in the
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
                // output directory for generated files)
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
        /* This piece of code used to cause the compiler to ignore jar files
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
           on its classpath
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            ourClass = Util.loadClass(getQualifiedName(),null,null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        } catch (LinkageError e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        if (ourClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
            // Try one last thing. If the class was compiled into
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
            // a directory that's not in the classpath, the load
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
            // will fail. Let's get the bits off the disk and load
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
            // it directly...
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
            if (env.loader == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                File destDir = env.getMain().getDestinationDir();
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
                if (destDir == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
                    destDir = new File(".");
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
                env.loader = new DirectoryLoader(destDir);
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
                ourClass = env.loader.loadClass(getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
            } catch (Exception e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        return ourClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    // Print "extends XX"
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
    protected boolean printExtends (IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
                                    boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
                                    boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
                                    boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
        ClassType parent = getSuperclass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        if (parent != null && (!useIDLNames ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
                               (!parent.isType(TYPE_ANY) && !parent.isType(TYPE_CORBA_OBJECT)))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
            writer.p(" extends ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
            parent.printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
    // Print "implements XX, YY"
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
    protected void printImplements (IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
                                    String prefix,
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
                                    boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
                                    boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
                                    boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        InterfaceType[] interfaces = getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        String adjective = " implements";
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        if (isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
            adjective = " extends";
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
            adjective = ":";
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
            if (!useIDLNames || (!interfaces[i].isType(TYPE_ANY) && !interfaces[i].isType(TYPE_CORBA_OBJECT))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
                if (i == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
                    writer.p(prefix + adjective + " ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
                    writer.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
                interfaces[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
    // Print members
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
    protected void printMembers (       IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
                                        boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                                        boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
                                        boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        CompoundType.Member[] members = getMembers();
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
            if (!members[i].isInnerClassDeclaration()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
                Type it = members[i].getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
                String visibility = members[i].getVisibility();
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
                String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
                if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                    name = members[i].getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
                    name = members[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
                String value = members[i].getValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
                writer.p(visibility);
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                if (visibility.length() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
                    writer.p(" ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
                it.printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
                writer.p(" " + name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                if (value != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                    writer.pln(" = " + value + ";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
                    writer.pln(";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
    // Print methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    protected void printMethods (       IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
                                        boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
                                        boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
                                        boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        CompoundType.Method[] methods = getMethods();
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        for (int m = 0; m < methods.length; m++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
            CompoundType.Method theMethod = methods[m];
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
            printMethod(theMethod,writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
    // Print a method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
    protected void printMethod (CompoundType.Method it,
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
                                IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
                                boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
                                boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
                                boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
        // Write visibility...
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        String visibility = it.getVisibility();
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        writer.p(visibility);
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        if (visibility.length() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
            writer.p(" ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        // Write return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        it.getReturnType().printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        // Write method name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
            writer.p(" " + it.getIDLName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
            writer.p(" " + it.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        // Write arguments...
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        writer.p(" (");
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        Type[] args = it.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
        String[] argNames = it.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
            if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                writer.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
            if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                writer.p("in ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            args[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            writer.p(" " + argNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
        writer.p(")");
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
        // Write exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
        ClassType[] exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        if (isType(TYPE_IMPLEMENTATION)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
            exceptions = it.getImplExceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
            exceptions = it.getExceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
        for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
            if (i == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
                if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                    writer.p(" raises (");
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                    writer.p(" throws ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                writer.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
            if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
                if (useQualifiedNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
                    writer.p(exceptions[i].getQualifiedIDLExceptionName(globalIDLNames));
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
                    writer.p(exceptions[i].getIDLExceptionName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
                writer.p(" [a.k.a. ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
                exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
                writer.p("]");
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
                exceptions[i].printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
        if (useIDLNames && exceptions.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
            writer.p(")");
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
        if (it.isInherited()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
            writer.p(" // Inherited from ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
        writer.p(it.getDeclaredBy());
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
        writer.pln(";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
     * Create a CompoundType instance for the given class. NOTE: This constructor
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
     * is ONLY for SpecialClassType and SpecialInterfaceType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
    protected CompoundType(ContextStack stack, int typeCode, ClassDefinition classDef) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
        super(stack,typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
        this.classDef = classDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
        classDecl = classDef.getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
        interfaces = new InterfaceType[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
        methods = new Method[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
        members = new Member[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
        // If we are an inner class/interface, reset the type codes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
        if (classDef.isInnerClass()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
            setTypeCode(typeCode | TM_INNER);
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
        // Set special flags...
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
        setFlags();
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
    private void setFlags() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
        // Set our special interface flags...
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
            isCORBAObject = env.defCorbaObject.implementedBy(env,classDecl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            isIDLEntity = env.defIDLEntity.implementedBy(env,classDecl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
            isValueBase = env.defValueBase.implementedBy(env,classDecl);
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
            isAbstractBase = isInterface() &&   // Interface, not a class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
                             isIDLEntity &&     // Implements IDLEntity.
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
                             !isValueBase &&    // Does not implement ValueBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
                             !isCORBAObject;    // Does not implement org.omg.CORBA.Object;
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
            isCORBAUserException = (classDecl.getName() == idCorbaUserException);
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
            // Is this an exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
            if (env.defThrowable.implementedBy(env, classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
                // Yes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                isException = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                // Is it a checked exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                if (env.defRuntimeException.implementedBy(env,classDecl) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                    env.defError.implementedBy(env,classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                    isCheckedException = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                    isCheckedException = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
                // Is it java.rmi.RemoteException or a subclass?
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
                if (env.defRemoteException.implementedBy(env,classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
                    isRemoteExceptionOrSubclass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
                    isRemoteExceptionOrSubclass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
                isException = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
        } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
            classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
     * Create a CompoundType instance for the given class.  The resulting
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
     * object is not yet completely initialized.
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    protected CompoundType(ContextStack stack, ClassDefinition classDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                           int typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        super(stack,typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
        this.classDef = classDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        classDecl = classDef.getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        // If we are an inner class/interface, reset the type codes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        if (classDef.isInnerClass()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
            setTypeCode(typeCode | TM_INNER);
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        // Set special flags...
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        setFlags();
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
        // Set names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
        Identifier id = classDef.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
        String idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
        String[] idlModuleNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
            // These can fail if we get case-sensitive name matches...
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
            idlName = IDLNames.getClassOrInterfaceName(id,env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
            idlModuleNames = IDLNames.getModuleNames(id,isBoxed(),env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
            setNames(id,idlModuleNames,idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
            // Is this an exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
            if (isException()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
                // Yes, so set our mangled exception names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
                isException = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
                idlExceptionName = IDLNames.getExceptionName(getIDLName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
                qualifiedIDLExceptionName =
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
                    IDLNames.getQualifiedName(getIDLModuleNames(),idlExceptionName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            // Set interfaces, methods and members...
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
            interfaces = null;          // set in initialize()
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
            methods = null;                     // set in initialize()
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
            members = null;                 // set in initialize()
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
        } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
            failedConstraint(7,false,stack,id.toString(),e.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
            throw new CompilerError("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
     * Initialize this instance.
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
    protected boolean initialize (      Vector directInterfaces,
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
                                        Vector directMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
                                        Vector directMembers,
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
                                        ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
                                        boolean quiet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
        // Initialize our arrays...
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
        if (directInterfaces != null && directInterfaces.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            interfaces = new InterfaceType[directInterfaces.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
            directInterfaces.copyInto(interfaces);
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
            interfaces = new InterfaceType[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
        if (directMethods != null && directMethods.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
            methods = new Method[directMethods.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
            directMethods.copyInto(methods);
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
            // Now set the idl names for each...
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
                IDLNames.setMethodNames(this, methods,env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
            } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
                failedConstraint(13,quiet,stack,getQualifiedName(),e.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
            methods = new Method[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        if (directMembers != null && directMembers.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
            members = new Member[directMembers.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
            directMembers.copyInto(members);
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
            // If we have any un-initialized inner classes, now is the time
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
            // to init them...
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
            for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
                if (members[i].isInnerClassDeclaration()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
                        members[i].init(stack,this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
                    } catch (CompilerError e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
                        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
            // Now set the idl names for each...
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
                IDLNames.setMemberNames(this, members,methods,env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
            } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
                int constraint = classDef.isInterface() ? 19 : 20;
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
                failedConstraint(constraint,quiet,stack,getQualifiedName(),e.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
            members = new Member[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        // Set our repositoryID...
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        if (result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
            result = setRepositoryID();
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
     * Return Type or null if error. classDef may be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
    protected static Type makeType (sun.tools.java.Type theType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
                                    ClassDefinition classDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
                                    ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
        if (stack.anyErrors()) return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        // See if we can find this type in the cache.  If so, return it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        String key = theType.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        Type result = getType(key,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
        if (result != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
        // Gotta try with context...
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
        result = getType(key + stack.getContextCodeString(),stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
        if (result != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
        // Gotta map it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        BatchEnvironment env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
        int typeCode = theType.getTypeCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
        case TC_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
        case TC_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
        case TC_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        case TC_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        case TC_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
        case TC_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
        case TC_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
        case TC_DOUBLE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
                // Primitive...
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
                result = PrimitiveType.forPrimitive(theType,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        case TC_ARRAY:
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                // Array.
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
                result = ArrayType.forArray(theType,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
        case TC_CLASS:
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
                                // First, make sure we have the class definition...
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                    ClassDefinition theClass = classDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
                    if (theClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
                        theClass = env.getClassDeclaration(theType).getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
                                // Is it an interface or a class?
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
                    if (theClass.isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
                        // An interface. Is it a special case?
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
                        result = SpecialInterfaceType.forSpecial(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
                        if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
                            // No, does it implement java.rmi.Remote?
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
                            if (env.defRemote.implementedBy(env,theClass.getClassDeclaration())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
                                // Yep, so just see if we can create an instance of RemoteType
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
                                // from it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
                                boolean parentIsValue = stack.isParentAValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
                                result = RemoteType.forRemote(theClass,stack,parentIsValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
                                // If we did not succeed AND we are in a value context, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
                                // go ahead and make an NC type out of it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
                                if (result == null && parentIsValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
                                    result = NCInterfaceType.forNCInterface(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
                            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
                                // Nope, is it an AbstractType?
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
                                result = AbstractType.forAbstract(theClass,stack,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
                                if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
                                    // No, so treat it as a non-conforming interface type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
                                    result = NCInterfaceType.forNCInterface(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
                        // A class. Is it a special case?
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
                        result = SpecialClassType.forSpecial(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
                        if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
                            ClassDeclaration classDecl = theClass.getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
                            // Nope, does it implement java.rmi.Remote?
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
                            if (env.defRemote.implementedBy(env,classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
                                // Yep, so just see if we can create an instance of
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
                                // ImplementationType from it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
                                boolean parentIsValue = stack.isParentAValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                                result = ImplementationType.forImplementation(theClass,stack,parentIsValue);
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
                                // If we did not succeed AND inValue is true, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
                                // go ahead and make an NC type out of it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
                                if (result == null && parentIsValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
                                    result = NCClassType.forNCClass(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
                            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                                // No, does it implement Serializable?
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
                                if (env.defSerializable.implementedBy(env,classDecl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
                                    // Yep, so just see if we can create an instance of ValueType
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
                                    // from it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
                                    result = ValueType.forValue(theClass,stack,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                                if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
                                    // Treat it as a non-conforming class type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                                    result = NCClassType.forNCClass(theClass,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
                } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
                    classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
        default: throw new CompilerError("Unknown typecode (" + typeCode + ") for " + theType.getTypeSignature());
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
     * Check if exception is RemoteException or one of its parents.
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
    public static boolean isRemoteException (ClassType ex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
                                             BatchEnvironment env) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
        sun.tools.java.Type exceptionType = ex.getClassDeclaration().getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
        if (exceptionType.equals(env.typeRemoteException) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
            exceptionType.equals(env.typeIOException) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
            exceptionType.equals(env.typeException) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
            exceptionType.equals(env.typeThrowable)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
     * Check if method is conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
    protected boolean isConformingRemoteMethod (Method method, boolean quiet)
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
        // Do we have one exception that is RemoteException or
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
        // a superclass of RemoteException?
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        boolean haveRemote = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
        ClassType[] exceptions = method.getExceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
        for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
            // Is it a conforming exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
            if (isRemoteException(exceptions[i],env)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
                // Got it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
                haveRemote = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
        // Do we have our exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
        if (!haveRemote) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
            // No, so report failure...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
            failedConstraint(5,quiet,stack,method.getEnclosing(), method.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        // Are any of the arguments exceptions which implement IDLEntity?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
        // If so, report failure...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
        boolean noIDLEntity = !isIDLEntityException(method.getReturnType(),method,quiet);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
        if (noIDLEntity) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
            Type[] args = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
            for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
                if (isIDLEntityException(args[i],method,quiet)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
                    noIDLEntity = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
        return (haveRemote && noIDLEntity);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
    protected boolean isIDLEntityException(Type type, CompoundType.Method method,boolean quiet)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
        throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
        if (type.isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
            type = type.getElementType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
        if (type.isCompound()){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
            if (((CompoundType)type).isIDLEntityException()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
                failedConstraint(18,quiet,stack,method.getEnclosing(), method.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
     * Convert all invalid types to valid ones.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
    protected void swapInvalidTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
        // Walk all interfaces and check them...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
        for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
            if (interfaces[i].getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
                interfaces[i] = (InterfaceType)getValidType(interfaces[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
        // Update methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
        for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
            methods[i].swapInvalidTypes();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
        // Update members...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
        for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
            members[i].swapInvalidTypes();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
     * Add matching types to list. Return true if this type has not
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
     * been previously checked, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
    protected boolean addTypes (int typeCodeFilter,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
                                HashSet checked,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
                                Vector matching) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
        // Check self.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
        boolean result = super.addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
        // Have we been checked before?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
        if (result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
            // Nope, so walk parent(s) and check them...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
            ClassType parent = getSuperclass();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
            if (parent != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
                parent.addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
            // Walk all interfaces and check them...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
            //if (interfaces == null) System.out.println("NULL for " +getQualifiedName() + " interfaces");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
            for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
                // Now recurse and add it and any referenced types...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
                //if (interfaces[i] == null) System.out.println("NULL for " +getQualifiedName() + " interfaces[" + i + "]");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
                interfaces[i].addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
            // Walk all methods and check arguments...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
            //if (methods == null) System.out.println("NULL for " +getQualifiedName() + " methods");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
            for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
                // Add return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
                //if (methods[i] == null) System.out.println("NULL for " +getQualifiedName() + " methods[" + i + "]");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
                //if (methods[i].getReturnType() == null) System.out.println("NULL for " +getQualifiedName() + methods[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
                methods[i].getReturnType().addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
                // Add args...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
                Type[] args = methods[i].getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
                //if (args == null) System.out.println("NULL for " + getQualifiedName() + " args");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
                for (int j = 0; j < args.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
                    Type arg = args[j];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
                    //if (arg == null) System.out.println("NULL for " + getQualifiedName() + " arg[" +j+"]");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
                                // Add argument...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
                    arg.addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
                // Add exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
                ClassType[] exceptions = methods[i].getExceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
                //if (exceptions == null) System.out.println("NULL for " + getQualifiedName() + " exceptions");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
                for (int j = 0; j < exceptions.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
                    ClassType ex = exceptions[j];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
                                // Add argument...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
                    ex.addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
            // Walk all members and add em...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
            //if (members == null) System.out.println("NULL for " +getQualifiedName() + " members");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
            for (int i = 0; i < members.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
                //if (members[i] == null) System.out.println("NULL for " +getQualifiedName() + " members[" + i + "]");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
                Type cType = members[i].getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
                //if (cType == null) System.out.println("NULL for " + getQualifiedName() + " cType");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
                // Add it...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
                cType.addTypes(typeCodeFilter,checked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
     * Return true if theType is a conforming constant type.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
    private boolean isConformingConstantType (MemberDefinition member) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
        return isConformingConstantType(member.getType(),member);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
     * Return true if theType is a conforming constant type.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
    private boolean isConformingConstantType (sun.tools.java.Type theType,MemberDefinition member) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
        // Constraint 3:    Constants must be either primitives or String.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
        int typeCode = theType.getTypeCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
        case TC_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
        case TC_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
        case TC_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
        case TC_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
        case TC_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
        case TC_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
        case TC_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
        case TC_DOUBLE: // Primitive, so OK...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
        case TC_CLASS:  // Must be java.lang.String
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
                if (theType.getClassName() != idJavaLangString) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
                    failedConstraint(3,false,stack,member.getClassDefinition(),member.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
                    result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
        case TC_ARRAY: // Array constants are not allowed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
                failedConstraint(3,false,stack,member.getClassDefinition(),member.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
        default:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
            throw new Error("unexpected type code: " + typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
     * Update any method from 'currentMethods' which is defined in a
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
     * parent class so that it's 'declaredBy' field specifies the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
     * parent.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
     * @param current The class or interface to gather methods from.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
     * @param currentMethods The list into which to put the methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
     *  for contraint 6.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
     * @param quiet true if silent errors.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
     * @param stack the context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
     * @return currentMethods or null if failed a constraint check.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
    protected Vector updateParentClassMethods(ClassDefinition current,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
                                              Vector currentMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
                                              ContextStack stack)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
        throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
        ClassDeclaration parentDecl = current.getSuperClass(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
        while (parentDecl != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
            ClassDefinition parentDef = parentDecl.getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
            Identifier currentID = parentDecl.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
            if ( currentID == idJavaLangObject ) break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
            // Walk all members of this class and update any that
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
            // already exist in currentMethods...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
            for (MemberDefinition member = parentDef.getFirstMember();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
                 member != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
                 member = member.getNextMember()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
                if (member.isMethod() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
                    !member.isInitializer() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
                    !member.isConstructor() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
                    !member.isPrivate()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
                    // It's a method.  Is it valid?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
                    Method method;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
                        method = new Method((CompoundType)this,member,quiet,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
                    } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
                        // Don't report anything here, it's already been reported...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
                        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
                    // Have we already seen it?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
                    int index = currentMethods.indexOf(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
                    if (index >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
                        // Yes, so update it...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
                        Method currentMethod = (Method)currentMethods.elementAt(index);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
                        currentMethod.setDeclaredBy(currentID);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
                    else currentMethods.addElement(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
            // Update parent and keep walking up the chain...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
            parentDecl = parentDef.getSuperClass(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
        return currentMethods;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
     * Add all of the public and protected methods defined in
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
     * current (other than initializers) to allMethods. If a sub-interface
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
     * re-declares an inherited method, it will not be added.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
     * @param current The class or interface to gather methods from.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
     * @param directMethods The list into which to put the methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
     * @param noMultiInheritedMethods A flag to enable/disable checking
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
     *  for contraint 6.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
     * @param quiet true if silent errors.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
     * @param stack the context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
     * @return directMethods or null if failed a constraint check.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
    protected Vector addAllMethods (ClassDefinition current, Vector directMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
                                    boolean noMultiInheritedMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
                                    boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
                                    ContextStack stack)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
        throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
        // Constraint 6:    Multiple inherited interfaces may not
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
        //                  declare the same method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
        ClassDeclaration[] interfaces = current.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
        // We want to add members starting at the _least_ derived
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
        // interfaces.  To do so, recurse until we have no more
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
        // interfaces...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
        for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
            Vector result = addAllMethods(interfaces[i].getClassDefinition(env),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
                                          directMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
                                          noMultiInheritedMethods,quiet,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
            if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
        // Walk all members of this interface, adding any unique methods
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
        // other than initializers and private methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
        for (MemberDefinition member = current.getFirstMember();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
             member != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
             member = member.getNextMember())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
                if (member.isMethod() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
                    !member.isInitializer() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
                    !member.isPrivate()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
                    // It's a method.  Is it valid?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
                    Method method;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
                        method = new Method((CompoundType)this,member,quiet,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
                    } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
                        // Don't report anything here, it's already been reported...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
                        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
                                // Have we already seen it?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
                    if (!directMethods.contains(method)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
                        // Nope, so add it...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
                        directMethods.addElement(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
                        // Yes. This is an error unless we are looking at the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
                        // target interface (or this is a ValueType). Are we?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
                        if (noMultiInheritedMethods && current != classDef  &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
                            !stack.isParentAValue() && !stack.getContext().isValue()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
                            // Nope. Say so and signal error by returning null..
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
                            Method existingMethod = (Method) directMethods.elementAt(directMethods.indexOf(method));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
                            ClassDefinition existingMemberClassDef = existingMethod.getMemberDefinition().getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
                            // There are more legal cases to consider here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
                            // If the two methods belong to interfaces that inherit from each other
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
                            // then it is just a redefinition which is legal.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
                            if ( current != existingMemberClassDef &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
                                 ! inheritsFrom(current, existingMemberClassDef) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
                                 ! inheritsFrom(existingMemberClassDef, current))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
                            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
                                //Identifier int1 = existingMethod.getEnclosing().getIdentifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
                                //Identifier int2 = current.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
                                //String message = int1.toString() + " and " + int2.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
                                String message = existingMemberClassDef.getName() + " and " + current.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
                                failedConstraint(6,quiet,stack,classDef,message,method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
                                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
                        // Bug fix 5014329
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
                        // find a matching method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
                        int index = directMethods.indexOf(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
                        Method other = (Method) directMethods.get(index);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
                        // merge the two methods, such that the new method
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
                        // will contain only those exception that can be thrown
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
                        // by both these methods, not just one of them.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
                        Method newMethod = method.mergeWith(other);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
                        // replace the old method with the new.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
                        directMethods.set(index, newMethod);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
        return directMethods;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
    // This should really be a method on ClassDefinition, but it takes too long to change the shared source.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
    // Works for both, classes and interfaces.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
    protected boolean inheritsFrom(ClassDefinition def, ClassDefinition otherDef) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
        if (def == otherDef)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
        ClassDefinition superDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
        if (def.getSuperClass() != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
            superDef = def.getSuperClass().getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
            if (inheritsFrom(superDef, otherDef))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
        ClassDeclaration[] interfaces = def.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
        for (int i=0; i<interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
            superDef = interfaces[i].getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
            if (inheritsFrom(superDef, otherDef))
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
     * Add all of the interfaces implemented directly by current
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
     * to the list. Returns null if any are non-conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
    protected Vector addRemoteInterfaces (Vector list,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
                                          boolean allowNonConforming,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
                                          ContextStack stack) throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
        // Add all the interfaces of current...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
        ClassDefinition theInterface = getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
        ClassDeclaration[] interfaces = theInterface.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
        stack.setNewContextCode(ContextStack.IMPLEMENTS);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
        for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
            ClassDefinition def = interfaces[i].getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
            // Is it a SpecialInterfaceType...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
            InterfaceType it = SpecialInterfaceType.forSpecial(def,stack);;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
            if (it == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
                // No, is it Remote?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
                if (env.defRemote.implementedBy(env, interfaces[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
                    // Yes, so it must be a RemoteType.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
                    it = RemoteType.forRemote(def,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
                    // Then try Abstract...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
                    it = AbstractType.forAbstract(def,stack,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
                    if (it == null && allowNonConforming) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
                        // Must be non-conforming...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
                        it = NCInterfaceType.forNCInterface(def,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
            if (it != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
                list.addElement(it);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
        return list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
     * Add all of the interfaces implemented directly by current
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
     * to the list.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
    protected Vector addNonRemoteInterfaces (Vector list,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
                                             ContextStack stack) throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
        // Add all the interfaces of current...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
        ClassDefinition theInterface = getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
        ClassDeclaration[] interfaces = theInterface.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
        stack.setNewContextCode(ContextStack.IMPLEMENTS);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
        for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
            ClassDefinition def = interfaces[i].getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
            // First try SpecialInterfaceType...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
            InterfaceType it = SpecialInterfaceType.forSpecial(def,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
            if (it == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
                // Then try AbstractType...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
                it = AbstractType.forAbstract(def,stack,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
                if (it == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
                    // Then try NCInterfaceType...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
                    it = NCInterfaceType.forNCInterface(def,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
            if (it != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
                list.addElement(it);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
        return list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
     * Walk self, adding constants and data members.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
     * @return true if all conform, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
    protected boolean addAllMembers (Vector allMembers,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
                                     boolean onlyConformingConstants,   // AND inner classes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
                                     boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
                                     ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
        // Walk all members of this interface...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
        for (MemberDefinition member = getClassDefinition().getFirstMember();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
             member != null && result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
             member = member.getNextMember())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
                if (!member.isMethod()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
                        String value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
02bb8761fcce Initial load
duke
parents:
diff changeset
  1548
                        // Prod it to setValue if it is a constant...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1549
02bb8761fcce Initial load
duke
parents:
diff changeset
  1550
                        member.getValue(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1551
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
                                // Get the value, if any...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
                        Node node = member.getValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
                        if (node != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
                            // We don't want to change the code in CharExpression,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
                            // which is shared among tools, to return the right string
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
                            // in case the type is char, so we treat it special here.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
                            if (member.getType().getTypeCode() == TC_CHAR) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
                                Integer intValue = (Integer)((IntegerExpression)node).getValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
                                value = "L'" + String.valueOf((char)intValue.intValue()) + "'";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
                            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
                                value = node.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
                        // Are we supposed to allow only conforming constants?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
                        if (onlyConformingConstants && member.getInnerClass() == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
                                // Yep, so check it...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
                            if (value == null || !isConformingConstantType(member)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
                                failedConstraint(3,quiet,stack,member.getClassDefinition(),member.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
                                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
                                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
                        // Make member and add to list...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
                            Member newMember = new Member(member,value,stack,this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
                            allMembers.addElement(newMember);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
                        } catch (CompilerError e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
                            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
                    } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
                        classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
                        result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
     * Walk self, adding constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
     * @return true if all conform, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
    protected boolean addConformingConstants (Vector allMembers,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
                                              ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
        // Walk all members of this interface...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
        for (MemberDefinition member = getClassDefinition().getFirstMember();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
             member != null && result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
             member = member.getNextMember())
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
                if (!member.isMethod()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
                        String value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
                        // Prod it to setValue if it is a constant...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
                        member.getValue(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
                                // Get the value, if any...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
                        Node node = member.getValue();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
                        if (node != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
                            value = node.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
                        // Is it a constant?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
                        if (value != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
                            // Yes, is it conforming?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
                            if (!isConformingConstantType(member)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
                                failedConstraint(3,quiet,stack,member.getClassDefinition(),member.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
                                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
                                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
                            // Yes, so make a member and add to list...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
                            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
                                Member newMember = new Member(member,value,stack,this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
                                allMembers.addElement(newMember);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
                            } catch (CompilerError e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
                                result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
                    } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
                        classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
                        result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
    protected ValueType[] getMethodExceptions (MemberDefinition member,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
                                               boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
                                               ContextStack stack) throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
        boolean result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1669
        stack.setNewContextCode(ContextStack.METHOD_EXCEPTION);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1670
        ClassDeclaration[] except = member.getExceptions(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1671
        ValueType[] exceptions = new ValueType[except.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
            for (int i = 0; i < except.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
                ClassDefinition theClass = except[i].getClassDefinition(env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
                    ValueType type = ValueType.forValue(theClass,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
                    if (type != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
                            exceptions[i] = type;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
                            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
                } catch (ClassCastException e1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
                    failedConstraint(22,quiet,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
                    throw new CompilerError("Method: exception " + theClass.getName() + " not a class type!");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
                } catch (NullPointerException e2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
                    failedConstraint(23,quiet,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
                    throw new CompilerError("Method: caught null pointer exception");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
        } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
            classNotFound(quiet,stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1693
            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1694
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1695
02bb8761fcce Initial load
duke
parents:
diff changeset
  1696
        if (!result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1697
            throw new Exception();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1698
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1699
02bb8761fcce Initial load
duke
parents:
diff changeset
  1700
        // Remove any duplicates (javac seems to allow them, but rmic will
02bb8761fcce Initial load
duke
parents:
diff changeset
  1701
        // generate bad ties)...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1702
02bb8761fcce Initial load
duke
parents:
diff changeset
  1703
        int dupCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1704
        for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1705
            for (int j = 0; j < exceptions.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1706
                if (i != j && exceptions[i] != null && exceptions[i] == exceptions[j]) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1707
                    exceptions[j] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1708
                    dupCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1709
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1710
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1711
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1712
        if (dupCount > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1713
            int offset = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1714
            ValueType[] temp = new ValueType[exceptions.length - dupCount];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1715
            for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1716
                if (exceptions[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1717
                    temp[offset++] = exceptions[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1718
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1719
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1720
            exceptions = temp;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1721
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1722
02bb8761fcce Initial load
duke
parents:
diff changeset
  1723
        return exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1724
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1725
02bb8761fcce Initial load
duke
parents:
diff changeset
  1726
02bb8761fcce Initial load
duke
parents:
diff changeset
  1727
    protected static String getVisibilityString (MemberDefinition member) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1728
        String vis = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1729
        String prefix = "";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1730
02bb8761fcce Initial load
duke
parents:
diff changeset
  1731
        if (member.isPublic()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1732
            vis += "public";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1733
            prefix = " ";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1734
        } else if (member.isProtected()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1735
            vis += "protected";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1736
            prefix = " ";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1737
        } else if (member.isPrivate()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1738
            vis += "private";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1739
            prefix = " ";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1740
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1741
02bb8761fcce Initial load
duke
parents:
diff changeset
  1742
        if (member.isStatic()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1743
            vis += prefix;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1744
            vis += "static";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1745
            prefix = " ";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1746
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1747
02bb8761fcce Initial load
duke
parents:
diff changeset
  1748
        if (member.isFinal()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1749
            vis += prefix;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1750
            vis += "final";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1751
            prefix = " ";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1752
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1753
02bb8761fcce Initial load
duke
parents:
diff changeset
  1754
        return vis;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1755
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1756
02bb8761fcce Initial load
duke
parents:
diff changeset
  1757
    protected boolean assertNotImpl(Type type,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1758
                                    boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1759
                                    ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1760
                                    CompoundType enclosing,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1761
                                    boolean dataMember) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1762
02bb8761fcce Initial load
duke
parents:
diff changeset
  1763
        if (type.isType(TYPE_IMPLEMENTATION)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1764
            int constraint = dataMember ? 28 : 21;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1765
            failedConstraint(constraint,quiet,stack,type,enclosing.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1766
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1767
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1768
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1769
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1770
02bb8761fcce Initial load
duke
parents:
diff changeset
  1771
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1772
    // Inner Class "Method"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1773
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1774
02bb8761fcce Initial load
duke
parents:
diff changeset
  1775
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1776
     * A CompoundType.Method object encapsulates IIOP-specific information
02bb8761fcce Initial load
duke
parents:
diff changeset
  1777
     * about a particular method in the interface represented by the outer
02bb8761fcce Initial load
duke
parents:
diff changeset
  1778
     * instance.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1779
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1780
    public class Method implements ContextElement, Cloneable {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1781
02bb8761fcce Initial load
duke
parents:
diff changeset
  1782
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1783
         * Is this method inherited?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1784
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1785
        public boolean isInherited () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1786
            return declaredBy != enclosing.getIdentifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1787
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1788
02bb8761fcce Initial load
duke
parents:
diff changeset
  1789
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1790
         * Is this method an attribute?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1791
         * Return true if getAttributeKind != ATTRIBUTE_NONE.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1792
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1793
        public boolean isAttribute () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1794
            return attributeKind != ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1795
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1796
02bb8761fcce Initial load
duke
parents:
diff changeset
  1797
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1798
         * Is this method a read-write attribute?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1799
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1800
        public boolean isReadWriteAttribute () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1801
            return attributeKind == ATTRIBUTE_IS_RW ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  1802
                attributeKind == ATTRIBUTE_GET_RW;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1803
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1804
02bb8761fcce Initial load
duke
parents:
diff changeset
  1805
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1806
         * Return the attribute kind.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1807
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1808
        public int getAttributeKind() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1809
            return attributeKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1810
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1811
02bb8761fcce Initial load
duke
parents:
diff changeset
  1812
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1813
         * Return the attribute name. Will be null if
02bb8761fcce Initial load
duke
parents:
diff changeset
  1814
         * attribute kind == ATTRIBUTE_NONE.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1815
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1816
        public String getAttributeName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1817
            return attributeName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1818
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1819
02bb8761fcce Initial load
duke
parents:
diff changeset
  1820
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1821
         * For kinds ATTRIBUTE_GET_RW or ATTRIBUTE_IS_RW, return
02bb8761fcce Initial load
duke
parents:
diff changeset
  1822
         * the index of the matching ATTRIBUTE_SET method, and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1823
         * vice-versa. For all other cases, return -1.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1824
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1825
        public int getAttributePairIndex() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1826
            return attributePairIndex;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1827
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1828
02bb8761fcce Initial load
duke
parents:
diff changeset
  1829
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1830
         * Return context element name.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1831
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1832
        public String getElementName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1833
            return memberDef.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1834
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1835
02bb8761fcce Initial load
duke
parents:
diff changeset
  1836
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1837
         * Equality check based on method signature.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1838
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1839
        public boolean equals(Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1840
            Method other = (Method) obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1841
02bb8761fcce Initial load
duke
parents:
diff changeset
  1842
            if (getName().equals(other.getName()) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1843
                arguments.length == other.arguments.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1844
02bb8761fcce Initial load
duke
parents:
diff changeset
  1845
                for (int i = 0; i < arguments.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1846
                    if (! arguments[i].equals(other.arguments[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1847
                        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1848
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1849
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1850
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1851
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1852
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1853
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1854
18302
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
  1855
        public int hashCode() {
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
  1856
            return getName().hashCode() ^ Arrays.hashCode(arguments);
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
  1857
        }
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
  1858
4
02bb8761fcce Initial load
duke
parents:
diff changeset
  1859
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1860
         * Return a new Method object that is a legal combination of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1861
         * this method object and another one.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1862
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  1863
         * This requires determining the exceptions declared by the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1864
         * combined method, which must be only those exceptions
02bb8761fcce Initial load
duke
parents:
diff changeset
  1865
         * that may thrown by both of the old methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1866
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1867
        public Method mergeWith(Method other) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1868
            if (!equals(other)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1869
                env.error(0, "attempt to merge method failed:", getName(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1870
                          enclosing.getClassDefinition().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1871
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1872
02bb8761fcce Initial load
duke
parents:
diff changeset
  1873
            Vector legalExceptions = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1874
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1875
                collectCompatibleExceptions(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1876
                      other.exceptions, exceptions, legalExceptions);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1877
                collectCompatibleExceptions(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1878
                      exceptions, other.exceptions, legalExceptions);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1879
            } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1880
                env.error(0, "class.not.found", e.name,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1881
                          enclosing.getClassDefinition().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1882
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1883
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1884
02bb8761fcce Initial load
duke
parents:
diff changeset
  1885
            Method merged = (Method) clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1886
            merged.exceptions = new ValueType[legalExceptions.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1887
            legalExceptions.copyInto(merged.exceptions);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1888
            merged.implExceptions = merged.exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1889
02bb8761fcce Initial load
duke
parents:
diff changeset
  1890
            return merged;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1891
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1892
02bb8761fcce Initial load
duke
parents:
diff changeset
  1893
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1894
         * Add to the supplied list all exceptions in the "from" array
02bb8761fcce Initial load
duke
parents:
diff changeset
  1895
         * that are subclasses of an exception in the "with" array.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1896
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1897
        private void collectCompatibleExceptions(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1898
                ValueType[] from, ValueType[] with, Vector list)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1899
                throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1900
02bb8761fcce Initial load
duke
parents:
diff changeset
  1901
            for (int i = 0; i < from.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1902
                ClassDefinition exceptionDef = from[i].getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1903
                if (!list.contains(from[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1904
                    for (int j = 0; j < with.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1905
                        if (exceptionDef.subClassOf(
02bb8761fcce Initial load
duke
parents:
diff changeset
  1906
                                enclosing.getEnv(),
02bb8761fcce Initial load
duke
parents:
diff changeset
  1907
                                with[j].getClassDeclaration())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1908
                            list.addElement(from[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1909
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1910
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1911
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1912
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1913
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1914
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1915
02bb8761fcce Initial load
duke
parents:
diff changeset
  1916
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1917
         * Return the compound type which contains this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1918
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1919
        public CompoundType getEnclosing() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1920
            return enclosing;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1921
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1922
02bb8761fcce Initial load
duke
parents:
diff changeset
  1923
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1924
         * Return the identifier for the class or interface which
02bb8761fcce Initial load
duke
parents:
diff changeset
  1925
         * declares this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1926
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1927
        public Identifier getDeclaredBy() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1928
            return declaredBy;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1929
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1930
02bb8761fcce Initial load
duke
parents:
diff changeset
  1931
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1932
         * Return the visibility (e.g. "public final") of this member.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1933
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1934
        public String getVisibility() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1935
            return vis;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1936
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1937
02bb8761fcce Initial load
duke
parents:
diff changeset
  1938
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1939
         * Methods to check various attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1940
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1941
        public boolean isPublic() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1942
            return memberDef.isPublic();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1943
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1944
02bb8761fcce Initial load
duke
parents:
diff changeset
  1945
        public boolean isProtected() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1946
            return memberDef.isPrivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1947
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1948
02bb8761fcce Initial load
duke
parents:
diff changeset
  1949
        public boolean isPrivate() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1950
            return memberDef.isPrivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1951
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1952
02bb8761fcce Initial load
duke
parents:
diff changeset
  1953
        public boolean isStatic() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1954
            return memberDef.isStatic();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1955
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1956
02bb8761fcce Initial load
duke
parents:
diff changeset
  1957
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1958
         * Return the name of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1959
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1960
        public String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1961
            return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1962
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1963
02bb8761fcce Initial load
duke
parents:
diff changeset
  1964
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1965
         * IDL_Naming
02bb8761fcce Initial load
duke
parents:
diff changeset
  1966
         * Return the IDL name of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1967
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1968
        public String getIDLName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1969
            return idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1970
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1971
02bb8761fcce Initial load
duke
parents:
diff changeset
  1972
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1973
         * Return the type of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1974
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1975
        public sun.tools.java.Type getType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1976
            return memberDef.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1977
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1978
02bb8761fcce Initial load
duke
parents:
diff changeset
  1979
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1980
         * Return true if this is a constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1981
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1982
        public boolean isConstructor () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1983
            return memberDef.isConstructor();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1984
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1985
02bb8761fcce Initial load
duke
parents:
diff changeset
  1986
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1987
         * Return true if this is NOT a constructor && is not
02bb8761fcce Initial load
duke
parents:
diff changeset
  1988
         * an attribute.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1989
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1990
        public boolean isNormalMethod () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1991
            return (!memberDef.isConstructor()) && attributeKind == ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1992
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1993
02bb8761fcce Initial load
duke
parents:
diff changeset
  1994
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1995
         * Get the return type of this method. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1996
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1997
        public Type getReturnType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1998
            return returnType;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1999
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2000
02bb8761fcce Initial load
duke
parents:
diff changeset
  2001
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2002
         * Return the argument types of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2003
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2004
        public Type[] getArguments() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2005
            return (Type[]) arguments.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2006
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2007
02bb8761fcce Initial load
duke
parents:
diff changeset
  2008
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2009
         * Return the names of the argument types of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2010
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2011
        public String[] getArgumentNames() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2012
            return argumentNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2013
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2014
02bb8761fcce Initial load
duke
parents:
diff changeset
  2015
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2016
         * Return the MemberDefinition from which this method was created.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2017
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2018
        public MemberDefinition getMemberDefinition() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2019
            return memberDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2020
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2021
02bb8761fcce Initial load
duke
parents:
diff changeset
  2022
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2023
         * Return an array of the exception classes declared to be
02bb8761fcce Initial load
duke
parents:
diff changeset
  2024
         * thrown by this remote method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2025
         *
02bb8761fcce Initial load
duke
parents:
diff changeset
  2026
         * For methods with the same name and type signature inherited
02bb8761fcce Initial load
duke
parents:
diff changeset
  2027
         * from multiple remote interfaces, the array will contain
02bb8761fcce Initial load
duke
parents:
diff changeset
  2028
         * the set of exceptions declared in all of the interfaces'
02bb8761fcce Initial load
duke
parents:
diff changeset
  2029
         * methods that can be legally thrown in each of them.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2030
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2031
        public ValueType[] getExceptions() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2032
            return (ValueType[]) exceptions.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2033
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2034
02bb8761fcce Initial load
duke
parents:
diff changeset
  2035
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2036
         * Same as getExceptions(), except when method is in an
02bb8761fcce Initial load
duke
parents:
diff changeset
  2037
         * ImplementationType and the exceptions list is narrower.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2038
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2039
        public ValueType[] getImplExceptions() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2040
            return (ValueType[]) implExceptions.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2041
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2042
02bb8761fcce Initial load
duke
parents:
diff changeset
  2043
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2044
         * Return an array containing only those exceptions which
02bb8761fcce Initial load
duke
parents:
diff changeset
  2045
         * need to be caught.  Removes java.rmi.RemoteException,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2046
         * java.lang.RuntimeException, java.lang.Error, and their
02bb8761fcce Initial load
duke
parents:
diff changeset
  2047
         * subclasses, then removes any exceptions which are more
02bb8761fcce Initial load
duke
parents:
diff changeset
  2048
         * derived than another in the list. Returns null if no
02bb8761fcce Initial load
duke
parents:
diff changeset
  2049
         * exceptions need to be caught.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2050
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2051
        public ValueType[] getUniqueCatchList(ValueType[] list) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2052
            ValueType[] result = list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2053
            int newSize = list.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2054
02bb8761fcce Initial load
duke
parents:
diff changeset
  2055
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2056
02bb8761fcce Initial load
duke
parents:
diff changeset
  2057
                // First, remove RemoteException, RuntimeException, Error, and their subclasses...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2058
                for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2059
                    ClassDeclaration decl = list[i].getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2060
                    if (env.defRemoteException.superClassOf(env, decl) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2061
                        env.defRuntimeException.superClassOf(env, decl) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2062
                        env.defError.superClassOf(env, decl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2063
                        list[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2064
                        newSize--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2065
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2066
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2067
02bb8761fcce Initial load
duke
parents:
diff changeset
  2068
                // Now remove derived types...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2069
                for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2070
                    if (list[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2071
                        ClassDefinition current = list[i].getClassDefinition();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2072
                        for (int j = 0; j < list.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2073
                            if (j != i && list[i] != null && list[j] != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2074
                                current.superClassOf(env, list[j].getClassDeclaration())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2075
                                list[j] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2076
                                newSize--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2077
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2078
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2079
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2080
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2081
02bb8761fcce Initial load
duke
parents:
diff changeset
  2082
            } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2083
                classNotFound(stack,e); // Report error but do not stop.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2084
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2085
02bb8761fcce Initial load
duke
parents:
diff changeset
  2086
            // Create new list if we removed anything...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2087
02bb8761fcce Initial load
duke
parents:
diff changeset
  2088
            if (newSize < list.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2089
                ValueType[] temp = new ValueType[newSize];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2090
                int offset = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2091
                for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2092
                    if (list[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2093
                        temp[offset++] = list[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2094
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2095
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2096
                list = temp;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2097
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2098
02bb8761fcce Initial load
duke
parents:
diff changeset
  2099
            if (list.length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2100
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2101
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2102
                return list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2103
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2104
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2105
02bb8761fcce Initial load
duke
parents:
diff changeset
  2106
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2107
         * Return an array containing only those exceptions which need to be
02bb8761fcce Initial load
duke
parents:
diff changeset
  2108
         * handled explicitly by the stub.  Removes java.lang.RuntimeException,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2109
         * java.lang.Error, and their subclasses, since these are all passed
02bb8761fcce Initial load
duke
parents:
diff changeset
  2110
         * back as CORBA system exceptions.  Also removes subclasses of
02bb8761fcce Initial load
duke
parents:
diff changeset
  2111
         * java.rmi.RemoteException but not java.rmi.RemoteException itself,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2112
         * since this may need to be thrown by the stub.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2113
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2114
        public ValueType[] getFilteredStubExceptions(ValueType[] list) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2115
            ValueType[] result = list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2116
            int newSize = list.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2117
02bb8761fcce Initial load
duke
parents:
diff changeset
  2118
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2119
02bb8761fcce Initial load
duke
parents:
diff changeset
  2120
                for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2121
                    ClassDeclaration decl = list[i].getClassDeclaration();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2122
                    if ((env.defRemoteException.superClassOf(env, decl) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2123
                         !env.defRemoteException.getClassDeclaration().equals(decl)) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2124
                        env.defRuntimeException.superClassOf(env, decl) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2125
                        env.defError.superClassOf(env, decl)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2126
                        list[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2127
                        newSize--;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2128
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2129
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2130
02bb8761fcce Initial load
duke
parents:
diff changeset
  2131
            } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2132
                classNotFound(stack,e); // Report error but do not stop.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2133
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2134
02bb8761fcce Initial load
duke
parents:
diff changeset
  2135
            // Create new list if we removed anything...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2136
02bb8761fcce Initial load
duke
parents:
diff changeset
  2137
            if (newSize < list.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2138
                ValueType[] temp = new ValueType[newSize];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2139
                int offset = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2140
                for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2141
                    if (list[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2142
                        temp[offset++] = list[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2143
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2144
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2145
                list = temp;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2146
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2147
02bb8761fcce Initial load
duke
parents:
diff changeset
  2148
            return list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2149
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2150
02bb8761fcce Initial load
duke
parents:
diff changeset
  2151
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2152
         * Return the string representation of this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2153
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2154
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2155
02bb8761fcce Initial load
duke
parents:
diff changeset
  2156
            if (stringRep == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2157
02bb8761fcce Initial load
duke
parents:
diff changeset
  2158
                StringBuffer result = new StringBuffer(returnType.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2159
02bb8761fcce Initial load
duke
parents:
diff changeset
  2160
                // Add name...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2161
02bb8761fcce Initial load
duke
parents:
diff changeset
  2162
                result.append(" ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2163
                result.append(getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2164
                result.append(" (");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2165
02bb8761fcce Initial load
duke
parents:
diff changeset
  2166
                // Add arguments...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2167
02bb8761fcce Initial load
duke
parents:
diff changeset
  2168
                for (int i = 0; i < arguments.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2169
                    if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2170
                        result.append(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2171
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2172
                    result.append(arguments[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2173
                    result.append(" ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2174
                    result.append(argumentNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2175
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2176
02bb8761fcce Initial load
duke
parents:
diff changeset
  2177
                result.append(")");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2178
02bb8761fcce Initial load
duke
parents:
diff changeset
  2179
                // Add exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2180
02bb8761fcce Initial load
duke
parents:
diff changeset
  2181
                for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2182
                    if (i == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2183
                        result.append(" throws ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2184
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2185
                        result.append(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2186
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2187
                    result.append(exceptions[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2188
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2189
02bb8761fcce Initial load
duke
parents:
diff changeset
  2190
                result.append(";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2191
02bb8761fcce Initial load
duke
parents:
diff changeset
  2192
                stringRep = result.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2193
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2194
02bb8761fcce Initial load
duke
parents:
diff changeset
  2195
            return stringRep;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2196
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2197
02bb8761fcce Initial load
duke
parents:
diff changeset
  2198
02bb8761fcce Initial load
duke
parents:
diff changeset
  2199
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2200
         * Set attribute kind. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2201
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2202
        public void setAttributeKind(int kind) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2203
            attributeKind = kind;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2204
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2205
02bb8761fcce Initial load
duke
parents:
diff changeset
  2206
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2207
         * Set pair index. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2208
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2209
        public void setAttributePairIndex(int index) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2210
            attributePairIndex = index;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2211
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2212
02bb8761fcce Initial load
duke
parents:
diff changeset
  2213
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2214
         * Set attribute name. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2215
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2216
        public void setAttributeName(String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2217
            attributeName = name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2218
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2219
02bb8761fcce Initial load
duke
parents:
diff changeset
  2220
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2221
         * Set the idl name. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2222
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2223
        public void setIDLName (String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2224
            this.idlName=idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2225
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2226
02bb8761fcce Initial load
duke
parents:
diff changeset
  2227
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2228
         * Set the implExceptions array. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2229
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2230
        public void setImplExceptions (ValueType[] exceptions) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2231
            implExceptions = exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2232
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2233
02bb8761fcce Initial load
duke
parents:
diff changeset
  2234
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2235
         * Set the declaredBy Identifier. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2236
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2237
        public void setDeclaredBy (Identifier by) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2238
            declaredBy = by;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2239
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2240
02bb8761fcce Initial load
duke
parents:
diff changeset
  2241
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2242
         * Convert all invalid types to valid ones.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2243
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2244
        protected void swapInvalidTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2245
02bb8761fcce Initial load
duke
parents:
diff changeset
  2246
            // Check return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2247
02bb8761fcce Initial load
duke
parents:
diff changeset
  2248
            if (returnType.getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2249
                returnType = getValidType(returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2250
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2251
02bb8761fcce Initial load
duke
parents:
diff changeset
  2252
            // Check args...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2253
02bb8761fcce Initial load
duke
parents:
diff changeset
  2254
            for (int i = 0; i < arguments.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2255
                if (arguments[i].getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2256
                    arguments[i] = getValidType(arguments[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2257
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2258
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2259
02bb8761fcce Initial load
duke
parents:
diff changeset
  2260
            // Check exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2261
02bb8761fcce Initial load
duke
parents:
diff changeset
  2262
            for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2263
                if (exceptions[i].getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2264
                    exceptions[i] = (ValueType)getValidType(exceptions[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2265
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2266
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2267
02bb8761fcce Initial load
duke
parents:
diff changeset
  2268
            // Check implExceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2269
02bb8761fcce Initial load
duke
parents:
diff changeset
  2270
            for (int i = 0; i < implExceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2271
                if (implExceptions[i].getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2272
                    implExceptions[i] = (ValueType)getValidType(implExceptions[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2273
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2274
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2276
02bb8761fcce Initial load
duke
parents:
diff changeset
  2277
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2278
         * Release all resources.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2279
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2280
        public void destroy () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2281
            if (memberDef != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2282
                memberDef = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2283
                enclosing = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2284
                if (exceptions != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2285
                    for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2286
                        if (exceptions[i] != null) exceptions[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2287
                        exceptions[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2288
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2289
                    exceptions = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2290
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2291
02bb8761fcce Initial load
duke
parents:
diff changeset
  2292
                if (implExceptions != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2293
                    for (int i = 0; i < implExceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2294
                        if (implExceptions[i] != null) implExceptions[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2295
                        implExceptions[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2296
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2297
                    implExceptions = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2298
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2299
02bb8761fcce Initial load
duke
parents:
diff changeset
  2300
                if (returnType != null) returnType.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2301
                returnType = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2302
02bb8761fcce Initial load
duke
parents:
diff changeset
  2303
                if (arguments != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2304
                    for (int i = 0; i < arguments.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2305
                        if (arguments[i] != null) arguments[i].destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2306
                        arguments[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2307
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2308
                    arguments = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2309
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2310
02bb8761fcce Initial load
duke
parents:
diff changeset
  2311
                if (argumentNames != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2312
                    for (int i = 0; i < argumentNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2313
                        argumentNames[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2314
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2315
                    argumentNames = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2316
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2317
02bb8761fcce Initial load
duke
parents:
diff changeset
  2318
                vis = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2319
                name = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2320
                idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2321
                stringRep = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2322
                attributeName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2323
                declaredBy = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2324
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2325
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2326
02bb8761fcce Initial load
duke
parents:
diff changeset
  2327
        private MemberDefinition memberDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2328
        private CompoundType enclosing;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2329
        private ValueType[] exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2330
        private ValueType[] implExceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2331
        private Type returnType;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2332
        private Type[] arguments;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2333
        private String[] argumentNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2334
        private String vis;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2335
        private String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2336
        private String idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2337
        private String stringRep = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2338
        private int attributeKind = ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2339
        private String attributeName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2340
        private int attributePairIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2341
        private Identifier declaredBy = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2342
02bb8761fcce Initial load
duke
parents:
diff changeset
  2343
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2344
         * Make up an argument name for the given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2345
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2346
        private String makeArgName (int argNum, Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2347
            return "arg" + argNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2348
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2349
02bb8761fcce Initial load
duke
parents:
diff changeset
  2350
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2351
         * Create a new Method object corresponding to the given
02bb8761fcce Initial load
duke
parents:
diff changeset
  2352
         * method definition.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2353
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2354
        public Method (CompoundType enclosing,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2355
                       MemberDefinition memberDef,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2356
                       boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2357
                       ContextStack stack) throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2358
02bb8761fcce Initial load
duke
parents:
diff changeset
  2359
            this.enclosing = enclosing;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2360
            this.memberDef = memberDef;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2361
            vis = getVisibilityString(memberDef);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2362
            idlName = null; // See setIDLName()
02bb8761fcce Initial load
duke
parents:
diff changeset
  2363
            boolean valid = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2364
            declaredBy = memberDef.getClassDeclaration().getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2365
02bb8761fcce Initial load
duke
parents:
diff changeset
  2366
            // Set name...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2367
02bb8761fcce Initial load
duke
parents:
diff changeset
  2368
            name = memberDef.getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2369
02bb8761fcce Initial load
duke
parents:
diff changeset
  2370
            // Update the context...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2371
02bb8761fcce Initial load
duke
parents:
diff changeset
  2372
            stack.setNewContextCode(ContextStack.METHOD);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2373
            stack.push(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2374
02bb8761fcce Initial load
duke
parents:
diff changeset
  2375
            // Set return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2376
02bb8761fcce Initial load
duke
parents:
diff changeset
  2377
            stack.setNewContextCode(ContextStack.METHOD_RETURN);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2378
            sun.tools.java.Type methodType = memberDef.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2379
            sun.tools.java.Type rtnType = methodType.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2380
02bb8761fcce Initial load
duke
parents:
diff changeset
  2381
            if (rtnType == sun.tools.java.Type.tVoid) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2382
                returnType = PrimitiveType.forPrimitive(rtnType,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2383
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2384
                returnType = makeType(rtnType,null,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2385
                if (returnType == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2386
                    !assertNotImpl(returnType,quiet,stack,enclosing,false)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2387
                    valid = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2388
                    failedConstraint(24,quiet,stack,enclosing.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2389
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2390
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2391
02bb8761fcce Initial load
duke
parents:
diff changeset
  2392
            // Set arguments and argument names...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2393
02bb8761fcce Initial load
duke
parents:
diff changeset
  2394
            stack.setNewContextCode(ContextStack.METHOD_ARGUMENT);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2395
            sun.tools.java.Type[] args = memberDef.getType().getArgumentTypes();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2396
            arguments = new Type[args.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2397
            argumentNames = new String[args.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  2398
            Vector origArgNames = memberDef.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2399
02bb8761fcce Initial load
duke
parents:
diff changeset
  2400
            for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2401
                Type type = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2402
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2403
                    type = makeType(args[i],null,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2404
                } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2405
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2406
02bb8761fcce Initial load
duke
parents:
diff changeset
  2407
                if (type != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2408
                    if (!assertNotImpl(type,quiet,stack,enclosing,false)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2409
                        valid = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2410
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2411
                    arguments[i] = type;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2412
                    if (origArgNames != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2413
                        LocalMember local = (LocalMember)origArgNames.elementAt(i+1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2414
                        argumentNames[i] = local.getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2415
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2416
                        argumentNames[i] = makeArgName(i,type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2417
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2418
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2419
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2420
                    valid = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2421
                    failedConstraint(25,false,stack,enclosing.getQualifiedName(),name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2422
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2423
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2424
02bb8761fcce Initial load
duke
parents:
diff changeset
  2425
            if (!valid) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2426
                stack.pop(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2427
                throw new Exception();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2428
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2429
02bb8761fcce Initial load
duke
parents:
diff changeset
  2430
            // Set exceptions...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2431
02bb8761fcce Initial load
duke
parents:
diff changeset
  2432
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2433
                exceptions = enclosing.getMethodExceptions(memberDef,quiet,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2434
                implExceptions = exceptions;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2435
                stack.pop(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2436
            } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2437
                stack.pop(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2438
                throw new Exception();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2439
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2440
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2441
02bb8761fcce Initial load
duke
parents:
diff changeset
  2442
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2443
         * Cloning is supported by returning a shallow copy of this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2444
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2445
        protected Object clone() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2446
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2447
                return super.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2448
            } catch (CloneNotSupportedException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2449
                throw new Error("clone failed");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2450
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2451
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2452
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2453
02bb8761fcce Initial load
duke
parents:
diff changeset
  2454
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  2455
    // Inner Class "Member"
02bb8761fcce Initial load
duke
parents:
diff changeset
  2456
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  2457
02bb8761fcce Initial load
duke
parents:
diff changeset
  2458
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2459
     * An CompoundType.Member object wraps a Type and a value representing
02bb8761fcce Initial load
duke
parents:
diff changeset
  2460
     * a data member, including constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2461
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2462
    public class Member implements ContextElement, Cloneable {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2463
02bb8761fcce Initial load
duke
parents:
diff changeset
  2464
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2465
         * Return context element name.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2466
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2467
        public String getElementName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2468
            return "\"" + getName() + "\"";
02bb8761fcce Initial load
duke
parents:
diff changeset
  2469
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2470
02bb8761fcce Initial load
duke
parents:
diff changeset
  2471
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2472
         * Return the type of this member.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2473
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2474
        public Type getType() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2475
            return type;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2476
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2477
02bb8761fcce Initial load
duke
parents:
diff changeset
  2478
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2479
         * Return the name of this member.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2480
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2481
        public String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2482
            return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2483
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2484
02bb8761fcce Initial load
duke
parents:
diff changeset
  2485
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2486
         * IDL_Naming
02bb8761fcce Initial load
duke
parents:
diff changeset
  2487
         * Return the IDL name of this member.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2488
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2489
        public String getIDLName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2490
            return idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2491
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2492
02bb8761fcce Initial load
duke
parents:
diff changeset
  2493
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2494
         * Return the visibility (e.g. "public final") of this member.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2495
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2496
        public String getVisibility() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2497
            return vis;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2498
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2499
02bb8761fcce Initial load
duke
parents:
diff changeset
  2500
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2501
         * Methods to check various attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2502
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2503
        public boolean isPublic() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2504
            return member.isPublic();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2505
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2506
02bb8761fcce Initial load
duke
parents:
diff changeset
  2507
        public boolean isPrivate() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2508
            return member.isPrivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2509
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2510
02bb8761fcce Initial load
duke
parents:
diff changeset
  2511
        public boolean isStatic() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2512
            return member.isStatic();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2513
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2514
02bb8761fcce Initial load
duke
parents:
diff changeset
  2515
        public boolean isFinal() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2516
            return member.isFinal();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2517
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2518
02bb8761fcce Initial load
duke
parents:
diff changeset
  2519
        public boolean isTransient() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2520
            if (forceTransient) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2521
            return member.isTransient();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2522
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2523
02bb8761fcce Initial load
duke
parents:
diff changeset
  2524
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2525
         * Return the value of this member. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2526
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2527
        public String getValue() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2528
            return value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2529
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2530
02bb8761fcce Initial load
duke
parents:
diff changeset
  2531
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2532
         * Return true if this member represents an inner class declaration,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2533
         * false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2534
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2535
        public boolean isInnerClassDeclaration() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2536
            return innerClassDecl;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2537
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2538
02bb8761fcce Initial load
duke
parents:
diff changeset
  2539
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2540
         * Return true if this member represents a constant.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2541
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2542
        public boolean isConstant () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2543
            return constant;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2544
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2545
02bb8761fcce Initial load
duke
parents:
diff changeset
  2546
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2547
         * Return the string representation of this constant.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2548
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2549
        public String toString() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2550
02bb8761fcce Initial load
duke
parents:
diff changeset
  2551
            String result = type.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2552
02bb8761fcce Initial load
duke
parents:
diff changeset
  2553
            if (value != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2554
                result += (" = " + value);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2555
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2556
02bb8761fcce Initial load
duke
parents:
diff changeset
  2557
            return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2558
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2559
02bb8761fcce Initial load
duke
parents:
diff changeset
  2560
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2561
         * Convert all invalid types to valid ones.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2562
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2563
        protected void swapInvalidTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2564
            if (type.getStatus() != STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2565
                type = getValidType(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2566
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2567
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2568
02bb8761fcce Initial load
duke
parents:
diff changeset
  2569
        protected void setTransient() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2570
            if (! isTransient()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2571
                forceTransient = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2572
                if (vis.length() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2573
                    vis = vis + " transient";
02bb8761fcce Initial load
duke
parents:
diff changeset
  2574
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2575
                    vis = "transient";
02bb8761fcce Initial load
duke
parents:
diff changeset
  2576
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2577
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2578
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2579
02bb8761fcce Initial load
duke
parents:
diff changeset
  2580
        protected MemberDefinition getMemberDefinition() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2581
            return member;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2582
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2583
02bb8761fcce Initial load
duke
parents:
diff changeset
  2584
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2585
         * Release all resources.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2586
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2587
        public void destroy () {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2588
            if (type != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2589
                type.destroy();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2590
                type = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2591
                vis = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2592
                value = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2593
                name = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2594
                idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2595
                member = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2596
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2597
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2598
02bb8761fcce Initial load
duke
parents:
diff changeset
  2599
        private Type type;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2600
        private String vis;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2601
        private String value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2602
        private String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2603
        private String idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2604
        private boolean innerClassDecl;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2605
        private boolean constant;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2606
        private MemberDefinition member;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2607
        private boolean forceTransient;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2608
02bb8761fcce Initial load
duke
parents:
diff changeset
  2609
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2610
         * Create a new Member object.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2611
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2612
        public Member(MemberDefinition member,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2613
                      String value,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2614
                      ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2615
                      CompoundType enclosing) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2616
            this.member = member;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2617
            this.value = value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2618
            forceTransient = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2619
            innerClassDecl = member.getInnerClass() != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2620
02bb8761fcce Initial load
duke
parents:
diff changeset
  2621
            // If we are not an inner class, finish initializing now.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2622
            // Otherwise, wait until outer class is finished, then
02bb8761fcce Initial load
duke
parents:
diff changeset
  2623
            // call init to avoid potential recursion problems...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2624
02bb8761fcce Initial load
duke
parents:
diff changeset
  2625
            if (!innerClassDecl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2626
                init (stack,enclosing);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2627
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2628
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2629
02bb8761fcce Initial load
duke
parents:
diff changeset
  2630
        public void init (ContextStack stack, CompoundType enclosing) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2631
02bb8761fcce Initial load
duke
parents:
diff changeset
  2632
            constant = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2633
            name = member.getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2634
            vis = getVisibilityString(member);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2635
            idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2636
02bb8761fcce Initial load
duke
parents:
diff changeset
  2637
            // Add self to stack...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2638
02bb8761fcce Initial load
duke
parents:
diff changeset
  2639
            int contextCode = ContextStack.MEMBER;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2640
            stack.setNewContextCode(contextCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2641
02bb8761fcce Initial load
duke
parents:
diff changeset
  2642
            // Check for special contextCodes...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2643
02bb8761fcce Initial load
duke
parents:
diff changeset
  2644
            if (member.isVariable()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2645
                if (value != null && member.isConstant()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2646
                    contextCode = ContextStack.MEMBER_CONSTANT;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2647
                    this.constant = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2648
                } else if (member.isStatic()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2649
                    contextCode = ContextStack.MEMBER_STATIC;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2650
                } else if (member.isTransient()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2651
                    contextCode = ContextStack.MEMBER_TRANSIENT;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2652
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2653
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2654
02bb8761fcce Initial load
duke
parents:
diff changeset
  2655
            stack.setNewContextCode(contextCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2656
            stack.push(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2657
02bb8761fcce Initial load
duke
parents:
diff changeset
  2658
            type = makeType(member.getType(),null,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2659
02bb8761fcce Initial load
duke
parents:
diff changeset
  2660
            if (type == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
  2661
                (!innerClassDecl &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2662
                 !member.isStatic() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2663
                 !member.isTransient() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  2664
                 !assertNotImpl(type,false,stack,enclosing,true))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2665
                stack.pop(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2666
                throw new CompilerError("");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2667
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2668
02bb8761fcce Initial load
duke
parents:
diff changeset
  2669
            // Clean up primitive constant values...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2670
02bb8761fcce Initial load
duke
parents:
diff changeset
  2671
            if (constant && type.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2672
                if (type.isType(TYPE_LONG) || type.isType(TYPE_FLOAT) || type.isType(TYPE_DOUBLE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2673
                    int length = value.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2674
                    char lastChar = value.charAt(length-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2675
                    if (!Character.isDigit(lastChar)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2676
                        this.value = value.substring(0,length-1);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2677
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2678
                } else if (type.isType(TYPE_BOOLEAN)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2679
                    value = value.toUpperCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2680
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2681
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2682
            if (constant && type.isType(TYPE_STRING)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2683
                value = "L" + value;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2684
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2685
            stack.pop(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2686
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2687
02bb8761fcce Initial load
duke
parents:
diff changeset
  2688
        public void setIDLName (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2689
            this.idlName = name;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2690
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2691
02bb8761fcce Initial load
duke
parents:
diff changeset
  2692
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2693
         * Cloning is supported by returning a shallow copy of this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
  2694
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2695
        protected Object clone() {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2696
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2697
                return super.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2698
            } catch (CloneNotSupportedException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2699
                throw new Error("clone failed");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2700
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2701
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2702
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2703
}