InnerClassFileTest.java revision 2933:49d207bf704d
1/* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 4491755 4785453 27 * @summary Prob w/static inner class with same name as a regular class 28 * @library /tools/lib 29 * @modules jdk.compiler/com.sun.tools.javac.api 30 * jdk.compiler/com.sun.tools.javac.file 31 * jdk.compiler/com.sun.tools.javac.main 32 * @build ToolBox 33 * @run main InnerClassFileTest 34 */ 35 36import java.nio.file.Path; 37import java.nio.file.Paths; 38 39// Original test: test/tools/javac/innerClassFile/Driver.sh 40public class InnerClassFileTest { 41 42 private static final String BSrc = 43 "package x;\n" + 44 "\n" + 45 "import x.*;\n" + 46 "\n" + 47 "public class B {\n" + 48 " public static class C {}\n" + 49 "}"; 50 51 private static final String CSrc = 52 "package x;\n" + 53 "\n" + 54 "import x.*;\n" + 55 "\n" + 56 "public class C {}"; 57 58 private static final String MainSrc = 59 "package y;\n" + 60 "\n" + 61 "class Main {\n" + 62 " private R1 a;\n" + 63 " private R2 b;\n" + 64 " private R3 c;\n" + 65 "}"; 66 67 private static final String R1Src = 68 "package y;\n" + 69 "\n" + 70 "public final class R1 {\n" + 71 " x.B.C a = null;\n" + 72 " x.C b = null;\n" + 73 " R2 c = new R2();\n" + 74 "}"; 75 76 private static final String R2Src = 77 "package y;\n" + 78 "\n" + 79 "public final class R2 {\n" + 80 " x.B.C a = null;\n" + 81 " x.C b = null;\n" + 82 "}"; 83 84 private static final String R3Src = 85 "package y;\n" + 86 "\n" + 87 "public final class R3 {\n" + 88 " x.B.C a = null;\n" + 89 " x.C b = null;\n" + 90 " R1 c = new R1();\n" + 91 "}"; 92 93 public static void main(String args[]) throws Exception { 94 new InnerClassFileTest().run(); 95 } 96 97 private final ToolBox tb = new ToolBox(); 98 99 void run() throws Exception { 100 createFiles(); 101 compileFiles(); 102 } 103 104 void createFiles() throws Exception { 105 Path srcDir = Paths.get("src"); 106 tb.writeJavaFiles(srcDir, BSrc, CSrc, MainSrc, R1Src, R2Src, R3Src); 107 } 108 109 void compileFiles() throws Exception { 110 tb.new JavacTask() 111 .outdir(".") 112 .classpath(".") 113 .sourcepath("src") 114 .files("src/x/B.java", "src/x/C.java", "src/y/Main.java") 115 .run() 116 .writeAll(); 117 118 tb.deleteFiles("y/R3.class"); 119 120 tb.new JavacTask() 121 .outdir(".") 122 .classpath(".") 123 .sourcepath("src") 124 .files("src/y/Main.java") 125 .run() 126 .writeAll(); 127 128 } 129 130} 131