src/share/classes/com/sun/tools/javadoc/Messager.java

changeset 1411
467f4f754368
parent 1359
25e14ad23cef
child 1413
bdcef2ef52d2
     1.1 --- a/src/share/classes/com/sun/tools/javadoc/Messager.java	Thu Nov 15 09:18:36 2012 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/Messager.java	Thu Nov 15 14:41:31 2012 -0800
     1.3 @@ -25,13 +25,15 @@
     1.4  
     1.5  package com.sun.tools.javadoc;
     1.6  
     1.7 -import java.io.PrintWriter;  // Access to 'javac' output streams
     1.8 +import java.io.PrintWriter;
     1.9  import java.text.MessageFormat;
    1.10 -import java.util.MissingResourceException;
    1.11 +import java.util.Locale;
    1.12  import java.util.ResourceBundle;
    1.13  
    1.14  import com.sun.javadoc.*;
    1.15  import com.sun.tools.javac.util.Context;
    1.16 +import com.sun.tools.javac.util.JCDiagnostic;
    1.17 +import com.sun.tools.javac.util.JavacMessages;
    1.18  import com.sun.tools.javac.util.Log;
    1.19  
    1.20  /**
    1.21 @@ -51,6 +53,7 @@
    1.22   * @author Neal Gafter (rewrite)
    1.23   */
    1.24  public class Messager extends Log implements DocErrorReporter {
    1.25 +    public static final SourcePosition NOPOS = null;
    1.26  
    1.27      /** Get the current messager, which is also the compiler log. */
    1.28      public static Messager instance0(Context context) {
    1.29 @@ -91,7 +94,9 @@
    1.30  
    1.31      final String programName;
    1.32  
    1.33 -    private ResourceBundle messageRB = null;
    1.34 +    private Locale locale;
    1.35 +    private final JavacMessages messages;
    1.36 +    private final JCDiagnostic.Factory javadocDiags;
    1.37  
    1.38      /** The default writer for diagnostics
    1.39       */
    1.40 @@ -121,6 +126,9 @@
    1.41                         PrintWriter warnWriter,
    1.42                         PrintWriter noticeWriter) {
    1.43          super(context, errWriter, warnWriter, noticeWriter);
    1.44 +        messages = JavacMessages.instance(context);
    1.45 +        messages.add("com.sun.tools.javadoc.resources.javadoc");
    1.46 +        javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
    1.47          this.programName = programName;
    1.48      }
    1.49  
    1.50 @@ -134,94 +142,18 @@
    1.51          return Integer.MAX_VALUE;
    1.52      }
    1.53  
    1.54 -    /**
    1.55 -     * Reset resource bundle, eg. locale has changed.
    1.56 -     */
    1.57 -    public void reset() {
    1.58 -        messageRB = null;
    1.59 -    }
    1.60 -
    1.61 -    /**
    1.62 -     * Get string from ResourceBundle, initialize ResourceBundle
    1.63 -     * if needed.
    1.64 -     */
    1.65 -    private String getString(String key) {
    1.66 -        if (messageRB == null) {
    1.67 -            try {
    1.68 -                messageRB = ResourceBundle.getBundle(
    1.69 -                          "com.sun.tools.javadoc.resources.javadoc");
    1.70 -            } catch (MissingResourceException e) {
    1.71 -                throw new Error("Fatal: Resource for javadoc is missing");
    1.72 -            }
    1.73 -        }
    1.74 -        return messageRB.getString(key);
    1.75 +    public void setLocale(Locale locale) {
    1.76 +        this.locale = locale;
    1.77      }
    1.78  
    1.79      /**
    1.80       * get and format message string from resource
    1.81       *
    1.82       * @param key selects message from resource
    1.83 +     * @param args arguments for the message
    1.84       */
    1.85 -    String getText(String key) {
    1.86 -        return getText(key, (String)null);
    1.87 -    }
    1.88 -
    1.89 -    /**
    1.90 -     * get and format message string from resource
    1.91 -     *
    1.92 -     * @param key selects message from resource
    1.93 -     * @param a1 first argument
    1.94 -     */
    1.95 -    String getText(String key, String a1) {
    1.96 -        return getText(key, a1, null);
    1.97 -    }
    1.98 -
    1.99 -    /**
   1.100 -     * get and format message string from resource
   1.101 -     *
   1.102 -     * @param key selects message from resource
   1.103 -     * @param a1 first argument
   1.104 -     * @param a2 second argument
   1.105 -     */
   1.106 -    String getText(String key, String a1, String a2) {
   1.107 -        return getText(key, a1, a2, null);
   1.108 -    }
   1.109 -
   1.110 -    /**
   1.111 -     * get and format message string from resource
   1.112 -     *
   1.113 -     * @param key selects message from resource
   1.114 -     * @param a1 first argument
   1.115 -     * @param a2 second argument
   1.116 -     * @param a3 third argument
   1.117 -     */
   1.118 -    String getText(String key, String a1, String a2, String a3) {
   1.119 -        return getText(key, a1, a2, a3, null);
   1.120 -    }
   1.121 -
   1.122 -    /**
   1.123 -     * get and format message string from resource
   1.124 -     *
   1.125 -     * @param key selects message from resource
   1.126 -     * @param a1 first argument
   1.127 -     * @param a2 second argument
   1.128 -     * @param a3 third argument
   1.129 -     * @param a4 fourth argument
   1.130 -     */
   1.131 -    String getText(String key, String a1, String a2, String a3,
   1.132 -                          String a4) {
   1.133 -        try {
   1.134 -            String message = getString(key);
   1.135 -            String[] args = new String[4];
   1.136 -            args[0] = a1;
   1.137 -            args[1] = a2;
   1.138 -            args[2] = a3;
   1.139 -            args[3] = a4;
   1.140 -            return MessageFormat.format(message, (Object[])args);
   1.141 -        } catch (MissingResourceException e) {
   1.142 -            return "********** Resource for javadoc is broken. There is no " +
   1.143 -                key + " key in resource.";
   1.144 -        }
   1.145 +    String getText(String key, Object... args) {
   1.146 +        return messages.getLocalizedString(locale, key, args);
   1.147      }
   1.148  
   1.149      /**
   1.150 @@ -307,41 +239,8 @@
   1.151       *
   1.152       * @param key selects message from resource
   1.153       */
   1.154 -    public void error(SourcePosition pos, String key) {
   1.155 -        printError(pos, getText(key));
   1.156 -    }
   1.157 -
   1.158 -    /**
   1.159 -     * Print error message, increment error count.
   1.160 -     *
   1.161 -     * @param key selects message from resource
   1.162 -     * @param a1 first argument
   1.163 -     */
   1.164 -    public void error(SourcePosition pos, String key, String a1) {
   1.165 -        printError(pos, getText(key, a1));
   1.166 -    }
   1.167 -
   1.168 -    /**
   1.169 -     * Print error message, increment error count.
   1.170 -     *
   1.171 -     * @param key selects message from resource
   1.172 -     * @param a1 first argument
   1.173 -     * @param a2 second argument
   1.174 -     */
   1.175 -    public void error(SourcePosition pos, String key, String a1, String a2) {
   1.176 -        printError(pos, getText(key, a1, a2));
   1.177 -    }
   1.178 -
   1.179 -    /**
   1.180 -     * Print error message, increment error count.
   1.181 -     *
   1.182 -     * @param key selects message from resource
   1.183 -     * @param a1 first argument
   1.184 -     * @param a2 second argument
   1.185 -     * @param a3 third argument
   1.186 -     */
   1.187 -    public void error(SourcePosition pos, String key, String a1, String a2, String a3) {
   1.188 -        printError(pos, getText(key, a1, a2, a3));
   1.189 +    public void error(SourcePosition pos, String key, Object... args) {
   1.190 +        printError(pos, getText(key, args));
   1.191      }
   1.192  
   1.193      /**
   1.194 @@ -349,54 +248,8 @@
   1.195       *
   1.196       * @param key selects message from resource
   1.197       */
   1.198 -    public void warning(SourcePosition pos, String key) {
   1.199 -        printWarning(pos, getText(key));
   1.200 -    }
   1.201 -
   1.202 -    /**
   1.203 -     * Print warning message, increment warning count.
   1.204 -     *
   1.205 -     * @param key selects message from resource
   1.206 -     * @param a1 first argument
   1.207 -     */
   1.208 -    public void warning(SourcePosition pos, String key, String a1) {
   1.209 -        printWarning(pos, getText(key, a1));
   1.210 -    }
   1.211 -
   1.212 -    /**
   1.213 -     * Print warning message, increment warning count.
   1.214 -     *
   1.215 -     * @param key selects message from resource
   1.216 -     * @param a1 first argument
   1.217 -     * @param a2 second argument
   1.218 -     */
   1.219 -    public void warning(SourcePosition pos, String key, String a1, String a2) {
   1.220 -        printWarning(pos, getText(key, a1, a2));
   1.221 -    }
   1.222 -
   1.223 -    /**
   1.224 -     * Print warning message, increment warning count.
   1.225 -     *
   1.226 -     * @param key selects message from resource
   1.227 -     * @param a1 first argument
   1.228 -     * @param a2 second argument
   1.229 -     * @param a3 third argument
   1.230 -     */
   1.231 -    public void warning(SourcePosition pos, String key, String a1, String a2, String a3) {
   1.232 -        printWarning(pos, getText(key, a1, a2, a3));
   1.233 -    }
   1.234 -
   1.235 -    /**
   1.236 -     * Print warning message, increment warning count.
   1.237 -     *
   1.238 -     * @param key selects message from resource
   1.239 -     * @param a1 first argument
   1.240 -     * @param a2 second argument
   1.241 -     * @param a3 third argument
   1.242 -     */
   1.243 -    public void warning(SourcePosition pos, String key, String a1, String a2, String a3,
   1.244 -                        String a4) {
   1.245 -        printWarning(pos, getText(key, a1, a2, a3, a4));
   1.246 +    public void warning(SourcePosition pos, String key, Object... args) {
   1.247 +        printWarning(pos, getText(key, args));
   1.248      }
   1.249  
   1.250      /**
   1.251 @@ -404,41 +257,8 @@
   1.252       *
   1.253       * @param key selects message from resource
   1.254       */
   1.255 -    public void notice(String key) {
   1.256 -        printNotice(getText(key));
   1.257 -    }
   1.258 -
   1.259 -    /**
   1.260 -     * Print a message.
   1.261 -     *
   1.262 -     * @param key selects message from resource
   1.263 -     * @param a1 first argument
   1.264 -     */
   1.265 -    public void notice(String key, String a1) {
   1.266 -        printNotice(getText(key, a1));
   1.267 -    }
   1.268 -
   1.269 -    /**
   1.270 -     * Print a message.
   1.271 -     *
   1.272 -     * @param key selects message from resource
   1.273 -     * @param a1 first argument
   1.274 -     * @param a2 second argument
   1.275 -     */
   1.276 -    public void notice(String key, String a1, String a2) {
   1.277 -        printNotice(getText(key, a1, a2));
   1.278 -    }
   1.279 -
   1.280 -    /**
   1.281 -     * Print a message.
   1.282 -     *
   1.283 -     * @param key selects message from resource
   1.284 -     * @param a1 first argument
   1.285 -     * @param a2 second argument
   1.286 -     * @param a3 third argument
   1.287 -     */
   1.288 -    public void notice(String key, String a1, String a2, String a3) {
   1.289 -        printNotice(getText(key, a1, a2, a3));
   1.290 +    public void notice(String key, Object... args) {
   1.291 +        printNotice(getText(key, args));
   1.292      }
   1.293  
   1.294      /**
   1.295 @@ -475,5 +295,4 @@
   1.296      public void exit() {
   1.297          throw new ExitJavadoc();
   1.298      }
   1.299 -
   1.300  }

mercurial