corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
child 13052 63c6c4c360e1
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
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
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.util.Locale;
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.CompilerError;
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.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.impl.util.RepositoryId;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 * IDLNames provides static utility methods to perform the IDL
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * name mappings specified in Chapter 5 of the Java Language
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * to IDL specification.
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
public class IDLNames implements sun.rmi.rmic.iiop.Constants {
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
     * Used to convert ascii to hex.
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    public static final byte ASCII_HEX[] =      {
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
        (byte)'0',
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
        (byte)'1',
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
        (byte)'2',
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
        (byte)'3',
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
        (byte)'4',
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
        (byte)'5',
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
        (byte)'6',
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
        (byte)'7',
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
        (byte)'8',
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        (byte)'9',
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        (byte)'A',
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        (byte)'B',
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
        (byte)'C',
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        (byte)'D',
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        (byte)'E',
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        (byte)'F',
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    };
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
     * Convert a name. The nameContext argument MUST be pre-filled with
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
     * all names from the appropriate context (e.g. all the method names
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
     * in a given class). The names must not have had any IDL conversions
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
     * applied.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
     * Section 28.3.2.2
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
     * Section 28.3.2.3
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
     * Section 28.3.2.4
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
     * Section 28.3.2.7 (member and method names only)
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    public static String getMemberOrMethodName (NameContext nameContext,
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
                                                String name,
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
                                                BatchEnvironment env) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        // Check namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        String result = (String) env.namesCache.get(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            // 28.3.2.7 Case sensitive member names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            // Note:    This must be done before any of
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            //          the other conversions!
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
            result = nameContext.get(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
            // 28.3.2.3 Leading underscores...
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            result = convertLeadingUnderscores(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            // 28.3.2.2 IDL keywords (NOTE: must be done
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            // after leading underscore conversion because
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
            // the mangling for IDL keywords creates a
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
            // leading underscore!)...
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
            result = convertIDLKeywords(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            // 28.3.2.4 Illegal IDL identifier characters...
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            result = convertToISOLatin1(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            // Add to namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            env.namesCache.put(name,result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        return result;
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
     * Convert names with illegal IDL identifier characters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
     * Section 28.3.2.4
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    public static String convertToISOLatin1 (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        // First, replace any escape sequences...
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        String result = replace(name,"x\\u","U");
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        result = replace(result,"x\\U","U");
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
        // Now see if we have any remaining illegal characters (see
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        // RepositoryId.IDL_IDENTIFIER_CHARS array)...
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        int length = result.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        StringBuffer buffer = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        for (int i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
            char c = result.charAt(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
            if (c > 255 || RepositoryId.IDL_IDENTIFIER_CHARS[c] == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                // We gotta convert. Have we already started?
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
                if (buffer == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
                    // No, so get set up...
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
                    buffer = new StringBuffer(result.substring(0,i));
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
                // Convert the character into the IDL escape syntax...
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
                buffer.append("U");
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
                buffer.append((char)ASCII_HEX[(c & 0xF000) >>> 12]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                buffer.append((char)ASCII_HEX[(c & 0x0F00) >>> 8]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                buffer.append((char)ASCII_HEX[(c & 0x00F0) >>> 4]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                buffer.append((char)ASCII_HEX[(c & 0x000F)]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                if (buffer != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                    buffer.append(c);
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        if (buffer != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
            result = buffer.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
     * Convert names which collide with IDL keywords.
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
     * Section 28.3.2.5
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    public static String convertIDLKeywords (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        for (int i = 0; i < IDL_KEYWORDS.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            if (name.equalsIgnoreCase(IDL_KEYWORDS[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                return "_" + name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
     * Convert names which have leading underscores
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     * Section 28.3.2.3
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    public static String convertLeadingUnderscores (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
        if (name.startsWith("_")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
            return "J" + name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
     * Convert a type name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
     * Section 28.3.2.5
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
     * Section 28.3.2.7 (class or interface names only)
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
     * Throws exception if fails 28.3.2.7.
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    public static String getClassOrInterfaceName (Identifier id,
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
                                                  BatchEnvironment env) throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
        // Get the type and package name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        String typeName = id.getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        String packageName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        if (id.isQualified()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
            packageName = id.getQualifier().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        // Check namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        String result = (String) env.namesCache.get(typeName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
            // 28.3.2.5 Inner classes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            result = replace(typeName,". ","__");
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            // 28.3.2.4 Illegal identifier characters...
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            result = convertToISOLatin1(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            // 28.3.2.7 Case sensitive class or interface names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            NameContext context = NameContext.forName(packageName,false,env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
            context.assertPut(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
            // Run it through the name checks...
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
            result = getTypeOrModuleName(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
            // Add it to the namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
            env.namesCache.put(typeName,result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
     * Convert an Exception name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
     * Section 28.3.7.2    (see ValueType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    public static String getExceptionName (String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        String result = idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
// d.11315 Incorrectly mangled exception names
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        if (idlName.endsWith(EXCEPTION_SUFFIX)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
            // Remove "Exception" and append "Ex". Strip leading underscore
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
            // in case the idlName is exactly "_Exception"...
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
            result = stripLeadingUnderscore(idlName.substring(0,idlName.lastIndexOf(EXCEPTION_SUFFIX)) + EX_SUFFIX);
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
            result = idlName + EX_SUFFIX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
     * Convert a qualified Identifier into an array of IDL names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
     * Section 28.3.2.1    (see CompoundType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
     * Throws exception if fails 28.3.2.7.
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    public static String[] getModuleNames (Identifier theID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
                                           boolean boxIt,
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
                                           BatchEnvironment env) throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        String[] result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
        if (theID.isQualified()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            // Extract the qualifier...
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
            Identifier id = theID.getQualifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
            // 28.3.2.7 Case sensitive module names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
            env.modulesContext.assertPut(id.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
            // Count them...
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
            int count = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
            Identifier current = id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
            while (current.isQualified()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
                current = current.getQualifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
                count++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
            result = new String[count];
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
            int index = count-1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
            current = id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
            // Now walk them and fill our array (backwards)...
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
            for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
                String item = current.getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
                // Check namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
                String cachedItem = (String) env.namesCache.get(item);
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
                if (cachedItem == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
                    // 28.3.2.4 Illegal identifier characters...
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
                    cachedItem = convertToISOLatin1(item);
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
                    // Run it through the name checks...
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
                    cachedItem = getTypeOrModuleName(cachedItem);
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
                    // Add it to the namesCache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                    env.namesCache.put(item,cachedItem);
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                result[index--] = cachedItem;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
                current = current.getQualifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        // If it is supposed to be "boxed", prepend
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        // IDL_BOXEDIDL_MODULE...
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        if (boxIt) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                result = IDL_BOXEDIDL_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
            String[] boxed = new String[result.length+IDL_BOXEDIDL_MODULE.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            System.arraycopy(IDL_BOXEDIDL_MODULE,0,boxed,0,IDL_BOXEDIDL_MODULE.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
            System.arraycopy(result,0,boxed,IDL_BOXEDIDL_MODULE.length,result.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            result = boxed;
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
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
     * Get an array name with the specified dimensions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
     * Section 28.3.6  (see ArrayType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
    public static String getArrayName (Type theType, int arrayDimension) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
        StringBuffer idlName = new StringBuffer(64);
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        // Prefix with seq<n>_...
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
        idlName.append(IDL_SEQUENCE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        idlName.append(Integer.toString(arrayDimension));
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
        idlName.append("_");
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        // Add the type name. We need to map any spaces in the
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        // name to "_"...
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        idlName.append(replace(stripLeadingUnderscore(theType.getIDLName())," ","_"));
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        // And we're done...
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
        return idlName.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
     * Get an array module names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
    public static String[] getArrayModuleNames (Type theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        String[] moduleName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        String[] typeModule = theType.getIDLModuleNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        int typeModuleLength = typeModule.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
        // Does the type have a module?
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
        if (typeModuleLength == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            // Nope, so just use the sequence module...
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
            moduleName = IDL_SEQUENCE_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
            // Yes, so gotta concatenate...
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
            moduleName = new String[typeModuleLength + IDL_SEQUENCE_MODULE.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
            System.arraycopy(IDL_SEQUENCE_MODULE,0,moduleName,0,IDL_SEQUENCE_MODULE.length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
            System.arraycopy(typeModule,0,moduleName,IDL_SEQUENCE_MODULE.length,typeModuleLength);
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        return moduleName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
    private static int getInitialAttributeKind (CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                                                BatchEnvironment env) throws ClassNotFound {
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        int result = ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        // First make sure it is not a constructor...
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        if (!method.isConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
            // Now check exceptions. It may not throw any checked
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
            // exception other than RemoteException or one of its
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
            // subclasses...
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
            boolean validExceptions = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            ClassType[] exceptions = method.getExceptions();
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
            if (exceptions.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
                    if (exceptions[i].isCheckedException() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                        !exceptions[i].isRemoteExceptionOrSubclass()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
                        validExceptions = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
                // If this is a ValueType, it is ok to not have any exceptions,
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                // otherwise this method does not qualify...
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
                validExceptions = method.getEnclosing().isType(TYPE_VALUE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
            if (validExceptions) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                String name = method.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                int nameLength = name.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
                int argCount = method.getArguments().length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
                Type returnType = method.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
                boolean voidReturn = returnType.isType(TYPE_VOID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
                boolean booleanReturn = returnType.isType(TYPE_BOOLEAN);
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
                // It's a getter if name starts with "get" and it has no arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                // and a return type that is not void...
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
                if (name.startsWith("get") && nameLength > 3 && argCount == 0 && !voidReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
                    result = ATTRIBUTE_GET;
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                    // It's a getter if name starts with "is" and it has no arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                    // and a boolean return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
                    if (name.startsWith("is") && nameLength > 2 && argCount == 0 && booleanReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                        result = ATTRIBUTE_IS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
                        // It's a setter if name starts with "set" and it has 1 argument
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
                        // and a void return type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
                        if (name.startsWith("set") && nameLength > 3 && argCount == 1 && voidReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
                            result = ATTRIBUTE_SET;
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    private static void setAttributeKinds (CompoundType.Method[] methods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
                                           int[] kinds,
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                                           String[] names) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        int count = methods.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        // Strip the prefixes off of the attribute names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            switch (kinds[i]) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                case ATTRIBUTE_GET: names[i] = names[i].substring(3); break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                case ATTRIBUTE_IS: names[i] = names[i].substring(2); break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
                case ATTRIBUTE_SET: names[i] = names[i].substring(3); break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        // Now, we need to look at all the IS attributes to see
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        // if there is a corresponding getter or setter which has
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        // a different return type. If so, mark it as not an
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        // attribute. Do this before checking for invalid setters...
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
            if (kinds[i] == ATTRIBUTE_IS) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
                for (int j = 0; j < count; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
                    if (j != i &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
                        (kinds[j] == ATTRIBUTE_GET || kinds[j] == ATTRIBUTE_SET) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                        names[i].equals(names[j])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                        // We have matching getter or setter. Do the types match?
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                        Type isType = methods[i].getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                        Type targetType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                        if (kinds[j] == ATTRIBUTE_GET) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
                            targetType = methods[j].getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
                            targetType = methods[j].getArguments()[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                        if (!isType.equals(targetType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                            // No, so forget this guy as an attribute...
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
                            kinds[i] = ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
                            names[i] = methods[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
        // Now, we need to look at all the setters to see if there
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
        // is a corresponding getter. If not, it is not a setter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
        // If there is, change the getter type to _RW and set the
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
        // pair index...
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
            if (kinds[i] == ATTRIBUTE_SET) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
                int getterIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
                int isGetterIndex = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
                // First look for is-getters, then for getters.
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                // This is preferred for boolean attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
                for (int j = 0; j < count; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                    if (j != i && names[i].equals(names[j])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
                        // Yep, is the return type of the getter the same
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                        // as the argument type of the setter?
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                        Type getterReturn = methods[j].getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                        Type setterArg = methods[i].getArguments()[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                        if (getterReturn.equals(setterArg)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                            if (kinds[j] == ATTRIBUTE_IS) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
                                isGetterIndex = j;
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                                // continue looking for another getter
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
                            } else if (kinds[j] == ATTRIBUTE_GET) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
                                getterIndex = j;
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                                // continue looking for an is-getter
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
                if (getterIndex > -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
                    if (isGetterIndex > -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
                        // We have both, a boolean is-getter and a boolean getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
                        // Use the is-getter and drop the getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
                        // We have a matching getter. Change it to a read-write type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
                        kinds[isGetterIndex] = ATTRIBUTE_IS_RW;
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
                        // Now set the pair index for both the getter and the setter...
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
                        methods[isGetterIndex].setAttributePairIndex(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
                        methods[i].setAttributePairIndex(isGetterIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
                        // We found a better matching is-getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
                        // Forget this other getter as an attribute.
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
                        kinds[getterIndex] = ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
                        names[getterIndex] = methods[getterIndex].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
                        // We only have one getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
                        // We have a matching getter. Change it to a read-write type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
                        kinds[getterIndex] = ATTRIBUTE_GET_RW;
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                        // Now set the pair index for both the getter and the setter...
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
                        methods[getterIndex].setAttributePairIndex(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
                        methods[i].setAttributePairIndex(getterIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
                    if (isGetterIndex > -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
                        // We only have one is-getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
                        // We have a matching getter. Change it to a read-write type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
                        kinds[isGetterIndex] = ATTRIBUTE_IS_RW;
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
                        // Now set the pair index for both the getter and the setter...
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
                        methods[isGetterIndex].setAttributePairIndex(i);
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
                        methods[i].setAttributePairIndex(isGetterIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
                        // We did not find a matching getter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
                        // Forget this setter as an attribute.
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
                        kinds[i] = ATTRIBUTE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
                        names[i] = methods[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
        // Finally, do the case conversion and set the
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
        // attribute kinds for each method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            if (kinds[i] != ATTRIBUTE_NONE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
                String name = names[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
                // Is the first character upper case?
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
                if (Character.isUpperCase(name.charAt(0))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
                    // Yes, is the second?
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                    if (name.length() == 1 || Character.isLowerCase(name.charAt(1))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                        // No, so convert the first character to lower case...
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                        StringBuffer buffer = new StringBuffer(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                        buffer.setCharAt(0,Character.toLowerCase(name.charAt(0)));
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                        names[i] = buffer.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
            methods[i].setAttributeKind(kinds[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
     * Set all the method names in a given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
     * Section 28.3.2.7    (see CompoundType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
     * Section 28.3.2.7
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
     * Section 28.3.4.3 (RemoteType/AbstractType only).
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
    public static void setMethodNames (CompoundType container,
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
                                       CompoundType.Method[] allMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
                                       BatchEnvironment env)
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
        throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
        // This method implements the following name mangling sequence:
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        //   1. If methods belong to a Remote interface, identify
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
        //      those which qualify as an attribute under 28.3.4.3.
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
        //      Those that do are referred to as 'attributes' below;
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        //      those that do not are referred to as 'methods'.
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        //   2. Apply the 28.3.4.3 manglings, except "__", to all
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        //      attribute names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
        //   3. Apply all 28.3 manglings, except 28.3.2.7, to all names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
        //   4. Apply 28.3.2.7 manglings to all method names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        //   5. Compare each attribute name to each method name. For
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        //      any which compare equal, append "__" to the attribute
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
        //      name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
        //   6. Compare each name (attribute and method) to all others.
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
        //      If any compare equal, throw an Exception with the
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
        //      conflicting name as the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
        int count = allMethods.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
        if (count == 0) return;
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        // Make an array of all the method names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
        String[] names = new String[count];
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
            names[i] = allMethods[i].getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
        // Are we dealing with a RemoteType, AbstractType, or ValueType?
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
        CompoundType enclosing = allMethods[0].getEnclosing();
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
        if (enclosing.isType(TYPE_REMOTE) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
            enclosing.isType(TYPE_ABSTRACT) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
            enclosing.isType(TYPE_VALUE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
            // Yes, so we must do the 28.3.4.3 attribute mapping. First, get
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
            // the initial attribute kind of each method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
            int[] kinds = new int[count];
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
            for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
                kinds[i] = getInitialAttributeKind(allMethods[i],env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
            // Now set the attribute kind for each method and do the
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
            // 28.3.4.3 name mangling...
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
            setAttributeKinds(allMethods,kinds,names);
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
        // Make and populate a new context from our names array...
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
        NameContext context = new NameContext(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
            context.put(names[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
        // Apply the appropriate 28.3 manglings to all the names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
        boolean haveConstructor = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
            if (!allMethods[i].isConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
                names[i] = getMemberOrMethodName(context,names[i],env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
                names[i] = IDL_CONSTRUCTOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
                haveConstructor = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
        // Now do the 28.3.2.7 mangling for method name collisions...
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        // Do this in two passes so that we don't change one during
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
        // the detection of collisions and then miss a real one...
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        boolean overloaded[] = new boolean[count];
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
            overloaded[i] = (!allMethods[i].isAttribute() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
                             !allMethods[i].isConstructor() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
                         doesMethodCollide(names[i],allMethods[i],allMethods,names,true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
        convertOverloadedMethods(allMethods,names,overloaded);
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
        // Now do the same mangling for constructor name collisions...
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
            overloaded[i] = (!allMethods[i].isAttribute() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
                             allMethods[i].isConstructor() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
                             doesConstructorCollide(names[i],allMethods[i],allMethods,names,true));
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        convertOverloadedMethods(allMethods,names,overloaded);
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
        // Now do the 28.3.4.3 mangling for attribute name collisions...
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
                CompoundType.Method method = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
            // If this is an attribute name, does it collide with a method?
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
            if (method.isAttribute() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
                doesMethodCollide(names[i],method,allMethods,names,true)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
                // Yes, so add double underscore...
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                    names[i] += "__";
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
        // Do the same mangling for any constructors which collide with
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
        // methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
        if (haveConstructor) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
            CompoundType.Method method = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
                // Is this a constructor which collides with a method?
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
                if (method.isConstructor() &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
                    doesConstructorCollide(names[i],method,allMethods,names,false)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
                // Yes, so add double underscore...
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
                names[i] += "__";
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
        // Now see if we have a collision with the container name (28.3.2.9).
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        String containerName = container.getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
            if (names[i].equalsIgnoreCase(containerName)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
                // Do not add underscore to attributes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
                // Otherwise getFoo will turn into _get_foo_.
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
                if (! allMethods[i].isAttribute()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
                    names[i] += "_";
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
        // Now see if we have any collisions (28.3.2.9). If we do,
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        // it's an error.  Note: a get/set pair does not collide.
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
            // Does it collide with any other name?
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
            if (doesMethodCollide(names[i],allMethods[i],allMethods,names,false)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
                // Yes, so bail...
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
                throw new Exception(allMethods[i].toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
        // Ok. We have unique names. Create the appropriate 'wire' name
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        // for each and set as the 'idl' name. If it is an attribute, also
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
        // set the attribute name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        for (int i = 0; i < count; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
            CompoundType.Method method = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
            String wireName = names[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
            if (method.isAttribute()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
                wireName = ATTRIBUTE_WIRE_PREFIX[method.getAttributeKind()] +
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
                    stripLeadingUnderscore(wireName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
                String attributeName = names[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
                method.setAttributeName(attributeName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
            method.setIDLName(wireName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
    private static String stripLeadingUnderscore (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
        if (name != null && name.length() > 1
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
            && name.charAt(0) == '_')
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
            return name.substring(1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
    private static String stripTrailingUnderscore (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
        if (name != null && name.length() > 1 &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
            name.charAt(name.length() - 1) == '_')
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
            return name.substring(0, name.length() - 1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
    private static void convertOverloadedMethods(CompoundType.Method[] allMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
                                                 String[] names,
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
                                                 boolean[] overloaded) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
        for (int i = 0; i < names.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
            // Do we need to mangle it?
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
            if (overloaded[i]) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
                // Yes, so add arguments...
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
                CompoundType.Method method = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
                Type[] args = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
                for (int k = 0; k < args.length; k++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
                                // Add the separator...
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
                    names[i] += "__";
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
                                // Get the fully qualified IDL name, without the "::"
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
                                // prefix...
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
                    String argIDLName = args[k].getQualifiedIDLName(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
                                // Replace any occurances of "::_" with "_" to
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
                                // undo any IDL keyword mangling and do next step
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
                                // at the same time...
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
                    argIDLName = replace(argIDLName,"::_","_");
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
                                // Replace any occurances of "::" with "_"...
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
                    argIDLName = replace(argIDLName,"::","_");
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
                                // Replace any occurances of " " with "_"...
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
                    argIDLName = replace(argIDLName," ","_");
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
                                // Add the argument type name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
                    names[i] += argIDLName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
                if (args.length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
                    names[i] += "__";
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
                // Remove any IDL keyword mangling...
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
                names[i] = stripLeadingUnderscore(names[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
    private static boolean doesMethodCollide (String name,
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
                                              CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
                                              CompoundType.Method[] allMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
                                              String[] allNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                                              boolean ignoreAttributes) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
        // Scan all methods looking for a match...
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
        for (int i = 0; i < allMethods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
            CompoundType.Method target = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
            if (method != target &&                                 // Not same instance
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
                !target.isConstructor() &&                      // Not a constructor
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
                (!ignoreAttributes || !target.isAttribute()) && // Correct kind
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
                name.equals(allNames[i])) {                         // Same names
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
                // Are we looking at a get/set pair?
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
                int kind1 = method.getAttributeKind();
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
                int kind2 = target.getAttributeKind();
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
                if ((kind1 != ATTRIBUTE_NONE && kind2 != ATTRIBUTE_NONE) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
                    ((kind1 == ATTRIBUTE_SET && kind2 != ATTRIBUTE_SET) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
                     (kind1 != ATTRIBUTE_SET && kind2 == ATTRIBUTE_SET) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
                     // one is a is-getter/setter pair and the other is just a getter
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
                     (kind1 == ATTRIBUTE_IS_RW && kind2 == ATTRIBUTE_GET) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
                     (kind1 == ATTRIBUTE_GET && kind2 == ATTRIBUTE_IS_RW))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                    // Yes, so ignore it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
                    // No, so we have a collision...
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
                    return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    private static boolean doesConstructorCollide (String name,
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
                                                   CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
                                                   CompoundType.Method[] allMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
                                                   String[] allNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
                                                   boolean compareConstructors) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
        // Scan all methods looking for a match...
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        for (int i = 0; i < allMethods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
            CompoundType.Method target = allMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
            if (method != target &&                                     // Not same instance
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
                (target.isConstructor() == compareConstructors) &&  // Correct kind
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
                name.equals(allNames[i])) {                             // Same names
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
                // We have a collision...
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
     * Set all the member names in a given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
     * Section 28.3.2.7    (see CompoundType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
     * Section 28.3.2.7
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
    public static void setMemberNames (CompoundType container,
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
                                       CompoundType.Member[] allMembers,
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
                                       CompoundType.Method[] allMethods,
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
                                       BatchEnvironment env)
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        throws Exception {
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
        // Make and populate a new context...
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        NameContext context = new NameContext(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
        for (int i = 0; i < allMembers.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
            context.put(allMembers[i].getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
        // Now set all the idl names...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
        for (int i = 0; i < allMembers.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
            CompoundType.Member member = allMembers[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
            String idlName = getMemberOrMethodName(context,member.getName(),env);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
            member.setIDLName(idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
        // First see if we have a collision with the container name (28.3.2.9).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
        String containerName = container.getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
        for (int i = 0; i < allMembers.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
            String name = allMembers[i].getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
            if (name.equalsIgnoreCase(containerName)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
                // REVISIT - How is this different than line 788
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
                allMembers[i].setIDLName(name+"_");
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
        // Check for collisions between member names...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
        for (int i = 0; i < allMembers.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
            String name = allMembers[i].getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
            for (int j = 0; j < allMembers.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
                if (i != j && allMembers[j].getIDLName().equals(name)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
                    // Collision...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
                    throw new Exception(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
        // Now check for collisions between member names and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
        // method names...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
        boolean changed;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
        do {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
            changed = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
            for (int i = 0; i < allMembers.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
                String name = allMembers[i].getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
                for (int j = 0; j < allMethods.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
                    if (allMethods[j].getIDLName().equals(name)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
                        // Collision, so append "_" to member name...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
                        allMembers[i].setIDLName(name+"_");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
                        changed = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
        } while (changed);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
     * Get the name for the specified type code.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
     * Section 28.3..3     (see PrimitiveType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
     * Section 28.3.5.10   (see SpecialClassType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
     * Section 28.3.4.1    (see SpecialInterfaceType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
     * Section 28.3.10.1   (see SpecialInterfaceType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
     * Section 28.3.10.2   (see SpecialClassType)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
    public static String getTypeName(int typeCode, boolean isConstant) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
        String idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
        case TYPE_VOID:             idlName = IDL_VOID; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
        case TYPE_BOOLEAN:          idlName = IDL_BOOLEAN; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
        case TYPE_BYTE:             idlName = IDL_BYTE; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
        case TYPE_CHAR:             idlName = IDL_CHAR; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
        case TYPE_SHORT:            idlName = IDL_SHORT; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
        case TYPE_INT:              idlName = IDL_INT; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
        case TYPE_LONG:             idlName = IDL_LONG; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
        case TYPE_FLOAT:            idlName = IDL_FLOAT; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
        case TYPE_DOUBLE:           idlName = IDL_DOUBLE; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
        case TYPE_ANY:                  idlName = IDL_ANY; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
        case TYPE_CORBA_OBJECT: idlName = IDL_CORBA_OBJECT; break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
        case TYPE_STRING:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
            {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
                if (isConstant) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
                    idlName = IDL_CONSTANT_STRING;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
                    idlName = IDL_STRING;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
        return idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
     * Create a qualified name.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
    public static String getQualifiedName (String[] idlModuleNames, String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
        String result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
        if (idlModuleNames != null && idlModuleNames.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
            for (int i = 0; i < idlModuleNames.length;i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
                if (i == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
                    result = idlModuleNames[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
                    result += IDL_NAME_SEPARATOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
                    result += idlModuleNames[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
            result += IDL_NAME_SEPARATOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
            result += idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
            result = idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
     * Replace substrings
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
     * @param source The source string.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
     * @param match The string to search for within the source string.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
     * @param replace The replacement for any matching components.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
     * @return
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
    public static String replace (String source, String match, String replace) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
        int index = source.indexOf(match,0);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
        if (index >=0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
            // We have at least one match, so gotta do the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
            // work...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
            StringBuffer result = new StringBuffer(source.length() + 16);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
            int matchLength = match.length();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
            int startIndex = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
            while (index >= 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
                result.append(source.substring(startIndex,index));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
                result.append(replace);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
                startIndex = index + matchLength;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
                index = source.indexOf(match,startIndex);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
            // Grab the last piece, if any...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
            if (startIndex < source.length()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
                result.append(source.substring(startIndex));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
            return result.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
            // No matches, just return the source...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
            return source;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
     * Get an IDL style repository id for
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
    public static String getIDLRepositoryID (String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
        return  IDL_REPOSITORY_ID_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
            replace(idlName,"::", "/") +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
            IDL_REPOSITORY_ID_VERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
    // Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
     * Convert a type or module name.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
     * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
     * Section 28.3.2.2
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
     * Section 28.3.2.3
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
    private static String getTypeOrModuleName (String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
        // 28.3.2.3 Leading underscores...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
        String result = convertLeadingUnderscores(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
        // 28.3.2.2 IDL keywords (NOTE: must be done
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
        // after leading underscore conversion because
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
        // the mangling for IDL keywords creates a
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
        // leading underscore!)...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
        return convertIDLKeywords(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
}