src/share/classes/sun/rmi/rmic/iiop/IDLNames.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 371
e324dfb90c9e
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

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

mercurial