test/langtools/tools/javac/processing/model/TestSourceVersion.java
changeset 47283 ce5fd3ba3fea
parent 47216 71c04702a3d5
child 48343 d4329843abf4
child 48499 239c7d9bb192
equal deleted inserted replaced
47282:65f19a0ce7e9 47283:ce5fd3ba3fea
    39  */
    39  */
    40 public class TestSourceVersion {
    40 public class TestSourceVersion {
    41     public static void main(String... args) {
    41     public static void main(String... args) {
    42         testLatestSupported();
    42         testLatestSupported();
    43         testVersionVaryingKeywords();
    43         testVersionVaryingKeywords();
       
    44         testRestrictedKeywords();
    44     }
    45     }
    45 
    46 
    46     private static void testLatestSupported() {
    47     private static void testLatestSupported() {
    47         if (SourceVersion.latest() != RELEASE_10 ||
    48         if (SourceVersion.latest() != RELEASE_10 ||
    48             SourceVersion.latestSupported() != RELEASE_10)
    49             SourceVersion.latestSupported() != RELEASE_10)
    72                 check(!isKeyword, isName(key, version),    "name",    version);
    73                 check(!isKeyword, isName(key, version),    "name",    version);
    73             }
    74             }
    74         }
    75         }
    75     }
    76     }
    76 
    77 
       
    78     private static void testRestrictedKeywords() {
       
    79         // Restricted keywords are not full keywords
       
    80 
       
    81         /*
       
    82          * JLS 3.9
       
    83          * " A further ten character sequences are restricted
       
    84          * keywords: open, module, requires, transitive, exports,
       
    85          * opens, to, uses, provides, and with"
       
    86          */
       
    87         Set<String> restrictedKeywords =
       
    88             Set.of("open", "module", "requires", "transitive", "exports",
       
    89                    "opens", "to", "uses", "provides", "with");
       
    90 
       
    91         for(String key : restrictedKeywords) {
       
    92             for(SourceVersion version : SourceVersion.values()) {
       
    93                 check(false, isKeyword(key, version), "keyword", version);
       
    94                 check(true,  isName(key, version),    "name",    version);
       
    95             }
       
    96         }
       
    97     }
       
    98 
    77     private static void check(boolean result, boolean expected,
    99     private static void check(boolean result, boolean expected,
    78                               String message, SourceVersion version) {
   100                               String message, SourceVersion version) {
    79         if (result != expected) {
   101         if (result != expected) {
    80             throw new RuntimeException("Unexpected " + message +  "-ness of _ on " + version);
   102             throw new RuntimeException("Unexpected " + message +  "-ness of _ on " + version);
    81         }
   103         }