changeset 304:d402db1005ad

6722234: javac diagnostics need better integration with the type-system Summary: Added RichDiagnosticFormatter which provides better formatting capabilities for javac types/symbols Reviewed-by: jjg
author mcimadamore
date Thu, 21 May 2009 10:56:36 +0100
parents 44eaac2b4501
children 84061bd68019
files src/share/classes/com/sun/tools/javac/code/Printer.java src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/main/JavaCompiler.java src/share/classes/com/sun/tools/javac/resources/compiler.properties src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java src/share/classes/com/sun/tools/javac/util/ForwardingDiagnosticFormatter.java src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java test/tools/javac/6304921/T6304921.java test/tools/javac/6304921/T6304921.out test/tools/javac/6491592/T6491592.out test/tools/javac/Diagnostics/6722234/T6722234a.java test/tools/javac/Diagnostics/6722234/T6722234a_1.out test/tools/javac/Diagnostics/6722234/T6722234a_2.out test/tools/javac/Diagnostics/6722234/T6722234b.java test/tools/javac/Diagnostics/6722234/T6722234b_1.out test/tools/javac/Diagnostics/6722234/T6722234b_2.out test/tools/javac/Diagnostics/6722234/T6722234c.java test/tools/javac/Diagnostics/6722234/T6722234c.out test/tools/javac/Diagnostics/6722234/T6722234d.java test/tools/javac/Diagnostics/6722234/T6722234d_1.out test/tools/javac/Diagnostics/6722234/T6722234d_2.out test/tools/javac/ExtendArray.java test/tools/javac/ExtendArray.out test/tools/javac/OverridePosition.java test/tools/javac/OverridePosition.out test/tools/javac/T4093617/T4093617.java test/tools/javac/T4093617/T4093617.out test/tools/javac/T5003235/T5003235c.java test/tools/javac/T5003235/T5003235c.out test/tools/javac/miranda/T4666866.java test/tools/javac/miranda/T4666866.out test/tools/javac/protectedAccess/ProtectedMemberAccess2.java test/tools/javac/protectedAccess/ProtectedMemberAccess3.java test/tools/javac/protectedAccess/ProtectedMemberAccess4.java
diffstat 36 files changed, 1124 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- 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<String, Locale>, Symbol.Visitor<String, Locale> {
 
+    List<Type> 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
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Thu May 21 10:56:36 2009 +0100
@@ -1008,11 +1008,10 @@
         @Override
         public String toString() {
             return "capture#"
-                + (hashCode() & 0xFFFFFFFFL) % PRIME
+                + (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
                 + " of "
                 + wildcard;
         }
-        static final int PRIME = 997;  // largest prime less than 1000
     }
 
     public static abstract class DelegatedType extends Type {
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu May 21 10:56:36 2009 +0100
@@ -391,6 +391,8 @@
             (options.get("shouldStopPolicy") != null)
             ? CompileState.valueOf(options.get("shouldStopPolicy"))
             : null;
+        if (options.get("oldDiags") == null)
+            log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
     }
 
     /* Switches:
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu May 21 10:56:36 2009 +0100
@@ -1165,3 +1165,64 @@
 compiler.err.enums.not.supported.in.source=\
     enums are not supported in -source {0}\n\
 (use -source 5 or higher to enable enums)
+
+########################################
+# Diagnostics for where clause implementation
+# used by the RichDiagnosticFormatter.
+########################################
+
+compiler.misc.type.null=\
+    <null>
+
+# X#n (where n is an int id) is disambiguated tvar name
+compiler.misc.type.var=\
+    {0}#{1}
+
+# CAP#n (where n is an int id) is an abbreviation for 'captured type'
+compiler.misc.captured.type=\
+    CAP#{0}
+
+# <INT#n> (where n is an int id) is an abbreviation for 'intersection type'
+compiler.misc.intersection.type=\
+    INT#{0}
+
+# where clause for captured type: contains upper ('extends {1}') and lower
+# ('super {2}') bound along with the wildcard that generated this captured type ({3})
+compiler.misc.where.captured=\
+    {0} extends {1} super: {2} from capture of {3}
+
+# compact where clause for captured type: contains upper ('extends {1}') along
+# with the wildcard that generated this captured type ({3})
+compiler.misc.where.captured.1=\
+    {0} extends {1} from capture of {3}
+
+# where clause for type variable: contains upper bound(s) ('extends {1}') along with
+# the kindname ({2}) and location ({3}) in which the typevar has been declared
+compiler.misc.where.typevar=\
+    {0} extends {1} declared in {2} {3}
+
+# compact where clause for type variable: contains the kindname ({2}) and location ({3})
+# in which the typevar has been declared
+compiler.misc.where.typevar.1=\
+    {0} declared in {2} {3}
+
+# where clause for type variable: contains all the upper bound(s) ('extends {1}')
+# of this intersection type
+compiler.misc.where.intersection=\
+    {0} extends {1}
+
+### Where clause headers ###
+compiler.misc.where.description.captured=\
+    where {0} is a fresh type-variable:
+compiler.misc.where.description.typevar=\
+    where {0} is a type-variable:
+compiler.misc.where.description.intersection=\
+    where {0} is an intersection type:
+compiler.misc.where.description.captured.1=\
+    where {0} are fresh type-variables:
+compiler.misc.where.description.typevar.1=\
+    where {0} are type-variables:
+compiler.misc.where.description.intersection.1=\
+    where {0} are intersection types:
+
+
--- a/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/util/AbstractDiagnosticFormatter.java	Thu May 21 10:56:36 2009 +0100
@@ -77,9 +77,11 @@
     protected int depth = 0;
 
     /**
-     * Printer instance to be used for formatting types/symbol
+     * All captured types that have been encountered during diagnostic formatting.
+     * This info is used by the FormatterPrinter in order to print friendly unique
+     * ids for captured types
      */
-    protected Printer printer;
+    private List<Type> allCaptured = List.nil();
 
     /**
      * Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object.
@@ -88,7 +90,6 @@
     protected AbstractDiagnosticFormatter(JavacMessages messages, SimpleConfiguration config) {
         this.messages = messages;
         this.config = config;
-        this.printer = new FormatterPrinter();
     }
 
     public String formatKind(JCDiagnostic d, Locale l) {
@@ -104,7 +105,7 @@
 
     @Override
     public String format(JCDiagnostic d, Locale locale) {
-        printer = new FormatterPrinter();
+        allCaptured = List.nil();
         return formatDiagnostic(d, locale);
     }
 
@@ -171,6 +172,9 @@
             return formatIterable(d, (Iterable<?>)arg, l);
         }
         else if (arg instanceof Type) {
+            if (!allCaptured.contains(arg)) {
+                allCaptured = allCaptured.append((Type)arg);
+            }
             return printer.visit((Type)arg, l);
         }
         else if (arg instanceof Symbol) {
@@ -291,6 +295,10 @@
                 d.getIntPosition() != Position.NOPOS;
     }
 
+    public boolean isRaw() {
+        return false;
+    }
+
     /**
      * Creates a string with a given amount of empty spaces. Useful for
      * indenting the text of a diagnostic message.
@@ -355,26 +363,26 @@
             String showSource = null;
             if ((showSource = options.get("showSource")) != null) {
                 if (showSource.equals("true"))
-                    visibleParts.add(DiagnosticPart.SOURCE);
+                    setVisiblePart(DiagnosticPart.SOURCE, true);
                 else if (showSource.equals("false"))
-                    visibleParts.remove(DiagnosticPart.SOURCE);
+                    setVisiblePart(DiagnosticPart.SOURCE, false);
             }
             String diagOpts = options.get("diags");
             if (diagOpts != null) {//override -XDshowSource
                 Collection<String> args = Arrays.asList(diagOpts.split(","));
                 if (args.contains("short")) {
-                    visibleParts.remove(DiagnosticPart.DETAILS);
-                    visibleParts.remove(DiagnosticPart.SUBDIAGNOSTICS);
+                    setVisiblePart(DiagnosticPart.DETAILS, false);
+                    setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
                 }
                 if (args.contains("source"))
-                    visibleParts.add(DiagnosticPart.SOURCE);
+                    setVisiblePart(DiagnosticPart.SOURCE, true);
                 if (args.contains("-source"))
-                    visibleParts.remove(DiagnosticPart.SOURCE);
+                    setVisiblePart(DiagnosticPart.SOURCE, false);
             }
             String multiPolicy = null;
             if ((multiPolicy = options.get("multilinePolicy")) != null) {
                 if (multiPolicy.equals("disabled"))
-                    visibleParts.remove(DiagnosticPart.SUBDIAGNOSTICS);
+                    setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
                 else if (multiPolicy.startsWith("limit:")) {
                     String limitString = multiPolicy.substring("limit:".length());
                     String[] limits = limitString.split(":");
@@ -421,6 +429,13 @@
             visibleParts = EnumSet.copyOf(diagParts);
         }
 
+        public void setVisiblePart(DiagnosticPart diagParts, boolean enabled) {
+            if (enabled)
+                visibleParts.add(diagParts);
+            else
+                visibleParts.remove(diagParts);
+        }
+
         /**
          * Shows a '^' sign under the source line displayed by the formatter
          * (if applicable).
@@ -441,6 +456,14 @@
         }
     }
 
+    public Printer getPrinter() {
+        return printer;
+    }
+
+    public void setPrinter(Printer printer) {
+        this.printer = printer;
+    }
+
     /**
      * An enhanced printer for formatting types/symbols used by
      * AbstractDiagnosticFormatter. Provides alternate numbering of captured
@@ -450,33 +473,14 @@
      * type referred by a given captured type C contains C itself) which might
      * lead to infinite loops.
      */
-    protected class FormatterPrinter extends Printer {
-
-        List<Type> allCaptured = List.nil();
-        List<Type> seenCaptured = List.nil();
-
+    protected Printer printer = new Printer() {
         @Override
         protected String localize(Locale locale, String key, Object... args) {
             return AbstractDiagnosticFormatter.this.localize(locale, key, args);
         }
-
         @Override
-        public String visitCapturedType(CapturedType t, Locale locale) {
-            if (seenCaptured.contains(t))
-                return localize(locale, "compiler.misc.type.captureof.1",
-                    allCaptured.indexOf(t) + 1);
-            else {
-                try {
-                    seenCaptured = seenCaptured.prepend(t);
-                    allCaptured = allCaptured.append(t);
-                    return localize(locale, "compiler.misc.type.captureof",
-                        allCaptured.indexOf(t) + 1,
-                        visit(t.wildcard, locale));
-                }
-                finally {
-                    seenCaptured = seenCaptured.tail;
-                }
-            }
+        protected String capturedVarId(CapturedType t, Locale locale) {
+            return "" + (allCaptured.indexOf(t) + 1);
         }
-    }
+    };
 }
--- a/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java	Thu May 21 10:56:36 2009 +0100
@@ -209,6 +209,7 @@
 
     @Override
     public BasicConfiguration getConfiguration() {
+        //the following cast is always safe - see init
         return (BasicConfiguration)super.getConfiguration();
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/ForwardingDiagnosticFormatter.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.tools.javac.util;
+
+import java.util.Set;
+import java.util.Locale;
+import javax.tools.Diagnostic;
+
+import com.sun.tools.javac.api.DiagnosticFormatter;
+import com.sun.tools.javac.api.DiagnosticFormatter.Configuration;
+import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
+import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit;
+import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind;
+
+/**
+ * A delegated diagnostic formatter delegates all formatting
+ * actions to an underlying formatter (aka the delegated formatter).
+ */
+public class ForwardingDiagnosticFormatter<D extends Diagnostic<?>, F extends DiagnosticFormatter<D>>
+        implements DiagnosticFormatter<D> {
+
+    /**
+     * The delegated formatter
+     */
+    protected F formatter;
+
+    /*
+     * configuration object used by this formatter
+     */
+    protected ForwardingConfiguration configuration;
+
+    public ForwardingDiagnosticFormatter(F formatter) {
+        this.formatter = formatter;
+        this.configuration = new ForwardingConfiguration(formatter.getConfiguration());
+    }
+
+    /**
+     * Returns the underlying delegated formatter
+     * @return delegate formatter
+     */
+    public F getDelegatedFormatter() {
+        return formatter;
+    }
+
+    public Configuration getConfiguration() {
+        return configuration;
+    }
+
+    public boolean displaySource(D diag) {
+        return formatter.displaySource(diag);
+    }
+
+    public String format(D diag, Locale l) {
+        return formatter.format(diag, l);
+    }
+
+    public String formatKind(D diag, Locale l) {
+        return formatter.formatKind(diag, l);
+    }
+
+    public String formatMessage(D diag, Locale l) {
+        return formatter.formatMessage(diag, l);
+    }
+
+    public String formatPosition(D diag, PositionKind pk, Locale l) {
+        return formatter.formatPosition(diag, pk, l);
+    }
+
+    public String formatSource(D diag, boolean fullname, Locale l) {
+        return formatter.formatSource(diag, fullname, l);
+    }
+
+    /**
+     * A delegated formatter configuration delegates all configurations settings
+     * to an underlying configuration object (aka the delegated configuration).
+     */
+    public static class ForwardingConfiguration implements DiagnosticFormatter.Configuration {
+
+        /** The configurationr object to which the forwarding configuration delegates some settings */
+        protected Configuration configuration;
+
+        public ForwardingConfiguration(Configuration configuration) {
+            this.configuration = configuration;
+        }
+
+        /**
+         * Returns the underlying delegated configuration.
+         * @return delegated configuration
+         */
+        public Configuration getDelegatedConfiguration() {
+            return configuration;
+        }
+
+        public int getMultilineLimit(MultilineLimit limit) {
+            return configuration.getMultilineLimit(limit);
+        }
+
+        public Set<DiagnosticPart> getVisible() {
+            return configuration.getVisible();
+        }
+
+        public void setMultilineLimit(MultilineLimit limit, int value) {
+            configuration.setMultilineLimit(limit, value);
+        }
+
+        public void setVisible(Set<DiagnosticPart> diagParts) {
+            configuration.setVisible(diagParts);
+        }
+    }
+}
--- a/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Wed May 20 19:10:06 2009 -0700
+++ b/src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java	Thu May 21 10:56:36 2009 +0100
@@ -124,4 +124,9 @@
         }
         return buf.toString();
     }
