test/tools/javac/innerClassFile/InnerClassFileTest.java

changeset 1591
dc8b7aa7cef3
parent 0
959103a6100f
equal deleted inserted replaced
1590:011cf7e0a148 1591:dc8b7aa7cef3
1 /*
2 * Copyright (c) 2013, 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/javac/lib
29 * @build ToolBox
30 * @run main InnerClassFileTest
31 */
32
33 import java.nio.file.Paths;
34
35 //original test: test/tools/javac/innerClassFile/Driver.sh
36 public class InnerClassFileTest {
37
38 private static final String BSrc =
39 "package x;\n" +
40 "\n" +
41 "import x.*;\n" +
42 "\n" +
43 "public class B {\n" +
44 " public static class C {}\n" +
45 "}";
46
47 private static final String CSrc =
48 "package x;\n" +
49 "\n" +
50 "import x.*;\n" +
51 "\n" +
52 "public class C {}";
53
54 private static final String MainSrc =
55 "package y;\n" +
56 "\n" +
57 "class Main {\n" +
58 " private R1 a;\n" +
59 " private R2 b;\n" +
60 " private R3 c;\n" +
61 "}";
62
63 private static final String R1Src =
64 "package y;\n" +
65 "\n" +
66 "public final class R1 {\n" +
67 " x.B.C a = null;\n" +
68 " x.C b = null;\n" +
69 " R2 c = new R2();\n" +
70 "}";
71
72 private static final String R2Src =
73 "package y;\n" +
74 "\n" +
75 "public final class R2 {\n" +
76 " x.B.C a = null;\n" +
77 " x.C b = null;\n" +
78 "}";
79
80 private static final String R3Src =
81 "package y;\n" +
82 "\n" +
83 "public final class R3 {\n" +
84 " x.B.C a = null;\n" +
85 " x.C b = null;\n" +
86 " R1 c = new R1();\n" +
87 "}";
88
89 public static void main(String args[]) throws Exception {
90 new InnerClassFileTest().run();
91 }
92
93 void run() throws Exception {
94 createFiles();
95 compileFiles();
96 }
97
98 void createFiles() throws Exception {
99 // mkdir src
100 // cp -r ${TESTSRC}${FS}* src
101 ToolBox.createJavaFileFromSource(Paths.get("src"), BSrc);
102 ToolBox.createJavaFileFromSource(Paths.get("src"), CSrc);
103 ToolBox.createJavaFileFromSource(Paths.get("src"), MainSrc);
104 ToolBox.createJavaFileFromSource(Paths.get("src"), R1Src);
105 ToolBox.createJavaFileFromSource(Paths.get("src"), R2Src);
106 ToolBox.createJavaFileFromSource(Paths.get("src"), R3Src);
107 }
108
109 void compileFiles() throws Exception {
110 // "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . -classpath .
111 // -sourcepath src src/x/B.java src/x/C.java src/y/Main.java
112 ToolBox.JavaToolArgs args =
113 new ToolBox.JavaToolArgs()
114 .setAllArgs("-d", ".", "-cp" , ".", "-sourcepath", "src",
115 "src/x/B.java", "src/x/C.java", "src/y/Main.java");
116 ToolBox.javac(args);
117
118 // rm y/R3.class
119 ToolBox.rm(Paths.get("y", "R3.class"));
120
121 // "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . -classpath .
122 // -sourcepath src src/y/Main.java
123 args.setAllArgs("-d", ".", "-cp", ".", "-sourcepath", "src", "src/y/Main.java");
124 ToolBox.javac(args);
125 }
126
127 }

mercurial