LetExpressionsAreUnnecessarilyGeneratedTest.java revision 3571:88cc9b782624
13229Spst/* 23229Spst * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 33229Spst * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43229Spst * 53229Spst * This code is free software; you can redistribute it and/or modify it 63229Spst * under the terms of the GNU General Public License version 2 only, as 73229Spst * published by the Free Software Foundation. 83229Spst * 93229Spst * This code is distributed in the hope that it will be useful, but WITHOUT 103229Spst * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 113229Spst * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 123229Spst * version 2 for more details (a copy is included in the LICENSE file that 133229Spst * accompanied this code). 143229Spst * 153229Spst * You should have received a copy of the GNU General Public License version 163229Spst * 2 along with this work; if not, write to the Free Software Foundation, 173229Spst * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 183229Spst * 193229Spst * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 203229Spst * or visit www.oracle.com if you need additional information or have any 213229Spst * questions. 223229Spst */ 233229Spst 243229Spst/** 253229Spst * @test 8160156 263229Spst * @summary javac is generating let expressions unnecessarily 273229Spst * @library /tools/lib 283229Spst * @modules 293229Spst * jdk.compiler/com.sun.tools.javac.api 303229Spst * jdk.compiler/com.sun.tools.javac.main 313229Spst * @build toolbox.ToolBox toolbox.JavacTask 323229Spst * @run main LetExpressionsAreUnnecessarilyGeneratedTest 333229Spst */ 343229Spst 353229Spstimport java.nio.file.Files; 363229Spstimport java.nio.file.Path; 373229Spstimport java.nio.file.Paths; 383229Spst 393229Spstimport toolbox.JavacTask; 403229Spstimport toolbox.Task; 413229Spstimport toolbox.TestRunner; 423229Spstimport toolbox.ToolBox; 433229Spst 443229Spstpublic class LetExpressionsAreUnnecessarilyGeneratedTest extends TestRunner { 453229Spst ToolBox tb; 463229Spst 473229Spst public static void main(String... args) throws Exception { 483229Spst new LetExpressionsAreUnnecessarilyGeneratedTest().runTests(); 493229Spst } 503229Spst 513229Spst public LetExpressionsAreUnnecessarilyGeneratedTest() { 523229Spst super(System.err); 533229Spst tb = new ToolBox(); 543229Spst } 553229Spst 563229Spst protected void runTests() throws Exception { 573229Spst runTests(m -> new Object[] { Paths.get(m.getName()) }); 583229Spst } 593229Spst 603229Spst @Test 613229Spst public void testDontGenerateLetExpr(Path testBase) throws Exception { 623229Spst Path src = testBase.resolve("src"); 633229Spst tb.writeJavaFiles(src, 643229Spst "package base;\n" + 653229Spst "public abstract class Base {\n" + 663229Spst " protected int i = 1;\n" + 673229Spst "}", 683229Spst 693229Spst "package sub;\n" + 703229Spst "import base.Base;\n" + 713229Spst "public class Sub extends Base {\n" + 723229Spst " private int i = 4;\n" + 733229Spst " void m() {\n" + 743229Spst " new Runnable() {\n" + 753229Spst " public void run() {\n" + 763229Spst " Sub.super.i += 10;\n" + 773229Spst " }\n" + 783229Spst " };\n" + 793229Spst " }\n" + 803229Spst "}"); 813229Spst 823229Spst Path out = testBase.resolve("out"); 833229Spst Files.createDirectories(out); 843229Spst Path base = src.resolve("base"); 853229Spst Path sub = src.resolve("sub"); 863229Spst 873229Spst new JavacTask(tb) 883229Spst .outdir(out) 893229Spst .files(tb.findJavaFiles(base)) 903229Spst .run(Task.Expect.SUCCESS); 913229Spst 923229Spst new JavacTask(tb) 933229Spst .classpath(out) 943229Spst .outdir(out) 953229Spst .files(tb.findJavaFiles(sub)) 963229Spst .run(Task.Expect.SUCCESS); 973229Spst } 983229Spst} 993229Spst