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