langtools/src/share/classes/com/sun/tools/javac/util/JavacMessages.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 9069 bcab4a29758f
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1652
diff changeset
     2
 * Copyright (c) 2005, 2008, 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. */
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    47
    protected static final Context.Key<JavacMessages> messagesKey =
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    48
        new Context.Key<JavacMessages>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    50
    /** Get the JavacMessages instance for this context. */
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    51
    public static JavacMessages instance(Context context) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    52
        JavacMessages instance = context.get(messagesKey);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        if (instance == null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    54
            instance = new JavacMessages(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    58
    private Map<Locale, SoftReference<List<ResourceBundle>>> bundleCache;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    59
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    60
    private List<String> bundleNames;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    62
    private Locale currentLocale;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    63
    private List<ResourceBundle> currentBundles;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    64
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    65
    public Locale getCurrentLocale() {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    66
        return currentLocale;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    69
    public void setCurrentLocale(Locale locale) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    70
        if (locale == null) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    71
            locale = Locale.getDefault();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    72
        }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    73
        this.currentBundles = getBundles(locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    74
        this.currentLocale = locale;
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
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    77
    /** Creates a JavacMessages object.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    79
    public JavacMessages(Context context) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    80
        this(defaultBundleName);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    81
        context.put(messagesKey, this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    84
    /** Creates a JavacMessages object.
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    85
     * @param bundleName the name to identify the resource buundle of localized messages.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    87
    public JavacMessages(String bundleName) throws MissingResourceException {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    88
        bundleNames = List.nil();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    89
        bundleCache = new HashMap<Locale, SoftReference<List<ResourceBundle>>>();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    90
        add(bundleName);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    91
        setCurrentLocale(Locale.getDefault());
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    92
    }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    93
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    94
    public JavacMessages() throws MissingResourceException {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    95
        this(defaultBundleName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public void add(String bundleName) throws MissingResourceException {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
    99
        bundleNames = bundleNames.prepend(bundleName);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   100
        if (!bundleCache.isEmpty())
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   101
            bundleCache.clear();
1476
4b54f7c2d3db 6759682: APT: compiler message file broken after refactoring of com.sun.tools.javac.util.Message
mcimadamore
parents: 1471
diff changeset
   102
        currentBundles = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   105
    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
   106
        if (locale == currentLocale && currentBundles != null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   107
            return currentBundles;
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   108
        SoftReference<List<ResourceBundle>> bundles = bundleCache.get(locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   109
        List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   110
        if (bundleList == null) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   111
            bundleList = List.nil();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   112
            for (String bundleName : bundleNames) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   113
                try {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   114
                    ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   115
                    bundleList = bundleList.prepend(rb);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   116
                } catch (MissingResourceException e) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   117
                    throw new InternalError("Cannot find javac resource bundle for locale " + locale);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   118
                }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   119
            }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   120
            bundleCache.put(locale, new SoftReference<List<ResourceBundle>>(bundleList));
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   121
        }
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   122
        return bundleList;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /** Gets the localized string corresponding to a key, formatted with a set of args.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public String getLocalizedString(String key, Object... args) {
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   128
        return getLocalizedString(currentLocale, key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   131
    public String getLocalizedString(Locale l, String key, Object... args) {
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   132
        if (l == null)
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   133
            l = getCurrentLocale();
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   134
        return getLocalizedString(getBundles(l), key, args);
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   135
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    /* Static access:
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     * javac has a firmly entrenched notion of a default message bundle
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     * which it can access from any static context. This is used to get
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     * easy access to simple localized strings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    private static final String defaultBundleName =
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        "com.sun.tools.javac.resources.compiler";
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    private static ResourceBundle defaultBundle;
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   146
    private static JavacMessages defaultMessages;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * Gets a localized string from the compiler's default bundle.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    // used to support legacy Log.getLocalizedString
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    static String getDefaultLocalizedString(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        return getLocalizedString(List.of(getDefaultBundle()), key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    // used to support legacy static Diagnostic.fragment
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   158
    @Deprecated
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   159
    static JavacMessages getDefaultMessages() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        if (defaultMessages == null)
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 10
diff changeset
   161
            defaultMessages = new JavacMessages(defaultBundleName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        return defaultMessages;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public static ResourceBundle getDefaultBundle() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
            if (defaultBundle == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                defaultBundle = ResourceBundle.getBundle(defaultBundleName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
            return defaultBundle;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            throw new Error("Fatal: Resource for compiler is missing", e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    private static String getLocalizedString(List<ResourceBundle> bundles,
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                                             String key,
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                                             Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
       String msg = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        for (List<ResourceBundle> l = bundles; l.nonEmpty() && msg == null; l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            ResourceBundle rb = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                msg = rb.getString(key);
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
            catch (MissingResourceException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                // ignore, try other bundles in list
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        if (msg == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            msg = "compiler message file broken: key=" + key +
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                " arguments={0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}";
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        return MessageFormat.format(msg, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
}