src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/MessageRetriever.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, Oracle and/or its affiliates. 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.  Oracle designates this

@@ -21,19 +21,23 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package com.sun.tools.doclets.internal.toolkit.util;
+package jdk.javadoc.internal.doclets.toolkit.util;
 
 import java.text.MessageFormat;
 import java.util.*;
 
-import com.sun.javadoc.*;
-import com.sun.tools.doclets.internal.toolkit.Configuration;
+import javax.lang.model.element.Element;
 
+import com.sun.source.util.DocTreePath;
+import jdk.javadoc.internal.doclets.toolkit.Configuration;
 
+import static javax.tools.Diagnostic.Kind.*;
+
+
 /**
  * Retrieve and format messages stored in a resource.
  *
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.

@@ -81,27 +85,41 @@
                             String resourcelocation) {
         this.configuration = configuration;
         this.resourcelocation = resourcelocation;
     }
 
+    private void initRB() {
+        if (messageRB == null) {
+            try {
+                messageRB = ResourceBundle.getBundle(resourcelocation, configuration.getLocale());
+            } catch (MissingResourceException e) {
+                throw new Error("Fatal: Resource (" + resourcelocation
+                        + ") for javadoc doclets is missing.");
+            }
+        }
+    }
+
     /**
+     * Returns a list of key in the ResourceBundle.
+     * @return list of keys.
+     */
+    public List<String> getKeys() {
+        initRB();
+        return Collections.list(messageRB.getKeys());
+    }
+
+    /**
      * Get and format message string from resource
      *
      * @param key selects message from resource
      * @param args arguments to be replaced in the message.
+     * @return the composed text
      * @throws MissingResourceException when the key does not
      * exist in the properties file.
      */
     public String getText(String key, Object... args) throws MissingResourceException {
-        if (messageRB == null) {
-            try {
-                messageRB = ResourceBundle.getBundle(resourcelocation);
-            } catch (MissingResourceException e) {
-                throw new Error("Fatal: Resource (" + resourcelocation +
-                                    ") for javadoc doclets is missing.");
-            }
-        }
+        initRB();
         String message = messageRB.getString(key);
         return MessageFormat.format(message, args);
     }
 
     /**

@@ -108,70 +126,83 @@
      * Print error message, increment error count.
      *
      * @param pos the position of the source
      * @param msg message to print
      */
-    private void printError(SourcePosition pos, String msg) {
-        configuration.root.printError(pos, msg);
+    private void printError(DocTreePath path, String msg) {
+        configuration.reporter.print(ERROR, path, msg);
     }
 
     /**
      * Print error message, increment error count.
      *
      * @param msg message to print
      */
     private void printError(String msg) {
-        configuration.root.printError(msg);
+        configuration.reporter.print(ERROR, msg);
     }
 
     /**
      * Print warning message, increment warning count.
      *
      * @param pos the position of the source
      * @param msg message to print
      */
-    private void printWarning(SourcePosition pos, String msg) {
-        configuration.root.printWarning(pos, msg);
+    private void printWarning(DocTreePath path, String msg) {
+        configuration.reporter.print(WARNING, path, msg);
     }
 
+    private void printWarning(Element e, String msg) {
+        configuration.reporter.print(WARNING, e, msg);
+    }
+
     /**
      * Print warning message, increment warning count.
      *
      * @param msg message to print
      */
     private void printWarning(String msg) {
-        configuration.root.printWarning(msg);
+        configuration.reporter.print(WARNING, msg);
     }
 
-    /**
-     * Print a message.
-     *
-     * @param pos the position of the source
-     * @param msg message to print
-     */
-    private void printNotice(SourcePosition pos, String msg) {
-        configuration.root.printNotice(pos, msg);
-    }
+//    Note: the following do not appear to be needed any more, delete me.
+//    /**
+//     * Print a message.
+//     *
+//     * @param pos the position of the source
+//     * @param msg message to print
+//     */
+//    private void printNotice(DocTreePath path, String msg) {
+//        DocEnv env = ((RootDocImpl)configuration.root).env;
+//        if (env.isQuiet() || env.isSilent()) {
+//            return;
+//        }
+//        configuration.reporter.print(NOTE, path, msg);
+//    }
 
-    /**
-     * Print a message.
-     *
-     * @param msg message to print
-     */
-    private void printNotice(String msg) {
-        configuration.root.printNotice(msg);
-    }
+//    Note: does not appear to be needed any more.
+//    /**
+//     * Print a message.
+//     *
+//     * @param pos the position of the source
+//     * @param key selects message from resource
+//     * @param args arguments to be replaced in the message.
+//     */
+//    public void notice(DocTreePath path, String key, Object... args) {
+//        printNotice(path, getText(key, args));
+//    }
 
+    // ERRORS
     /**
      * Print error message, increment error count.
      *
-     * @param pos the position of the source
+     * @param path the path to the source
      * @param key selects message from resource
      * @param args arguments to be replaced in the message.
      */
-    public void error(SourcePosition pos, String key, Object... args) {
-        printError(pos, getText(key, args));
+    public void error(DocTreePath path, String key, Object... args) {
+        printError(path, getText(key, args));
     }
 
     /**
      * Print error message, increment error count.
      *

@@ -180,20 +211,33 @@
      */
     public void error(String key, Object... args) {
         printError(getText(key, args));
     }
 
+    // WARNINGS
     /**
      * Print warning message, increment warning count.
+
+     * @param path the path to the source
+     * @param key selects message from resource
+     * @param args arguments to be replaced in the message.
+     */
+    public void warning(DocTreePath path, String key, Object... args) {
+        if (configuration.showMessage(path, key))
+            printWarning(path, getText(key, args));
+    }
+
+    /**
+     * Print warning message, increment warning count.
      *
-     * @param pos the position of the source
+     * @param e element target of the message
      * @param key selects message from resource
      * @param args arguments to be replaced in the message.
      */
-    public void warning(SourcePosition pos, String key, Object... args) {
-        if (configuration.showMessage(pos, key))
-            printWarning(pos, getText(key, args));
+    public void warning(Element e, String key, Object... args) {
+        if (configuration.showMessage(e, key))
+            printWarning(e, getText(key, args));
     }
 
     /**
      * Print warning message, increment warning count.
      *

@@ -202,20 +246,22 @@
      */
     public void warning(String key, Object... args) {
         printWarning(getText(key, args));
     }
 
+    // NOTICES
     /**
      * Print a message.
      *
-     * @param pos the position of the source
-     * @param key selects message from resource
-     * @param args arguments to be replaced in the message.
+     * @param msg message to print
      */
-    public void notice(SourcePosition pos, String key, Object... args) {
-        printNotice(pos, getText(key, args));
+    private void printNotice(String msg) {
+        if (configuration.quiet) {
+            return;
     }
+        configuration.reporter.print(NOTE, msg);
+    }
 
     /**
      * Print a message.
      *
      * @param key selects message from resource