src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Messages.java
author ehelin
Fri, 02 Mar 2018 09:20:16 +0100
changeset 49318 f5954447b0bd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8197842: Remove unused macros VM_STRUCTS_EXT and VM_TYPES_EXT Reviewed-by: sjohanss, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     1
/*
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     4
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    10
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    15
 * accompanied this code).
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    16
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    20
 *
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    23
 * questions.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    24
 */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    25
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    26
package com.sun.tools.jdeprscan;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    27
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    28
import java.text.MessageFormat;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    29
import java.util.Locale;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    30
import java.util.MissingResourceException;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    31
import java.util.ResourceBundle;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    32
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    33
/**
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    34
 * Message handling class for localization.
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    35
 */
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    36
public class Messages {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    37
    /** Indicates whether line separators in messages need replacement. */
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    38
    static final boolean REPLACE_LINESEP = ! System.lineSeparator().equals("\n");
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    39
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    40
    /** The resource bundle, must be non-null. */
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    41
    static final ResourceBundle bundle;
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    42
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    43
    static {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    44
        Locale locale = Locale.getDefault();
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    45
        try {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    46
            bundle = ResourceBundle.getBundle("com.sun.tools.jdeprscan.resources.jdeprscan", locale);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    47
        } catch (MissingResourceException e) {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    48
            throw new InternalError("Cannot find jdeprscan resource bundle for locale " + locale, e);
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    49
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    50
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    51
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    52
    /**
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    53
     * Gets a message from the resource bundle. If necessary, translates "\n",
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    54
     * the line break string used in the message file, to the system-specific
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    55
     * line break string.
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    56
     *
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    57
     * @param key the message key
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    58
     * @param args the message arguments
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    59
     */
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    60
    public static String get(String key, Object... args) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    61
        try {
41863
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    62
            String msg = MessageFormat.format(bundle.getString(key), args);
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    63
            if (REPLACE_LINESEP) {
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    64
                msg = msg.replace("\n", System.lineSeparator());
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    65
            }
98b049c8b848 8165646: (jdeprscan) adjust tool output to improve clarity
smarks
parents: 40596
diff changeset
    66
            return msg;
40596
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    67
        } catch (MissingResourceException e) {
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    68
            throw new InternalError("Missing message: " + key, e);
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    69
        }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    70
    }
43b19b36e8e6 8145464: implement deprecation static analysis tool
smarks
parents:
diff changeset
    71
}