langtools/src/share/classes/com/sun/tools/javac/util/JavacMessages.java
author jlahoda
Fri, 01 Aug 2014 11:09:40 -0700
changeset 25848 3bc09f4676a9
parent 25287 d2440361b323
permissions -rw-r--r--
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks. Summary: Generalizing the crules infrastructure, adding a new analyzer to check String concatenation in Assert calls. Reviewed-by: jjg, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 22163
diff changeset
     2
 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.util;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    28
import com.sun.tools.javac.api.Messages;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    29
import java.lang.ref.SoftReference;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.util.ResourceBundle;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.MissingResourceException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.text.MessageFormat;
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    33
import java.util.HashMap;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    34
import java.util.Locale;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    35
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/**
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    38
 *  Support for formatted localized messages.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    40
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    41
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    45
public class JavacMessages implements Messages {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    46
    /** The context key for the JavacMessages object. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
    47
    public static final Context.Key<JavacMessages> messagesKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    49
    /** Get the JavacMessages instance for this context. */
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    50
    public static JavacMessages instance(Context context) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    51
        JavacMessages instance = context.get(messagesKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        if (instance == null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    53
            instance = new JavacMessages(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    57
    private Map<Locale, SoftReference<List<ResourceBundle>>> bundleCache;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    58
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    59
    private List<String> bundleNames;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    61
    private Locale currentLocale;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    62
    private List<ResourceBundle> currentBundles;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    63
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    64
    public Locale getCurrentLocale() {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    65
        return currentLocale;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    68
    public void setCurrentLocale(Locale locale) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    69
        if (locale == null) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    70
            locale = Locale.getDefault();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    71
        }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    72
        this.currentBundles = getBundles(locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    73
        this.currentLocale = locale;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    74
    }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    75
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    76
    /** Creates a JavacMessages object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    78
    public JavacMessages(Context context) {
9069
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    79
        this(defaultBundleName, context.get(Locale.class));
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    80
        context.put(messagesKey, this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    83
    /** Creates a JavacMessages object.
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 9069
diff changeset
    84
     * @param bundleName the name to identify the resource bundle of localized messages.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    86
    public JavacMessages(String bundleName) throws MissingResourceException {
9069
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    87
        this(bundleName, null);
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    88
    }
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    89
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    90
    /** Creates a JavacMessages object.
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 9069
diff changeset
    91
     * @param bundleName the name to identify the resource bundle of localized messages.
9069
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    92
     */
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    93
    public JavacMessages(String bundleName, Locale locale) throws MissingResourceException {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    94
        bundleNames = List.nil();
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
    95
        bundleCache = new HashMap<>();
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    96
        add(bundleName);
9069
bcab4a29758f 6597678: JavaCompiler.getStandardFileManager always uses default charset not the one that user specifies
jjg
parents: 5847
diff changeset
    97
        setCurrentLocale(locale);
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    98
    }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    99
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   100
    public JavacMessages() throws MissingResourceException {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   101
        this(defaultBundleName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    public void add(String bundleName) throws MissingResourceException {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   105
        bundleNames = bundleNames.prepend(bundleName);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   106
        if (!bundleCache.isEmpty())
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   107
            bundleCache.clear();
1476
4b54f7c2d3db 6759682: APT: compiler message file broken after refactoring of com.sun.tools.javac.util.Message
mcimadamore
parents: 1471
diff changeset
   108
        currentBundles = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   111
    public List<ResourceBundle> getBundles(Locale locale) {
1476
4b54f7c2d3db 6759682: APT: compiler message file broken after refactoring of com.sun.tools.javac.util.Message
mcimadamore
parents: 1471
diff changeset
   112
        if (locale == currentLocale && currentBundles != null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   113
            return currentBundles;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   114
        SoftReference<List<ResourceBundle>> bundles = bundleCache.get(locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   115
        List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   116
        if (bundleList == null) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   117
            bundleList = List.nil();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   118
            for (String bundleName : bundleNames) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   119
                try {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   120
                    ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   121
                    bundleList = bundleList.prepend(rb);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   122
                } catch (MissingResourceException e) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   123
                    throw new InternalError("Cannot find javac resource bundle for locale " + locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   124
                }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   125
            }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
   126
            bundleCache.put(locale, new SoftReference<>(bundleList));
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   127
        }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   128
        return bundleList;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /** Gets the localized string corresponding to a key, formatted with a set of args.
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    public String getLocalizedString(String key, Object... args) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   134
        return getLocalizedString(currentLocale, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   137
    public String getLocalizedString(Locale l, String key, Object... args) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   138
        if (l == null)
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   139
            l = getCurrentLocale();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   140
        return getLocalizedString(getBundles(l), key, args);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   141
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    /* Static access:
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * javac has a firmly entrenched notion of a default message bundle
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * which it can access from any static context. This is used to get
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * easy access to simple localized strings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    private static final String defaultBundleName =
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        "com.sun.tools.javac.resources.compiler";
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    private static ResourceBundle defaultBundle;
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   152
    private static JavacMessages defaultMessages;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 22163
diff changeset
   156
     * Returns a localized string from the compiler's default bundle.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    // used to support legacy Log.getLocalizedString
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    static String getDefaultLocalizedString(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        return getLocalizedString(List.of(getDefaultBundle()), key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    // used to support legacy static Diagnostic.fragment
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   164
    @Deprecated
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   165
    static JavacMessages getDefaultMessages() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        if (defaultMessages == null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   167
            defaultMessages = new JavacMessages(defaultBundleName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        return defaultMessages;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    public static ResourceBundle getDefaultBundle() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            if (defaultBundle == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                defaultBundle = ResourceBundle.getBundle(defaultBundleName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            return defaultBundle;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            throw new Error("Fatal: Resource for compiler is missing", e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    private static String getLocalizedString(List<ResourceBundle> bundles,
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                                             String key,
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                                             Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
       String msg = null;
21488
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   186
       for (List<ResourceBundle> l = bundles; l.nonEmpty() && msg == null; l = l.tail) {
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   187
           ResourceBundle rb = l.head;
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   188
           try {
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   189
               msg = rb.getString(key);
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   190
           }
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   191
           catch (MissingResourceException e) {
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   192
               // ignore, try other bundles in list
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   193
           }
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   194
       }
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   195
       if (msg == null) {
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   196
           msg = "compiler message file broken: key=" + key +
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   197
               " arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}";
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   198
       }
4a69e26aa999 8025290: javac implicit versus explicit lambda compilation error
vromero
parents: 11052
diff changeset
   199
       return MessageFormat.format(msg, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
}