1.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Fri Jul 25 12:22:09 2008 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Mon Jul 28 10:22:10 2008 +0100 1.3 @@ -25,15 +25,13 @@ 1.4 1.5 package com.sun.tools.javac.util; 1.6 1.7 -import java.util.ResourceBundle; 1.8 -import java.util.Collection; 1.9 import java.util.Locale; 1.10 import java.util.Map; 1.11 1.12 import javax.tools.Diagnostic; 1.13 import javax.tools.JavaFileObject; 1.14 1.15 -import com.sun.tools.javac.api.Formattable; 1.16 +import com.sun.tools.javac.api.DiagnosticFormatter; 1.17 import com.sun.tools.javac.file.JavacFileManager; 1.18 import com.sun.tools.javac.tree.JCTree; 1.19 1.20 @@ -256,7 +254,7 @@ 1.21 private final int line; 1.22 private final int column; 1.23 private final String key; 1.24 - private final Object[] args; 1.25 + protected Object[] args; 1.26 private boolean mandatory; 1.27 1.28 /** 1.29 @@ -400,52 +398,25 @@ 1.30 * @return the prefix string associated with a particular type of diagnostic 1.31 */ 1.32 public String getPrefix(DiagnosticType dt) { 1.33 - switch (dt) { 1.34 - case FRAGMENT: return ""; 1.35 - case NOTE: return getLocalizedString("compiler.note.note"); 1.36 - case WARNING: return getLocalizedString("compiler.warn.warning"); 1.37 - case ERROR: return getLocalizedString("compiler.err.error"); 1.38 - default: 1.39 - throw new AssertionError("Unknown diagnostic type: " + dt); 1.40 + return getFormatter().formatKind(this, Locale.getDefault()); 1.41 + } 1.42 + 1.43 + private DiagnosticFormatter<JCDiagnostic> getFormatter() { 1.44 + if (defaultFormatter == null) { 1.45 + defaultFormatter = new BasicDiagnosticFormatter(messages); 1.46 } 1.47 + return defaultFormatter; 1.48 } 1.49 1.50 + 1.51 /** 1.52 * Return the standard presentation of this diagnostic. 1.53 */ 1.54 public String toString() { 1.55 - if (defaultFormatter == null) { 1.56 - defaultFormatter = 1.57 - new DiagnosticFormatter(); 1.58 - } 1.59 - return defaultFormatter.format(this); 1.60 + return getFormatter().format(this,Locale.getDefault()); 1.61 } 1.62 1.63 - private static DiagnosticFormatter defaultFormatter; 1.64 - 1.65 - private static final String messageBundleName = 1.66 - "com.sun.tools.javac.resources.compiler"; 1.67 - 1.68 - private String getLocalizedString(String key, Object... args) { 1.69 - String[] strings = new String[args.length]; 1.70 - for (int i = 0; i < strings.length; i++) { 1.71 - Object arg = args[i]; 1.72 - if (arg == null) 1.73 - strings[i] = null; 1.74 - else if (arg instanceof JCDiagnostic) 1.75 - strings[i] = ((JCDiagnostic) arg).getMessage(null); 1.76 - else if (arg instanceof Collection<?>) 1.77 - strings[i] = DiagnosticFormatter.convert((Collection<?>)arg).toString(); 1.78 - else if (arg instanceof Formattable) { 1.79 - ResourceBundle rb = ResourceBundle.getBundle(messageBundleName); 1.80 - strings[i] = ((Formattable)arg).toString(rb); 1.81 - } 1.82 - else 1.83 - strings[i] = arg.toString(); 1.84 - } 1.85 - 1.86 - return messages.getLocalizedString(key, (Object[]) strings); 1.87 - } 1.88 + private static DiagnosticFormatter<JCDiagnostic> defaultFormatter; 1.89 1.90 // Methods for javax.tools.Diagnostic 1.91 1.92 @@ -469,7 +440,6 @@ 1.93 1.94 public String getMessage(Locale locale) { 1.95 // RFE 6406133: JCDiagnostic.getMessage ignores locale argument 1.96 - return getLocalizedString(key, args); 1.97 + return getFormatter().formatMessage(this, locale); 1.98 } 1.99 - 1.100 }