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