+
+    @Override
+    public boolean isRaw() {
+        return true;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,648 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.tools.javac.util;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import com.sun.tools.javac.code.Kinds;
+import com.sun.tools.javac.code.Printer;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.*;
+import com.sun.tools.javac.code.Types;
+
+import static com.sun.tools.javac.code.TypeTags.*;
+import static com.sun.tools.javac.code.Flags.*;
+import static com.sun.tools.javac.util.LayoutCharacters.*;
+import static com.sun.tools.javac.util.RichDiagnosticFormatter.RichConfiguration.*;
+
+/**
+ * A rich diagnostic formatter is a formatter that provides better integration
+ * with javac's type system. A diagostic is first preprocessed in order to keep
+ * track of each types/symbols in it; after these informations are collected,
+ * the diagnostic is rendered using a standard formatter, whose type/symbol printer
+ * has been replaced by a more refined version provided by this rich formatter.
+ * The rich formatter currently enables three different features: (i) simple class
+ * names - that is class names are displayed used a non qualified name (thus
+ * omitting package info) whenever possible - (ii) where clause list - a list of
+ * additional subdiagnostics that provide specific info about type-variables,
+ * captured types, intersection types that occur in the diagnostic that is to be
+ * formatted and (iii) type-variable disambiguation - when the diagnostic refers
+ * to two different type-variables with the same name, their representation is
+ * disambiguated by appending an index to the type variable name.
+ */
+public class RichDiagnosticFormatter extends
+        ForwardingDiagnosticFormatter<JCDiagnostic, AbstractDiagnosticFormatter> {
+
+    final Symtab syms;
+    final Types types;
+    final JCDiagnostic.Factory diags;
+    final JavacMessages messages;
+
+    /* name simplifier used by this formatter */
+    ClassNameSimplifier nameSimplifier;
+
+    /* map for keeping track of a where clause associated to a given type */
+    Map<WhereClauseKind, Map<Type, JCDiagnostic>> whereClauses;
+
+    /** Get the DiagnosticFormatter instance for this context. */
+    public static RichDiagnosticFormatter instance(Context context) {
+        RichDiagnosticFormatter instance = context.get(RichDiagnosticFormatter.class);
+        if (instance == null)
+            instance = new RichDiagnosticFormatter(context);
+        return instance;
+    }
+
+    protected RichDiagnosticFormatter(Context context) {
+        super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
+        this.formatter.setPrinter(printer);
+        this.syms = Symtab.instance(context);
+        this.diags = JCDiagnostic.Factory.instance(context);
+        this.types = Types.instance(context);
+        this.messages = JavacMessages.instance(context);
+        whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>();
+        configuration = new RichConfiguration(Options.instance(context), formatter);
+        for (WhereClauseKind kind : WhereClauseKind.values())
+            whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
+    }
+
+    @Override
+    public String format(JCDiagnostic diag, Locale l) {
+        StringBuilder sb = new StringBuilder();
+        nameSimplifier = new ClassNameSimplifier();
+        for (WhereClauseKind kind : WhereClauseKind.values())
+            whereClauses.get(kind).clear();
+        preprocessDiagnostic(diag);
+        sb.append(formatter.format(diag, l));
+        if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
+            List<JCDiagnostic> clauses = getWhereClauses();
+            String indent = formatter.isRaw() ? "" :
+                formatter.indentString(DetailsInc);
+            for (JCDiagnostic d : clauses) {
+                String whereClause = formatter.format(d, l);
+                if (whereClause.length() > 0) {
+                    sb.append('\n' + indent + whereClause);
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Preprocess a given diagnostic by looking both into its arguments and into
+     * its subdiagnostics (if any). This preprocessing is responsible for
+     * generating info corresponding to features like where clauses, name
+     * simplification, etc.
+     *
+     * @param diag the diagnostic to be preprocessed
+     */
+    protected void preprocessDiagnostic(JCDiagnostic diag) {
+        for (Object o : diag.getArgs()) {
+            if (o != null) {
+                preprocessArgument(o);
+            }
+        }
+        if (diag.isMultiline()) {
+            for (JCDiagnostic d : diag.getSubdiagnostics())
+                preprocessDiagnostic(d);
+        }
+    }
+
+    /**
+     * Preprocess a diagnostic argument. A type/symbol argument is
+     * preprocessed by specialized type/symbol preprocessors.
+     *
+     * @param arg the argument to be translated
+     */
+    protected void preprocessArgument(Object arg) {
+        if (arg instanceof Type) {
+            preprocessType((Type)arg);
+        }
+        else if (arg instanceof Symbol) {
+            preprocessSymbol((Symbol)arg);
+        }
+        else if (arg instanceof JCDiagnostic) {
+            preprocessDiagnostic((JCDiagnostic)arg);
+        }
+        else if (arg instanceof Iterable<?>) {
+            for (Object o : (Iterable<?>)arg) {
+                preprocessArgument(o);
+            }
+        }
+    }
+
+    /**
+     * Build a list of multiline diagnostics containing detailed info about
+     * type-variables, captured types, and intersection types
+     *
+     * @return where clause list
+     */
+    protected List<JCDiagnostic> getWhereClauses() {
+        List<JCDiagnostic> clauses = List.nil();
+        for (WhereClauseKind kind : WhereClauseKind.values()) {
+            List<JCDiagnostic> lines = List.nil();
+            for (Map.Entry<Type, JCDiagnostic> entry : whereClauses.get(kind).entrySet()) {
+                lines = lines.prepend(entry.getValue());
+            }
+            if (!lines.isEmpty()) {
+                String key = kind.key();
+                if (lines.size() > 1)
+                    key += ".1";
+                JCDiagnostic d = diags.fragment(key, whereClauses.get(kind).keySet());
+                d = new JCDiagnostic.MultilineDiagnostic(d, lines.reverse());
+                clauses = clauses.prepend(d);
+            }
+        }
+        return clauses.reverse();
+    }
+    //where
+    /**
+     * This enum defines all posssible kinds of where clauses that can be
+     * attached by a rich diagnostic formatter to a given diagnostic
+     */
+    enum WhereClauseKind {
+
+        /** where clause regarding a type variable */
+        TYPEVAR("where.description.typevar"),
+        /** where clause regarding a captured type */
+        CAPTURED("where.description.captured"),
+        /** where clause regarding an intersection type */
+        INTERSECTION("where.description.intersection");
+
+        /** resource key for this where clause kind */
+        private String key;
+
+        WhereClauseKind(String key) {
+            this.key = key;
+        }
+
+        String key() {
+            return key;
+        }
+    }
+
+    // <editor-fold defaultstate="collapsed" desc="name simplifier">
+    /**
+     * A name simplifier keeps track of class names usages in order to determine
+     * whether a class name can be compacted or not. Short names are not used
+     * if a conflict is detected, e.g. when two classes with the same simple
+     * name belong to different packages - in this case the formatter reverts
+     * to fullnames as compact names might lead to a confusing diagnostic.
+     */
+    class ClassNameSimplifier {
+
+        /* table for keeping track of all short name usages */
+        Map<Name, List<Symbol>> nameClashes = new HashMap<Name, List<Symbol>>();
+
+        /**
+         * Add a name usage to the simplifier's internal cache
+         */
+        protected void addUsage(Symbol sym) {
+            Name n = sym.getSimpleName();
+            List<Symbol> conflicts = nameClashes.get(n);
+            if (conflicts == null) {
+                conflicts = List.nil();
+            }
+            if (!conflicts.contains(sym))
+                nameClashes.put(n, conflicts.append(sym));
+        }
+
+        public String simplify(Symbol s) {
+            String name = s.getQualifiedName().toString();
+            if (!s.type.isCompound()) {
+                List<Symbol> conflicts = nameClashes.get(s.getSimpleName());
+                if (conflicts == null ||
+                    (conflicts.size() == 1 &&
+                    conflicts.contains(s))) {
+                    List<Name> l = List.nil();
+                    Symbol s2 = s;
+                    while (s2.type.getEnclosingType().tag == CLASS
+                            && s2.owner.kind == Kinds.TYP) {
+                        l = l.prepend(s2.getSimpleName());
+                        s2 = s2.owner;
+                    }
+                    l = l.prepend(s2.getSimpleName());
+                    StringBuilder buf = new StringBuilder();
+                    String sep = "";
+                    for (Name n2 : l) {
+                        buf.append(sep);
+                        buf.append(n2);
+                        sep = ".";
+                    }
+                    name = buf.toString();
+                }
+            }
+            return name;
+        }
+    };
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="rich printer">
+    /**
+     * Enhanced type/symbol printer that provides support for features like simple names
+     * and type variable disambiguation. This enriched printer exploits the info
+     * discovered during type/symbol preprocessing. This printer is set on the delegate
+     * formatter so that rich type/symbol info can be properly rendered.
+     */
+    protected Printer printer = new Printer() {
+
+        @Override
+        public String localize(Locale locale, String key, Object... args) {
+            return formatter.localize(locale, key, args);
+        }
+
+        @Override
+        public String capturedVarId(CapturedType t, Locale locale) {
+            return indexOf(t, WhereClauseKind.CAPTURED) + "";
+        }
+
+        @Override
+        public String visitType(Type t, Locale locale) {
+            String s = super.visitType(t, locale);
+            if (t == syms.botType)
+                s = localize(locale, "compiler.misc.type.null");
+            return s;
+        }
+
+        @Override
+        public String visitCapturedType(CapturedType t, Locale locale) {
+            if (getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
+                return localize(locale,
+                    "compiler.misc.captured.type",
+                    indexOf(t, WhereClauseKind.CAPTURED));
+            }
+            else
+                return super.visitCapturedType(t, locale);
+        }
+
+        @Override
+        public String visitClassType(ClassType t, Locale locale) {
+            if (t.isCompound() &&
+                    getConfiguration().isEnabled(RichFormatterFeature.WHERE_CLAUSES)) {
+                return localize(locale,
+                        "compiler.misc.intersection.type",
+                        indexOf(t, WhereClauseKind.INTERSECTION));
+            }
+            else
+                return super.visitClassType(t, locale);
+        }
+
+        @Override
+        protected String className(ClassType t, boolean longform, Locale locale) {
+            Symbol sym = t.tsym;
+            if (sym.name.length() == 0 ||
+                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
+                return super.className(t, longform, locale);
+            }
+            else if (longform)
+                return nameSimplifier.simplify(sym).toString();
+            else
+                return sym.name.toString();
+        }
+
+        @Override
+        public String visitTypeVar(TypeVar t, Locale locale) {
+            if (unique(t) ||
+                    !getConfiguration().isEnabled(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES)) {
+                return t.toString();
+            }
+            else {
+                return localize(locale,
+                        "compiler.misc.type.var",
+                        t.toString(), indexOf(t, WhereClauseKind.TYPEVAR));
+            }
+        }
+
+        private int indexOf(Type type, WhereClauseKind kind) {
+            int index = 0;
+            boolean found = false;
+            for (Type t : whereClauses.get(kind).keySet()) {
+                if (t == type) {
+                    found = true;
+                    break;
+                }
+                index++;
+            }
+            if (!found)
+                throw new AssertionError("Missing symbol in where clause " + type);
+            return index + 1;
+        }
+
+        private boolean unique(TypeVar typevar) {
+            int found = 0;
+            for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
+                if (t.toString().equals(typevar.toString())) {
+                    found++;
+                }
+            }
+            if (found < 1)
+                throw new AssertionError("Missing type variable in where clause " + typevar);
+            return found == 1;
+        }
+
+        @Override
+        protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
+            return super.printMethodArgs(args, varArgs, locale);
+        }
+
+        @Override
+        public String visitClassSymbol(ClassSymbol s, Locale locale) {
+            String name = nameSimplifier.simplify(s);
+            if (name.length() == 0 ||
+                    !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
+                return super.visitClassSymbol(s, locale);
+            }
+            else {
+                return name;
+            }
+        }
+
+        @Override
+        public String visitMethodSymbol(MethodSymbol s, Locale locale) {
+            String ownerName = visit(s.owner, locale);
+            if ((s.flags() & BLOCK) != 0) {
+               return ownerName;
+            } else {
+                String ms = (s.name == s.name.table.names.init)
+                    ? ownerName
+                    : s.name.toString();
+                if (s.type != null) {
+                    if (s.type.tag == FORALL) {
+                        ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
+                    }
+                    ms += "(" + printMethodArgs(
+                            s.type.getParameterTypes(),
+                            (s.flags() & VARARGS) != 0,
+                            locale) + ")";
+                }
+                return ms;
+            }
+        }
+    };
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="type scanner">
+    /**
+     * Preprocess a given type looking for (i) additional info (where clauses) to be
+     * added to the main diagnostic (ii) names to be compacted.
+     */
+    protected void preprocessType(Type t) {
+        typePreprocessor.visit(t);
+    }
+    //where
+    protected Types.UnaryVisitor<Void> typePreprocessor =
+            new Types.UnaryVisitor<Void>() {
+
+        public Void visit(List<Type> ts) {
+            for (Type t : ts)
+                visit(t);
+            return null;
+        }
+
+        @Override
+        public Void visitForAll(ForAll t, Void ignored) {
+            visit(t.tvars);
+            visit(t.qtype);
+            return null;
+        }
+
+        @Override
+        public Void visitMethodType(MethodType t, Void ignored) {
+            visit(t.argtypes);
+            visit(t.restype);
+            return null;
+        }
+
+        @Override
+        public Void visitErrorType(ErrorType t, Void ignored) {
+            Type ot = t.getOriginalType();
+            if (ot != null)
+                visit(ot);
+            return null;
+        }
+
+        @Override
+        public Void visitArrayType(ArrayType t, Void ignored) {
+            visit(t.elemtype);
+            return null;
+        }
+
+        @Override
+        public Void visitWildcardType(WildcardType t, Void ignored) {
+            visit(t.type);
+            return null;
+        }
+
+        public Void visitType(Type t, Void ignored) {
+            return null;
+        }
+
+        @Override
+        public Void visitCapturedType(CapturedType t, Void ignored) {
+            if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) {
+                String suffix = t.lower == syms.botType ? ".1" : "";
+                JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard);
+                whereClauses.get(WhereClauseKind.CAPTURED).put(t, d);
+                visit(t.wildcard);
+                visit(t.lower);
+                visit(t.bound);
+            }
+            return null;
+        }
+
+        @Override
+        public Void visitClassType(ClassType t, Void ignored) {
+            if (t.isCompound()) {
+                if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) {
+                    Type supertype = types.supertype(t);
+                    List<Type> interfaces = types.interfaces(t);
+                    JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype));
+                    whereClauses.get(WhereClauseKind.INTERSECTION).put(t, d);
+                    visit(supertype);
+                    visit(interfaces);
+                }
+            }
+            nameSimplifier.addUsage(t.tsym);
+            visit(t.getTypeArguments());
+            if (t.getEnclosingType() != Type.noType)
+                visit(t.getEnclosingType());
+            return null;
+        }
+
+        @Override
+        public Void visitTypeVar(TypeVar t, Void ignored) {
+            if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) {
+                Type bound = t.bound;
+                while ((bound instanceof ErrorType))
+                    bound = ((ErrorType)bound).getOriginalType();
+                List<Type> bounds  = types.getBounds(t);
+                nameSimplifier.addUsage(t.tsym);
+
+                boolean boundErroneous = bounds.head == null ||
+                                         bounds.head.tag == NONE ||
+                                         bounds.head.tag == ERROR;
+
+
+                JCDiagnostic d = diags.fragment("where.typevar" +
+                        (boundErroneous ? ".1" : ""), t, bounds,
+                        Kinds.kindName(t.tsym.location()), t.tsym.location());
+                whereClauses.get(WhereClauseKind.TYPEVAR).put(t, d);
+                symbolPreprocessor.visit(t.tsym.location(), null);
+                visit(bounds);
+            }
+            return null;
+        }
+    };
+    // </editor-fold>
+
+    // <editor-fold defaultstate="collapsed" desc="symbol scanner">
+    /**
+     * Preprocess a given symbol looking for (i) additional info (where clauses) to be
+     * asdded to the main diagnostic (ii) names to be compacted
+     */
+    protected void preprocessSymbol(Symbol s) {
+        symbolPreprocessor.visit(s, null);
+    }
+    //where
+    protected Types.DefaultSymbolVisitor<Void, Void> symbolPreprocessor =
+            new Types.DefaultSymbolVisitor<Void, Void>() {
+
+        @Override
+        public Void visitClassSymbol(ClassSymbol s, Void ignored) {
+            nameSimplifier.addUsage(s);
+            return null;
+        }
+
+        @Override
+        public Void visitSymbol(Symbol s, Void ignored) {
+            return null;
+        }
+
+        @Override
+        public Void visitMethodSymbol(MethodSymbol s, Void ignored) {
+            visit(s.owner, null);
+            typePreprocessor.visit(s.type);
+            return null;
+        }
+    };
+    // </editor-fold>
+
+    @Override
+    public RichConfiguration getConfiguration() {
+        //the following cast is always safe - see init
+        return (RichConfiguration)configuration;
+    }
+
+    /**
+     * Configuration object provided by the rich formatter.
+     */
+    public static class RichConfiguration extends ForwardingDiagnosticFormatter.ForwardingConfiguration {
+
+        /** set of enabled rich formatter's features */
+        protected java.util.EnumSet<RichFormatterFeature> features;
+
+        @SuppressWarnings("fallthrough")
+        public RichConfiguration(Options options, AbstractDiagnosticFormatter formatter) {
+            super(formatter.getConfiguration());
+            features = formatter.isRaw() ? EnumSet.noneOf(RichFormatterFeature.class) :
+                EnumSet.of(RichFormatterFeature.SIMPLE_NAMES,
+                    RichFormatterFeature.WHERE_CLAUSES,
+                    RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
+            String diagOpts = options.get("diags");
+            if (diagOpts != null) {
+                for (String args: diagOpts.split(",")) {
+                    if (args.equals("-where")) {
+                        features.remove(RichFormatterFeature.WHERE_CLAUSES);
+                    }
+                    else if (args.equals("where")) {
+                        features.add(RichFormatterFeature.WHERE_CLAUSES);
+                    }
+                    if (args.equals("-simpleNames")) {
+                        features.remove(RichFormatterFeature.SIMPLE_NAMES);
+                    }
+                    else if (args.equals("simpleNames")) {
+                        features.add(RichFormatterFeature.SIMPLE_NAMES);
+                    }
+                    if (args.equals("-disambiguateTvars")) {
+                        features.remove(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
+                    }
+                    else if (args.equals("disambiguateTvars")) {
+                        features.add(RichFormatterFeature.UNIQUE_TYPEVAR_NAMES);
+                    }
+                }
+            }
+        }
+
+        /**
+         * Returns a list of all the features supported by the rich formatter.
+         * @return list of supported features
+         */
+        public RichFormatterFeature[] getAvailableFeatures() {
+            return RichFormatterFeature.values();
+        }
+
+        /**
+         * Enable a specific feature on this rich formatter.
+         * @param feature feature to be enabled
+         */
+        public void enable(RichFormatterFeature feature) {
+            features.add(feature);
+        }
+
+        /**
+         * Disable a specific feature on this rich formatter.
+         * @param feature feature to be disabled
+         */
+        public void disable(RichFormatterFeature feature) {
+            features.remove(feature);
+        }
+
+        /**
+         * Is a given feature enabled on this formatter?
+         * @param feature feature to be tested
+         */
+        public boolean isEnabled(RichFormatterFeature feature) {
+            return features.contains(feature);
+        }
+
+        /**
+         * The advanced formatting features provided by the rich formatter
+         */
+        public enum RichFormatterFeature {
+            /** a list of additional info regarding a given type/symbol */
+            WHERE_CLAUSES,
+            /** full class names simplification (where possible) */
+            SIMPLE_NAMES,
+            /** type-variable names disambiguation */
+            UNIQUE_TYPEVAR_NAMES;
+        }
+    }
+}
--- a/test/tools/javac/6304921/T6304921.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/6304921/T6304921.java	Thu May 21 10:56:36 2009 +0100
@@ -1,7 +1,7 @@
 /*
  * @test (important: no SCCS keywords to affect offsets in golden file.)  /nodynamiccopyright/
  * @bug 6304921
- * @compile/fail/ref=T6304921.out -XDstdout -XDcompilePolicy=bytodo -XDdiags=%b:%s/%o/%e:%_%t%m|%p%m -Xjcov -Xlint:all,-path -Werror T6304921.java
+ * @compile/fail/ref=T6304921.out -XDstdout -XDcompilePolicy=bytodo -XDrawDiagnostics -Xjcov -Xlint:all,-path -Werror T6304921.java
  */
 
 import java.util.ArrayList;
--- a/test/tools/javac/6304921/T6304921.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/6304921/T6304921.out	Thu May 21 10:56:36 2009 +0100
@@ -1,20 +1,7 @@
-T6304921.java:671/671/680: warning: [rawtypes] found raw type: java.util.ArrayList
-        List<Integer> list = new ArrayList();
-                                 ^
-  missing type parameters for generic class java.util.ArrayList<E>
-T6304921.java:667/667/682: warning: [unchecked] unchecked conversion
-        List<Integer> list = new ArrayList();
-                             ^
-  required: java.util.List<java.lang.Integer>
-  found:    java.util.ArrayList
-error: warnings found and -Werror specified
-T6304921.java:727/733/737: cannot find symbol
-        System.orr.println("abc"); // name not found
-              ^
-  symbol:   variable orr
-  location: class java.lang.System
-T6304921.java:812/816/822: operator + cannot be applied to int,boolean
-        return 123 + true; // bad binary expression
-                   ^
+T6304921.java:29:34: compiler.warn.raw.class.use: java.util.ArrayList, java.util.ArrayList<E>
+T6304921.java:29:30: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.ArrayList, java.util.List<java.lang.Integer>
+- compiler.err.warnings.and.werror
+T6304921.java:35:15: compiler.err.cant.resolve.location: kindname.variable, orr, , , kindname.class, java.lang.System
+T6304921.java:38:20: compiler.err.operator.cant.be.applied: +, int,boolean
 3 errors
 2 warnings
--- a/test/tools/javac/6491592/T6491592.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/6491592/T6491592.out	Thu May 21 10:56:36 2009 +0100
@@ -1,2 +1,2 @@
-T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,<nulltype>
+T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,compiler.misc.type.null
 1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234a.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug     6722234
+ * @summary javac diagnostics need better integration with the type-system
+ * @author  mcimadamore
+ * @compile/fail/ref=T6722234a_1.out -XDrawDiagnostics -XDdiags=disambiguateTvars T6722234a.java
+ * @compile/fail/ref=T6722234a_2.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6722234a.java
+ */
+
+class T6722234a<T extends String> {
+    <T extends Integer> void test(T t) {
+        m(t);
+    }
+    void m(T t) {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234a_1.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,2 @@
+T6722234a.java:35:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, null
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234a_2.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,3 @@
+T6722234a.java:35:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, null
+- compiler.misc.where.description.typevar.1: compiler.misc.type.var: T, 1,compiler.misc.type.var: T, 2,{(compiler.misc.where.typevar: compiler.misc.type.var: T, 1, java.lang.String, kindname.class, T6722234a),(compiler.misc.where.typevar: compiler.misc.type.var: T, 2, java.lang.Integer, kindname.method, <compiler.misc.type.var: T, 2>test(compiler.misc.type.var: T, 2))}
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234b.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug     6722234
+ * @summary javac diagnostics need better integration with the type-system
+ * @author  mcimadamore
+ * @compile/fail/ref=T6722234b_1.out -XDrawDiagnostics -XDdiags=simpleNames T6722234b.java
+ * @compile/fail/ref=T6722234b_2.out -XDrawDiagnostics -XDdiags=simpleNames,where T6722234b.java
+ */
+
+import java.util.*;
+
+class T6722234b {
+    <T> void m(List<T> l1, List<T> l2) {}
+
+    void test(List<? extends T6722234b> list) {
+        m(list, list);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234b_1.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,2 @@
+T6722234b.java:39:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, null
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234b_2.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,4 @@
+T6722234b.java:39:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, null
+- compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, Object, kindname.method, <T>m(List<T>,List<T>))}
+- compiler.misc.where.description.captured.1: compiler.misc.captured.type: 1,compiler.misc.captured.type: 2,{(compiler.misc.where.captured.1: compiler.misc.captured.type: 1, T6722234b, compiler.misc.type.null, ? extends T6722234b),(compiler.misc.where.captured.1: compiler.misc.captured.type: 2, T6722234b, compiler.misc.type.null, ? extends T6722234b)}
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234c.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug     6722234
+ * @summary javac diagnostics need better integration with the type-system
+ * @author  mcimadamore
+ * @compile/fail/ref=T6722234c.out -XDrawDiagnostics -XDdiags=simpleNames T6722234c.java
+ */
+
+class T6722234c {
+    static class String {}
+    <T> void m(String s2) {}
+
+    void test() {
+        m("");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234c.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,2 @@
+T6722234c.java:37:9: compiler.err.cant.apply.symbol: kindname.method, m, T6722234c.String, java.lang.String, kindname.class, T6722234c, null
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234d.java	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug     6722234
+ * @summary javac diagnostics need better integration with the type-system
+ * @author  mcimadamore
+ * @compile/fail/ref=T6722234d_1.out -XDrawDiagnostics -XDdiags=where T6722234d.java
+ * @compile/fail/ref=T6722234d_2.out -XDrawDiagnostics -XDdiags=where,simpleNames T6722234d.java
+ */
+
+class T6722234d {
+    interface I1 {}
+    interface I2 {}
+    class A implements I1, I2 {}
+    class B implements I1, I2 {}
+    class Test {
+        <Z> Z m(Z z1, Z z2) { return null; }
+        void main(){
+            A a = m(new A(), new B());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234d_1.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,3 @@
+T6722234d.java:41:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types), compiler.misc.intersection.type: 1, T6722234d.A
+- compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, java.lang.Object,T6722234d.I1,T6722234d.I2)}
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/Diagnostics/6722234/T6722234d_2.out	Thu May 21 10:56:36 2009 +0100
@@ -0,0 +1,3 @@
+T6722234d.java:41:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types), compiler.misc.intersection.type: 1, T6722234d.A
+- compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, Object,I1,I2)}
+1 error
--- a/test/tools/javac/ExtendArray.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/ExtendArray.java	Thu May 21 10:56:36 2009 +0100
@@ -3,7 +3,7 @@
  * @bug 4336282 4785453
  * @summary Verify that extending an erray class does not crash the compiler.
  *
- * @compile/fail/ref=ExtendArray.out -XDstdout -XDdiags=%b:%l:%_%m ExtendArray.java
+ * @compile/fail/ref=ExtendArray.out -XDstdout -XDrawDiagnostics ExtendArray.java
  */
 
 // Note that an error is expected, but not a crash.
--- a/test/tools/javac/ExtendArray.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/ExtendArray.out	Thu May 21 10:56:36 2009 +0100
@@ -1,6 +1,2 @@
-ExtendArray.java:11: unexpected type
-public class ExtendArray extends Object[] {}
-                                       ^
-  required: class
-  found:    java.lang.Object[]
+ExtendArray.java:11:40: compiler.err.type.found.req: java.lang.Object[], (compiler.misc.type.req.class)
 1 error
--- a/test/tools/javac/OverridePosition.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/OverridePosition.java	Thu May 21 10:56:36 2009 +0100
@@ -4,7 +4,7 @@
  * @summary "attemping to assign weaker access" message doesn't give method line number
  * @author Neal Gafter
  *
- * @compile/fail/ref=OverridePosition.out -XDstdout -XDdiags=%b:%l:%_%m OverridePosition.java
+ * @compile/fail/ref=OverridePosition.out -XDstdout -XDrawDiagnostics OverridePosition.java
  */
 
 package T4524388;
--- a/test/tools/javac/OverridePosition.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/OverridePosition.out	Thu May 21 10:56:36 2009 +0100
@@ -1,7 +1,3 @@
-OverridePosition.java:17: method() in T4524388.Testa cannot implement method() in T4524388.Interface; attempting to assign weaker access privileges; was public
-    void method() {}
-         ^
-OverridePosition.java:24: method() in T4524388.A cannot implement method() in T4524388.Interface; attempting to assign weaker access privileges; was public
-class B extends A implements Interface {
-^
+OverridePosition.java:17:10: compiler.err.override.weaker.access: (compiler.misc.cant.implement: method(), T4524388.Testa, method(), T4524388.Interface), public
+OverridePosition.java:24:1: compiler.err.override.weaker.access: (compiler.misc.cant.implement: method(), T4524388.A, method(), T4524388.Interface), public
 2 errors
--- a/test/tools/javac/T4093617/T4093617.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/T4093617/T4093617.java	Thu May 21 10:56:36 2009 +0100
@@ -3,7 +3,7 @@
  * @bug     4093617
  * @summary Object has no superclass
  * @author  Peter von der Ah\u00e9
- * @compile/fail/ref=T4093617.out -XDstdout -XDdiags=%b:%l:%_%m T4093617.java
+ * @compile/fail/ref=T4093617.out -XDstdout -XDrawDiagnostics T4093617.java
  */
 
 package java.lang;
--- a/test/tools/javac/T4093617/T4093617.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/T4093617/T4093617.out	Thu May 21 10:56:36 2009 +0100
@@ -1,4 +1,2 @@
-T4093617.java:12: java.lang.Object has no superclass
-    Object() { super(); }
-               ^
+T4093617.java:12:16: compiler.err.no.superclass: java.lang.Object
 1 error
--- a/test/tools/javac/T5003235/T5003235c.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/T5003235/T5003235c.java	Thu May 21 10:56:36 2009 +0100
@@ -3,7 +3,7 @@
  * @bug     5003235
  * @summary Access to private inner classes
  * @author  Peter von der Ah\u00e9
- * @compile/fail/ref=T5003235c.out -XDstdout -XDdiags=%b:%l:%_%m T5003235c.java
+ * @compile/fail/ref=T5003235c.out -XDstdout -XDrawDiagnostics T5003235c.java
  */
 
 class T5003235c {
--- a/test/tools/javac/T5003235/T5003235c.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/T5003235/T5003235c.out	Thu May 21 10:56:36 2009 +0100
@@ -1,4 +1,2 @@
-T5003235c.java:15: T5003235c.B has private access in T5003235c
-class C extends T5003235c.B.Inner {}
-                         ^
+T5003235c.java:15:26: compiler.err.report.access: T5003235c.B, private, T5003235c
 1 error
--- a/test/tools/javac/miranda/T4666866.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/miranda/T4666866.java	Thu May 21 10:56:36 2009 +0100
@@ -4,7 +4,7 @@
  * @summary REGRESSION: Generated error message unhelpful for missing methods
  * @author gafter
  *
- * @compile/fail/ref=T4666866.out -XDstdout -XDdiags=%b:%l:%_%m T4666866.java
+ * @compile/fail/ref=T4666866.out -XDstdout -XDrawDiagnostics T4666866.java
  */
 
 class t implements Runnable {}
--- a/test/tools/javac/miranda/T4666866.out	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/miranda/T4666866.out	Thu May 21 10:56:36 2009 +0100
@@ -1,4 +1,2 @@
-T4666866.java:10: t is not abstract and does not override abstract method run() in java.lang.Runnable
-class t implements Runnable {}
-^
+T4666866.java:10:1: compiler.err.does.not.override.abstract: t, run(), java.lang.Runnable
 1 error
--- a/test/tools/javac/protectedAccess/ProtectedMemberAccess2.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/protectedAccess/ProtectedMemberAccess2.java	Thu May 21 10:56:36 2009 +0100
@@ -4,7 +4,7 @@
  * @summary Verify correct implementation of JLS2e 6.6.2.1
  * @author maddox
  *
- * @compile/fail/ref=ProtectedMemberAccess2.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess2.java
+ * @compile/fail/ref=ProtectedMemberAccess2.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess2.java
  */
 
 // 71 errors expected.
--- a/test/tools/javac/protectedAccess/ProtectedMemberAccess3.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/protectedAccess/ProtectedMemberAccess3.java	Thu May 21 10:56:36 2009 +0100
@@ -4,7 +4,7 @@
  * @summary Verify correct implementation of JLS2e 6.6.2.1
  * @author maddox
  *
- * @compile/fail/ref=ProtectedMemberAccess3.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess3.java
+ * @compile/fail/ref=ProtectedMemberAccess3.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess3.java
  */
 
 // 46 errors expected.
--- a/test/tools/javac/protectedAccess/ProtectedMemberAccess4.java	Wed May 20 19:10:06 2009 -0700
+++ b/test/tools/javac/protectedAccess/ProtectedMemberAccess4.java	Thu May 21 10:56:36 2009 +0100
@@ -4,7 +4,7 @@
  * @summary Verify correct implementation of JLS2e 6.6.2.1
  * @author maddox
  *
- * @compile/fail/ref=ProtectedMemberAccess4.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess4.java
+ * @compile/fail/ref=ProtectedMemberAccess4.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess4.java
  */
 
 // 33 errors expected.