InnerClassFileTest.java revision 3294:9adfb22ff08f
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 *          jdk.jdeps/com.sun.tools.javap
33 * @build ToolBox
34 * @run main InnerClassFileTest
35 */
36
37import java.nio.file.Path;
38import java.nio.file.Paths;
39
40// Original test: test/tools/javac/innerClassFile/Driver.sh
41public class InnerClassFileTest {
42
43    private static final String BSrc =
44        "package x;\n" +
45        "\n" +
46        "import x.*;\n" +
47        "\n" +
48        "public class B {\n" +
49        "    public static class C {}\n" +
50        "}";
51
52    private static final String CSrc =
53        "package x;\n" +
54        "\n" +
55        "import x.*;\n" +
56        "\n" +
57        "public class C {}";
58
59    private static final String MainSrc =
60        "package y;\n" +
61        "\n" +
62        "class Main {\n" +
63        "        private R1 a;\n" +
64        "        private R2 b;\n" +
65        "        private R3 c;\n" +
66        "}";
67
68    private static final String R1Src =
69        "package y;\n" +
70        "\n" +
71        "public final class R1 {\n" +
72        "    x.B.C a = null;\n" +
73        "    x.C b = null;\n" +
74        "    R2 c = new R2();\n" +
75        "}";
76
77    private static final String R2Src =
78        "package y;\n" +
79        "\n" +
80        "public final class R2 {\n" +
81        "    x.B.C a = null;\n" +
82        "    x.C b = null;\n" +
83        "}";
84
85    private static final String R3Src =
86        "package y;\n" +
87        "\n" +
88        "public final class R3 {\n" +
89        "    x.B.C a = null;\n" +
90        "    x.C b = null;\n" +
91        "    R1 c = new R1();\n" +
92        "}";
93
94    public static void main(String args[]) throws Exception {
95        new InnerClassFileTest().run();
96    }
97
98    private final ToolBox tb = new ToolBox();
99
100    void run() throws Exception {
101        createFiles();
102        compileFiles();
103    }
104
105    void createFiles() throws Exception {
106        Path srcDir = Paths.get("src");
107        tb.writeJavaFiles(srcDir, BSrc, CSrc, MainSrc, R1Src, R2Src, R3Src);
108    }
109
110    void compileFiles() throws Exception {
111        tb.new JavacTask()
112                .outdir(".")
113                .classpath(".")
114                .sourcepath("src")
115                .files("src/x/B.java", "src/x/C.java", "src/y/Main.java")
116                .run()
117                .writeAll();
118
119        tb.deleteFiles("y/R3.class");
120
121        tb.new JavacTask()
122                .outdir(".")
123                .classpath(".")
124                .sourcepath("src")
125                .files("src/y/Main.java")
126                .run()
127                .writeAll();
128
129    }
130
131}
132