407 |
407 |
408 /* ************************************************************************* |
408 /* ************************************************************************* |
409 * Class name generation |
409 * Class name generation |
410 **************************************************************************/ |
410 **************************************************************************/ |
411 |
411 |
|
412 |
|
413 private Map<Pair<Name, Name>, Integer> localClassNameIndexes = new HashMap<>(); |
|
414 |
412 /** Return name of local class. |
415 /** Return name of local class. |
413 * This is of the form {@code <enclClass> $ n <classname> } |
416 * This is of the form {@code <enclClass> $ n <classname> } |
414 * where |
417 * where |
415 * enclClass is the flat name of the enclosing class, |
418 * enclClass is the flat name of the enclosing class, |
416 * classname is the simple name of the local class |
419 * classname is the simple name of the local class |
417 */ |
420 */ |
418 Name localClassName(ClassSymbol c) { |
421 Name localClassName(ClassSymbol c) { |
419 for (int i=1; ; i++) { |
422 Name enclFlatname = c.owner.enclClass().flatname; |
420 Name flatname = names. |
423 String enclFlatnameStr = enclFlatname.toString(); |
421 fromString("" + c.owner.enclClass().flatname + |
424 Pair<Name, Name> key = new Pair<>(enclFlatname, c.name); |
422 syntheticNameChar + i + |
425 Integer index = localClassNameIndexes.get(key); |
423 c.name); |
426 for (int i = (index == null) ? 1 : index; ; i++) { |
424 if (compiled.get(flatname) == null) return flatname; |
427 Name flatname = names.fromString(enclFlatnameStr |
425 } |
428 + syntheticNameChar + i + c.name); |
|
429 if (compiled.get(flatname) == null) { |
|
430 localClassNameIndexes.put(key, i + 1); |
|
431 return flatname; |
|
432 } |
|
433 } |
|
434 } |
|
435 |
|
436 void clearLocalClassNameIndexes(ClassSymbol c) { |
|
437 localClassNameIndexes.remove(new Pair<>( |
|
438 c.owner.enclClass().flatname, c.name)); |
426 } |
439 } |
427 |
440 |
428 public void newRound() { |
441 public void newRound() { |
429 compiled.clear(); |
442 compiled.clear(); |
|
443 localClassNameIndexes.clear(); |
430 } |
444 } |
431 |
445 |
432 /* ************************************************************************* |
446 /* ************************************************************************* |
433 * Type Checking |
447 * Type Checking |
434 **************************************************************************/ |
448 **************************************************************************/ |