langtools/test/tools/javac/diags/CheckResourceKeys.java
author jlahoda
Thu, 13 Feb 2014 13:38:48 +0100
changeset 23114 7fe55d6324d5
parent 15385 ee1eebe7e210
child 27319 030080f03e4f
permissions -rw-r--r--
8033961: Formatting of -Xlint: command line help Summary: Improving formatting of command line help for -Xlint, including a short description of each lint. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     1
/*
23114
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     4
 *
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     8
 *
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    13
 * accompanied this code).
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    14
 *
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    18
 *
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    21
 * questions.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    22
 */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    23
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    24
/*
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    25
 * @test
8637
be1b564b50aa 6980021: javac should document @file command line option
jjg
parents: 6144
diff changeset
    26
 * @bug 6964768 6964461 6964469 6964487 6964460 6964481 6980021
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    27
 * @summary need test program to validate javac resource bundles
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    28
 */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    29
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    30
import java.io.*;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    31
import java.util.*;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    32
import javax.tools.*;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    33
import com.sun.tools.classfile.*;
23114
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
    34
import com.sun.tools.javac.code.Lint.LintCategory;
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    35
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    36
/**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    37
 * Compare string constants in javac classes against keys in javac resource bundles.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    38
 */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    39
public class CheckResourceKeys {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    40
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    41
     * Main program.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    42
     * Options:
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    43
     * -finddeadkeys
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    44
     *      look for keys in resource bundles that are no longer required
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    45
     * -findmissingkeys
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    46
     *      look for keys in resource bundles that are missing
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    47
     *
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    48
     * @throws Exception if invoked by jtreg and errors occur
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    49
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    50
    public static void main(String... args) throws Exception {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    51
        CheckResourceKeys c = new CheckResourceKeys();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    52
        if (c.run(args))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    53
            return;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    54
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    55
        if (is_jtreg())
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    56
            throw new Exception(c.errors + " errors occurred");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    57
        else
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    58
            System.exit(1);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    59
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    60
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    61
    static boolean is_jtreg() {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    62
        return (System.getProperty("test.src") != null);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    63
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    64
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    65
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    66
     * Main entry point.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    67
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    68
    boolean run(String... args) throws Exception {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    69
        boolean findDeadKeys = false;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    70
        boolean findMissingKeys = false;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    71
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    72
        if (args.length == 0) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    73
            if (is_jtreg()) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    74
                findDeadKeys = true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    75
                findMissingKeys = true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    76
            } else {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    77
                System.err.println("Usage: java CheckResourceKeys <options>");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    78
                System.err.println("where options include");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    79
                System.err.println("  -finddeadkeys      find keys in resource bundles which are no longer required");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    80
                System.err.println("  -findmissingkeys   find keys in resource bundles that are required but missing");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    81
                return true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    82
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    83
        } else {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    84
            for (String arg: args) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    85
                if (arg.equalsIgnoreCase("-finddeadkeys"))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    86
                    findDeadKeys = true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    87
                else if (arg.equalsIgnoreCase("-findmissingkeys"))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    88
                    findMissingKeys = true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    89
                else
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    90
                    error("bad option: " + arg);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    91
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    92
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    93
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    94
        if (errors > 0)
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    95
            return false;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    96
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    97
        Set<String> codeStrings = getCodeStrings();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    98
        Set<String> resourceKeys = getResourceKeys();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
    99
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   100
        if (findDeadKeys)
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   101
            findDeadKeys(codeStrings, resourceKeys);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   102
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   103
        if (findMissingKeys)
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   104
            findMissingKeys(codeStrings, resourceKeys);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   105
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   106
        return (errors == 0);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   107
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   108
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   109
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   110
     * Find keys in resource bundles which are probably no longer required.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   111
     * A key is probably required if there is a string fragment in the code
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   112
     * that is part of the resource key, or if the key is well-known
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   113
     * according to various pragmatic rules.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   114
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   115
    void findDeadKeys(Set<String> codeStrings, Set<String> resourceKeys) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   116
        String[] prefixes = {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   117
            "compiler.err.", "compiler.warn.", "compiler.note.", "compiler.misc.",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   118
            "javac."
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   119
        };
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   120
        for (String rk: resourceKeys) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   121
            // some keys are used directly, without a prefix.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   122
            if (codeStrings.contains(rk))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   123
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   124
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   125
            // remove standard prefix
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   126
            String s = null;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   127
            for (int i = 0; i < prefixes.length && s == null; i++) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   128
                if (rk.startsWith(prefixes[i])) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   129
                    s = rk.substring(prefixes[i].length());
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   130
                }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   131
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   132
            if (s == null) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   133
                error("Resource key does not start with a standard prefix: " + rk);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   134
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   135
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   136
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   137
            if (codeStrings.contains(s))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   138
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   139
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   140
            // keys ending in .1 are often synthesized
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   141
            if (s.endsWith(".1") && codeStrings.contains(s.substring(0, s.length() - 2)))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   142
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   143
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   144
            // verbose keys are generated by ClassReader.printVerbose
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   145
            if (s.startsWith("verbose.") && codeStrings.contains(s.substring(8)))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   146
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   147
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   148
            // mandatory warning messages are synthesized with no characteristic substring
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   149
            if (isMandatoryWarningString(s))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   150
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   151
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   152
            // check known (valid) exceptions
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   153
            if (knownRequired.contains(rk))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   154
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   155
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   156
            // check known suspects
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   157
            if (needToInvestigate.contains(rk))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   158
                continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   159
23114
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   160
            //check lint description keys:
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   161
            if (s.startsWith("opt.Xlint.desc.")) {
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   162
                String option = s.substring(15);
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   163
                boolean found = false;
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   164
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   165
                for (LintCategory lc : LintCategory.values()) {
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   166
                    if (option.equals(lc.option))
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   167
                        found = true;
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   168
                }
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   169
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   170
                if (found)
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   171
                    continue;
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   172
            }
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   173
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   174
            error("Resource key not found in code: " + rk);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   175
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   176
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   177
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   178
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   179
     * The keys for mandatory warning messages are all synthesized and do not
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   180
     * have a significant recognizable substring to look for.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   181
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   182
    private boolean isMandatoryWarningString(String s) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   183
        String[] bases = { "deprecated", "unchecked", "varargs", "sunapi" };
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   184
        String[] tails = { ".filename", ".filename.additional", ".plural", ".plural.additional", ".recompile" };
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   185
        for (String b: bases) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   186
            if (s.startsWith(b)) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   187
                String tail = s.substring(b.length());
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   188
                for (String t: tails) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   189
                    if (tail.equals(t))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   190
                        return true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   191
                }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   192
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   193
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   194
        return false;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   195
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   196
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   197
    Set<String> knownRequired = new TreeSet<String>(Arrays.asList(
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   198
        // See Resolve.getErrorKey
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   199
        "compiler.err.cant.resolve.args",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   200
        "compiler.err.cant.resolve.args.params",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   201
        "compiler.err.cant.resolve.location.args",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   202
        "compiler.err.cant.resolve.location.args.params",
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 12213
diff changeset
   203
        "compiler.misc.cant.resolve.location.args",
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 12213
diff changeset
   204
        "compiler.misc.cant.resolve.location.args.params",
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   205
        // JavaCompiler, reports #errors and #warnings
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   206
        "compiler.misc.count.error",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   207
        "compiler.misc.count.error.plural",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   208
        "compiler.misc.count.warn",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   209
        "compiler.misc.count.warn.plural",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   210
        // Used for LintCategory
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   211
        "compiler.warn.lintOption",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   212
        // Other
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   213
        "compiler.misc.base.membership"                                 // (sic)
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   214
        ));
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   215
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   216
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   217
    Set<String> needToInvestigate = new TreeSet<String>(Arrays.asList(
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14452
diff changeset
   218
        "compiler.misc.fatal.err.cant.close.loader",        // Supressed by JSR308
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   219
        "compiler.err.cant.read.file",                      // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   220
        "compiler.err.illegal.self.ref",                    // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   221
        "compiler.err.io.exception",                        // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   222
        "compiler.err.limit.pool.in.class",                 // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   223
        "compiler.err.name.reserved.for.internal.use",      // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   224
        "compiler.err.no.match.entry",                      // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   225
        "compiler.err.not.within.bounds.explain",           // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   226
        "compiler.err.signature.doesnt.match.intf",         // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   227
        "compiler.err.signature.doesnt.match.supertype",    // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   228
        "compiler.err.type.var.more.than.once",             // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   229
        "compiler.err.type.var.more.than.once.in.result",   // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   230
        "compiler.misc.ccf.found.later.version",            // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   231
        "compiler.misc.non.denotable.type",                 // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   232
        "compiler.misc.unnamed.package",                    // should be required, CR 6964147
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   233
        "compiler.misc.verbose.retro",                      // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   234
        "compiler.misc.verbose.retro.with",                 // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   235
        "compiler.misc.verbose.retro.with.list",            // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   236
        "compiler.warn.proc.type.already.exists",           // TODO in JavacFiler
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   237
        "javac.err.invalid.arg",                            // UNUSED ??
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   238
        "javac.opt.arg.class",                              // UNUSED ??
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   239
        "javac.opt.arg.pathname",                           // UNUSED ??
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   240
        "javac.opt.moreinfo",                               // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   241
        "javac.opt.nogj",                                   // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   242
        "javac.opt.printflat",                              // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   243
        "javac.opt.printsearch",                            // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   244
        "javac.opt.prompt",                                 // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   245
        "javac.opt.retrofit",                               // UNUSED
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   246
        "javac.opt.s",                                      // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   247
        "javac.opt.scramble",                               // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   248
        "javac.opt.scrambleall"                             // option commented out
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   249
        ));
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   250
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   251
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   252
     * For all strings in the code that look like they might be fragments of
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   253
     * a resource key, verify that a key exists.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   254
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   255
    void findMissingKeys(Set<String> codeStrings, Set<String> resourceKeys) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   256
        for (String cs: codeStrings) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   257
            if (cs.matches("[A-Za-z][^.]*\\..*")) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   258
                // ignore filenames (i.e. in SourceFile attribute
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   259
                if (cs.matches(".*\\.java"))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   260
                    continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   261
                // ignore package and class names
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   262
                if (cs.matches("(com|java|javax|sun)\\.[A-Za-z.]+"))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   263
                    continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   264
                // explicit known exceptions
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   265
                if (noResourceRequired.contains(cs))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   266
                    continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   267
                // look for matching resource
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   268
                if (hasMatch(resourceKeys, cs))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   269
                    continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   270
                error("no match for \"" + cs + "\"");
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   271
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   272
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   273
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   274
    // where
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   275
    private Set<String> noResourceRequired = new HashSet<String>(Arrays.asList(
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   276
            // system properties
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   277
            "application.home", // in Paths.java
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   278
            "env.class.path",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   279
            "line.separator",
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 9087
diff changeset
   280
            "os.name",
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   281
            "user.dir",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   282
            // file names
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   283
            "ct.sym",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   284
            "rt.jar",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   285
            "tools.jar",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   286
            // -XD option names
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   287
            "process.packages",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   288
            "ignore.symbol.file",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   289
            // prefix/embedded strings
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   290
            "compiler.",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   291
            "compiler.misc.",
23114
7fe55d6324d5 8033961: Formatting of -Xlint: command line help
jlahoda
parents: 15385
diff changeset
   292
            "opt.Xlint.desc.",
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   293
            "count.",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   294
            "illegal.",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   295
            "javac.",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   296
            "verbose."
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   297
    ));
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   298
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   299
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   300
     * Look for a resource that ends in this string fragment.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   301
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   302
    boolean hasMatch(Set<String> resourceKeys, String s) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   303
        for (String rk: resourceKeys) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   304
            if (rk.endsWith(s))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   305
                return true;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   306
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   307
        return false;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   308
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   309
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   310
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   311
     * Get the set of strings from (most of) the javac classfiles.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   312
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   313
    Set<String> getCodeStrings() throws IOException {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   314
        Set<String> results = new TreeSet<String>();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   315
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   316
        JavaFileManager fm = c.getStandardFileManager(null, null, null);
6144
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   317
        JavaFileManager.Location javacLoc = findJavacLocation(fm);
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   318
        String[] pkgs = {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   319
            "javax.annotation.processing",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   320
            "javax.lang.model",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   321
            "javax.tools",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   322
            "com.sun.source",
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   323
            "com.sun.tools.javac"
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   324
        };
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   325
        for (String pkg: pkgs) {
6144
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   326
            for (JavaFileObject fo: fm.list(javacLoc,
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   327
                    pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   328
                String name = fo.getName();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   329
                // ignore resource files, and files which are not really part of javac
14452
f083d81c2b46 8003134: CheckResourceKeys issues
jjg
parents: 14447
diff changeset
   330
                if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*")
f083d81c2b46 8003134: CheckResourceKeys issues
jjg
parents: 14447
diff changeset
   331
                        || name.matches(".*CreateSymbols\\.class.*"))
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   332
                    continue;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   333
                scan(fo, results);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   334
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   335
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   336
        return results;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   337
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   338
6144
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   339
    // depending on how the test is run, javac may be on bootclasspath or classpath
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   340
    JavaFileManager.Location findJavacLocation(JavaFileManager fm) {
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   341
        JavaFileManager.Location[] locns =
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   342
            { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   343
        try {
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   344
            for (JavaFileManager.Location l: locns) {
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   345
                JavaFileObject fo = fm.getJavaFileForInput(l,
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   346
                    "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS);
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   347
                if (fo != null)
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   348
                    return l;
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   349
            }
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   350
        } catch (IOException e) {
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   351
            throw new Error(e);
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   352
        }
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   353
        throw new IllegalStateException("Cannot find javac");
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   354
    }
12fbc9782944 6968434: test CheckResourceKeys fails on control builds
jjg
parents: 6031
diff changeset
   355
6031
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   356
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   357
     * Get the set of strings from a class file.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   358
     * Only strings that look like they might be a resource key are returned.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   359
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   360
    void scan(JavaFileObject fo, Set<String> results) throws IOException {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   361
        InputStream in = fo.openInputStream();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   362
        try {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   363
            ClassFile cf = ClassFile.read(in);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   364
            for (ConstantPool.CPInfo cpinfo: cf.constant_pool.entries()) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   365
                if (cpinfo.getTag() == ConstantPool.CONSTANT_Utf8) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   366
                    String v = ((ConstantPool.CONSTANT_Utf8_info) cpinfo).value;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   367
                    if (v.matches("[A-Za-z0-9-_.]+"))
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   368
                        results.add(v);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   369
                }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   370
            }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   371
        } catch (ConstantPoolException ignore) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   372
        } finally {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   373
            in.close();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   374
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   375
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   376
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   377
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   378
     * Get the set of keys from the javac resource bundles.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   379
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   380
    Set<String> getResourceKeys() {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   381
        Set<String> results = new TreeSet<String>();
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   382
        for (String name : new String[]{"javac", "compiler"}) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   383
            ResourceBundle b =
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   384
                    ResourceBundle.getBundle("com.sun.tools.javac.resources." + name);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   385
            results.addAll(b.keySet());
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   386
        }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   387
        return results;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   388
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   389
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   390
    /**
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   391
     * Report an error.
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   392
     */
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   393
    void error(String msg) {
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   394
        System.err.println("Error: " + msg);
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   395
        errors++;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   396
    }
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   397
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   398
    int errors;
50004868a787 6964768: need test program to validate javac resource bundles
jjg
parents:
diff changeset
   399
}