test/langtools/tools/javac/switchextra/RuleParsingTest.java
changeset 53878 4584d0331318
parent 53023 6879069d9d94
child 59021 cfc7bb9a5a92
equal deleted inserted replaced
53877:dfea18758dfa 53878:4584d0331318
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    46 import com.sun.source.util.Trees;
    46 import com.sun.source.util.Trees;
    47 
    47 
    48 public class RuleParsingTest {
    48 public class RuleParsingTest {
    49 
    49 
    50     public static void main(String[] args) throws Exception {
    50     public static void main(String[] args) throws Exception {
    51         new RuleParsingTest().testParseComplexExpressions();
    51         String sourceVersion = Integer.toString(Runtime.version().feature());
       
    52         new RuleParsingTest().testParseComplexExpressions(sourceVersion);
    52     }
    53     }
    53 
    54 
    54     void testParseComplexExpressions() throws Exception {
    55     void testParseComplexExpressions(String sourceVersion) throws Exception {
    55         String[] expressions = {
    56         String[] expressions = {
    56             "(a)",
    57             "(a)",
    57             "a",
    58             "a",
    58             "a + a",
    59             "a + a",
    59             "~a + a",
    60             "~a + a",
    92         assert tool != null;
    93         assert tool != null;
    93         DiagnosticListener<JavaFileObject> noErrors = d -> { throw new AssertionError(d.getMessage(null)); };
    94         DiagnosticListener<JavaFileObject> noErrors = d -> { throw new AssertionError(d.getMessage(null)); };
    94 
    95 
    95         StringWriter out = new StringWriter();
    96         StringWriter out = new StringWriter();
    96         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
    97         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
    97             List.of("--enable-preview", "-source", "13"), null,
    98             List.of("--enable-preview", "-source", sourceVersion), null,
    98             Arrays.asList(new MyFileObject(code.toString())));
    99             Arrays.asList(new MyFileObject(code.toString())));
    99         CompilationUnitTree cut = ct.parse().iterator().next();
   100         CompilationUnitTree cut = ct.parse().iterator().next();
   100         Trees trees = Trees.instance(ct);
   101         Trees trees = Trees.instance(ct);
   101         new TreePathScanner<Void, Void>() {
   102         new TreePathScanner<Void, Void>() {
   102             @Override
   103             @Override