1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/innerClassFile/InnerClassFileTest.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,127 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 4491755 4785453 1.30 + * @summary Prob w/static inner class with same name as a regular class 1.31 + * @library /tools/javac/lib 1.32 + * @build ToolBox 1.33 + * @run main InnerClassFileTest 1.34 + */ 1.35 + 1.36 +import java.nio.file.Paths; 1.37 + 1.38 +//original test: test/tools/javac/innerClassFile/Driver.sh 1.39 +public class InnerClassFileTest { 1.40 + 1.41 + private static final String BSrc = 1.42 + "package x;\n" + 1.43 + "\n" + 1.44 + "import x.*;\n" + 1.45 + "\n" + 1.46 + "public class B {\n" + 1.47 + " public static class C {}\n" + 1.48 + "}"; 1.49 + 1.50 + private static final String CSrc = 1.51 + "package x;\n" + 1.52 + "\n" + 1.53 + "import x.*;\n" + 1.54 + "\n" + 1.55 + "public class C {}"; 1.56 + 1.57 + private static final String MainSrc = 1.58 + "package y;\n" + 1.59 + "\n" + 1.60 + "class Main {\n" + 1.61 + " private R1 a;\n" + 1.62 + " private R2 b;\n" + 1.63 + " private R3 c;\n" + 1.64 + "}"; 1.65 + 1.66 + private static final String R1Src = 1.67 + "package y;\n" + 1.68 + "\n" + 1.69 + "public final class R1 {\n" + 1.70 + " x.B.C a = null;\n" + 1.71 + " x.C b = null;\n" + 1.72 + " R2 c = new R2();\n" + 1.73 + "}"; 1.74 + 1.75 + private static final String R2Src = 1.76 + "package y;\n" + 1.77 + "\n" + 1.78 + "public final class R2 {\n" + 1.79 + " x.B.C a = null;\n" + 1.80 + " x.C b = null;\n" + 1.81 + "}"; 1.82 + 1.83 + private static final String R3Src = 1.84 + "package y;\n" + 1.85 + "\n" + 1.86 + "public final class R3 {\n" + 1.87 + " x.B.C a = null;\n" + 1.88 + " x.C b = null;\n" + 1.89 + " R1 c = new R1();\n" + 1.90 + "}"; 1.91 + 1.92 + public static void main(String args[]) throws Exception { 1.93 + new InnerClassFileTest().run(); 1.94 + } 1.95 + 1.96 + void run() throws Exception { 1.97 + createFiles(); 1.98 + compileFiles(); 1.99 + } 1.100 + 1.101 + void createFiles() throws Exception { 1.102 +// mkdir src 1.103 +// cp -r ${TESTSRC}${FS}* src 1.104 + ToolBox.createJavaFileFromSource(Paths.get("src"), BSrc); 1.105 + ToolBox.createJavaFileFromSource(Paths.get("src"), CSrc); 1.106 + ToolBox.createJavaFileFromSource(Paths.get("src"), MainSrc); 1.107 + ToolBox.createJavaFileFromSource(Paths.get("src"), R1Src); 1.108 + ToolBox.createJavaFileFromSource(Paths.get("src"), R2Src); 1.109 + ToolBox.createJavaFileFromSource(Paths.get("src"), R3Src); 1.110 + } 1.111 + 1.112 + void compileFiles() throws Exception { 1.113 +// "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . -classpath . 1.114 +// -sourcepath src src/x/B.java src/x/C.java src/y/Main.java 1.115 + ToolBox.JavaToolArgs args = 1.116 + new ToolBox.JavaToolArgs() 1.117 + .setAllArgs("-d", ".", "-cp" , ".", "-sourcepath", "src", 1.118 + "src/x/B.java", "src/x/C.java", "src/y/Main.java"); 1.119 + ToolBox.javac(args); 1.120 + 1.121 +// rm y/R3.class 1.122 + ToolBox.rm(Paths.get("y", "R3.class")); 1.123 + 1.124 +// "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . -classpath . 1.125 +// -sourcepath src src/y/Main.java 1.126 + args.setAllArgs("-d", ".", "-cp", ".", "-sourcepath", "src", "src/y/Main.java"); 1.127 + ToolBox.javac(args); 1.128 + } 1.129 + 1.130 +}