diff -r 44eaac2b4501 -r d402db1005ad src/share/classes/com/sun/tools/javac/code/Printer.java --- a/src/share/classes/com/sun/tools/javac/code/Printer.java Wed May 20 19:10:06 2009 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java Thu May 21 10:56:36 2009 +0100 @@ -43,6 +43,9 @@ */ public abstract class Printer implements Type.Visitor, Symbol.Visitor { + List seenCaptured = List.nil(); + static final int PRIME = 997; // largest prime less than 1000 + /** * This method should be overriden in order to provide proper i18n support. * @@ -54,7 +57,18 @@ protected abstract String localize(Locale locale, String key, Object... args); /** - * Create a printer with default i18n support provided my Messages. + * Maps a captured type into an unique identifier. + * + * @param t the captured type for which an id is to be retrieved + * @param locale locale settings + * @return unique id representing this captured type + */ + protected abstract String capturedVarId(CapturedType t, Locale locale); + + /** + * Create a printer with default i18n support provided by Messages. By default, + * captured types ids are generated using hashcode. + * * @param messages Messages class to be used for i18n * @return printer visitor instance */ @@ -63,6 +77,11 @@ @Override protected String localize(Locale locale, String key, Object... args) { return messages.getLocalizedString(locale, key, args); + } + + @Override + protected String capturedVarId(CapturedType t, Locale locale) { + return (t.hashCode() & 0xFFFFFFFFL) % PRIME + ""; }}; } @@ -120,9 +139,20 @@ @Override public String visitCapturedType(CapturedType t, Locale locale) { - return localize(locale, "compiler.misc.type.captureof", - (t.hashCode() & 0xFFFFFFFFL) % Type.CapturedType.PRIME, - visit(t.wildcard, locale)); + if (seenCaptured.contains(t)) + return localize(locale, "compiler.misc.type.captureof.1", + capturedVarId(t, locale)); + else { + try { + seenCaptured = seenCaptured.prepend(t); + return localize(locale, "compiler.misc.type.captureof", + capturedVarId(t, locale), + visit(t.wildcard, locale)); + } + finally { + seenCaptured = seenCaptured.tail; + } + } } @Override